% Calcul d'une mosaique d'image à partir de 2 images : I1 et I2 % connaissant l'homographie H entre les 2. % L'image resultat est stockee dans Res. % On choisit de projeter I2 dans I1 pour construire la mosaique. % Attention !!! % On suppose un axe de rotation parallèle aux colonnes. % C'est la raison pour laquelle on inverse les lignes et les colonnes % dans la reconstruction de la mosaique. function [Imos] = mosaiqueNbis(TailleFenetre, NbPoints, k, seuil, imref, varargin) homos = cell(1, length(varargin)); homos(1) = {eye(3)}; for i = 1:length(varargin) - 1 Im1 = im2double(varargin{i}); Im2 = im2double(varargin{i+1}); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Detection des points d'interet avec Harris % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Im1_gray = rgb2gray(Im1); Im2_gray = rgb2gray(Im2); XY_1 = harris(Im1_gray, TailleFenetre, NbPoints, k); XY_2 = harris(Im2_gray, TailleFenetre, NbPoints, k); % affichage temporaire figure; affichage_POI(Im1,XY_1,'POI Image 1',1,2,1); affichage_POI(Im2,XY_2,'POI Image 2',1,2,2); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Appariement des points d'interet % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% [XY_C1, XY_C2] = apparier_POI(Im1_gray, XY_1, Im2_gray, XY_2, TailleFenetre, seuil); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Estimation (et verification) de l'homographie % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % https://github.com/hero9968/Multiple-View-Geometry-in-Computer-Vision/blob/master/vgg_examples/ransacfithomography_vgg.m s = 4; t = 0.999; fitFuncHomo = @(XY) homographie(XY(:, 1:2), XY(:, 3:4)); disFuncHomo = @(H, XY) distance_homographie(XY(:, 1:2), XY(:, 3:4), H); [H, idx] = ransac([XY_C1, XY_C2], fitFuncHomo, disFuncHomo, s, t); % XY = [XY_C1, XY_C2]; % H = homographie(XY(:, 1:2), XY(:, 3:4)); homos(i + 1) = {H}; figure('Name', 'Appariement des points d''interet RANSAC'); affichage_appariement(Im1, XY_C1(idx, 1), XY_C1(idx, 2), 'Points d''interet Image 1', 1, 2, 1); affichage_appariement(Im2, XY_C2(idx, 1), XY_C2(idx, 2), 'Points d''interet correspondants Image 2', 1, 2, 2); end homos_to_ref = cell(1, length(varargin)); homos_to_ref(imref) = {eye(3)}; homos_tmp = eye(3); for i = imref-1:-1:1 homos_tmp = homos_tmp / homos{i + 1}; homos_to_ref(i) = {homos_tmp}; end homos_tmp = eye(3); for i = imref+1:length(varargin) homos_tmp = homos_tmp * homos{i}; homos_to_ref(i) = {homos_tmp}; end %%%%%%%%%%%%%%%%%%%%%% % Collage des images % %%%%%%%%%%%%%%%%%%%%%% Imos = mosaiqueter2(homos_to_ref, varargin); imwrite(Imos, "test.png");