How to deform an image using two reference points?

조회 수: 3 (최근 30일)
Julien Reynes
Julien Reynes 2019년 1월 8일
댓글: Julien Reynes 2019년 1월 11일
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

답변 (1개)

Image Analyst
Image Analyst 2019년 1월 8일
Try Steve's blog: Spatial transforms
  댓글 수: 4
Image Analyst
Image Analyst 2019년 1월 11일
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 2019년 1월 11일
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

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Histograms에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by