How to deform an image using two reference points?

3 Ansichten (letzte 30 Tage)
Julien Reynes
Julien Reynes am 8 Jan. 2019
Kommentiert: Julien Reynes am 11 Jan. 2019
Hi there,
I am trying to correlate two images, actually two maps of a mineral acquired with two different instruments. The problem is : one instrument deformed a little bit the map, so it is not possible to do a direct correlation. I would like to adjust and resample this deformed map to fit the other one (map1), considered as reference because the instrument is more accurate in term of XY stage.
I have the two maps as matrix, and I put them in a bigger NaN matrix (I used that to be able to do rotation and move them to find best correlation). I set two reference points, that I can identify in both maps. What I would like is to deform and resample map 2 in order to have ref1-ref2 distance same than in the reference image.
I did this schema, hope it helps to understand my problem. If you have any idea of functions/ tips I could use to achieve that I would be gratefull.
Of course In case of success I would share my code as a function on the platform.SchemaDeform.PNG
Cheers,
J. Reynes

Antworten (1)

Image Analyst
Image Analyst am 8 Jan. 2019
Try Steve's blog: Spatial transforms
  4 Kommentare
Image Analyst
Image Analyst am 11 Jan. 2019
Sorry - didn't see your prior reply for some reason (or else I didn't have time to delve into it).
You're right - that doesn't sound right. If you can verify it, I'd probably call them and prove it to tech support so they can log it as a bug.
Are you sure, or maybe it's just that the screen is not updated so you THINK that's what's happening. I'd put a "drawnow" after the while loop and take out the pause and see if that works or not.
Julien Reynes
Julien Reynes am 11 Jan. 2019
Now it works fine without the "pause" when yesterday it returned error message "undefined function or variable RefDistorded" or "undefined function or variable Distorded".
I restarted my computer in between, maybe it solved the problem.
Here is now my function, it is working, so if anyone find this topic and wanna do the same!
Cheers,
J.R.
function [ TransformedMap ] = affineTransform( Original,Distorded )
%Synthax: [TransformedMap]=affineTransform(original,Distorded)
% affineTransform propose the user to set reference point on an original
% image and a distorded one, then correct the distorded image to fit the
% original one. The function realise scale, shearing and translation
% geometric transformations.
%---------------- Display reference figure and ask user to set point -----%
figure;
Data=Original;
imagesc(Data);
colorbar;
colormap([jet(64);0,0,0]);
DataS = sort(Data(:));
DataSpos = DataS(find(DataS));
CutPos = round(length(DataSpos) * 0.065);
caxis([DataSpos(CutPos), DataSpos(end-CutPos)]);
axis image
title('reference')
Clic=0;
Compt=0;
while Clic<3; %if clic right, stop asking for points
Compt=Compt+1;
[x_input(Compt),y_input(Compt),Clic] = ginput(1); %user input
if Clic<3;
hold on
plot(x_input(Compt),y_input(Compt),'Marker','o','MarkerFaceColor',rgb('Pink'));
text(x_input(Compt),y_input(Compt),num2str(Compt));
end
end
%save xy coordinate of the reference points
RefOriginal(:,1)=round(x_input(1:end-1));
RefOriginal(:,2)=round(y_input(1:end-1));
%-------------- Display distorded figure and ask user to set points ------%
figure
Data=Distorded;
imagesc(Data);
colorbar;
colormap([jet(64);0,0,0]);
DataS = sort(Data(:));
DataSpos = DataS(find(DataS));
CutPos = round(length(DataSpos) * 0.065);
caxis([DataSpos(CutPos), DataSpos(end-CutPos)]);
axis image
title('distorded')
Clic=0;
Compt=0;
while Clic<3; %if clic right, stop asking for points
Compt=Compt+1;
[x_input(Compt),y_input(Compt),Clic] = ginput(1); %user input
if Clic<3;
hold on
plot(x_input(Compt),y_input(Compt),'Marker','o','MarkerFaceColor',rgb('Pink'));
text(x_input(Compt),y_input(Compt),num2str(Compt));
end
end
%save xy coordinate of the distorded points
RefDistorded(:,1)=round(x_input(1:end-1));
RefDistorded(:,2)=round(y_input(1:end-1));
%pause(1)%ask matlab to wait to be sure all variables are updated
%---------------- Estimate transformation --------------------------------%
tform = fitgeotrans(RefDistorded, RefOriginal,'affine');
%pause(1)%ask matlab to wait to be sure all variables are updated
%----------------- Do image transformation -------------------------------%
TransformedMap = imwarp(Distorded,tform);
%Compare recovered to riginal by looking at them side-by-side
figure
%-- Original figure
subplot(131)
Data=Original;
imagesc(Data);
colorbar;
colormap([jet(64);0,0,0]);
DataS = sort(Data(:));
DataSpos = DataS(find(DataS));
CutPos = round(length(DataSpos) * 0.065);
caxis([DataSpos(CutPos), DataSpos(end-CutPos)]);
axis image
title('Reference')
% -- Distorded figure
subplot(132)
Data=Distorded;
imagesc(Data);
colorbar;
colormap([jet(64);0,0,0]);
DataS = sort(Data(:));
DataSpos = DataS(find(DataS));
CutPos = round(length(DataSpos) * 0.065);
caxis([DataSpos(CutPos), DataSpos(end-CutPos)]);
axis image
title('Distorded')
% -- Transformed figure
subplot(133)
Data=TransformedMap;
imagesc(Data);
colorbar;
colormap([jet(64);0,0,0]);
DataS = sort(Data(:));
DataSpos = DataS(find(DataS));
CutPos = round(length(DataSpos) * 0.065);
caxis([DataSpos(CutPos), DataSpos(end-CutPos)]);
axis image
title('recovered')
end

Melden Sie sich an, um zu kommentieren.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by