Fitgeotrans and imwarp to transform an image to fit datapoints

4 次查看(过去 30 天)
Hi, I have images of a sample that has been analysed. The analysed spots can be seen on the image. I also have the XY-coordinates of the analysed spots. I want to reference the image to those analysed spots using fitgeotrans and imwarp. I get the image to rotate and stretch accordingly but I want the datapoints to plot on top of the image or to show the image below the datapoints. I'm using the functions in a gui, so I define the moving and fixed points using ginput. I want the moving and fixed points to plot at the exact same position in the diagram after carrying out the transformation. Instead the image is transformed correctly but is not stretched so that the fixed and moving points are located perfectly on top of each other.
Here are the code snippets that I use for the transformation at the moment:
movingPoints = ginput(2);
[xfix,yfix,~] = MagnetGInput(h,length(movingPoints));
tform = fitgeotrans(movingPoints,[xfix(1) yfix(1); xfix(2) yfix(2)],'NonreflectiveSimilarity');
img_new = imwarp(img,tform);
im = image(xlim,ylim,img_new);
im.AlphaData = 0.5;
In the attached photo I want the middle red line to span the whole range of the aligned circles. It is kind of parallel already but is to short. For referencing I clicked on the very ends of this line and on the very end of the line defined by the circles.
I would be very happy about some help. Thank you very much!
  2 个评论
Yves Feisel
Yves Feisel 2018-10-15
编辑:Yves Feisel 2018-10-15
I'm still in the need of a solution and would be very grateful for help. If you need more information to provide proper help please let me know.
I found that when I use :
im = image(img_new);
without the xlim and ylim attributes, the image is stretched and rotated correctly, but it is plotted with the lower left corner matching the origin of the diagram ( 0 / 0 ). How can I achieve it to move to the datapoints (X and Y both negative in my case) and match the controlpoints?
Yves Feisel
Yves Feisel 2018-10-16
I have put together a working example that might help to make clear what I am trying to achieve. The two ginput commands are used to determine the control points for fitgeotrans. The first three points I choose on the middle red line of the image in the background. First point on the lower end, second point on the upper end and the third point in the middle. The MagnetGInput command links those points to the respective datapoints. I choose first point: lower left datapoint, second point: upper right datapoint, third point: datapoint in the middle. As you will see, this results in an image being transformed correctly but not plotted in the correct position directly below the datapoints. Additionally, the length of the middle red line is not the same as the length of the line formed by the datapoints. Why is that? What attributes can I use to let the image plot directly below the datapoints and stretched correctly? I read about the 'OutputView' attribute but I don't know how to use it if I want to reference an image to datapoints instead of two images with each other.
What am I missing here? Anything else I need to consider? Please somebody shed some light on this issue.
Thank you very much!
You will need MagnetGInput.m and the image-file 'profiles.jpg' which are both attached.
working example (place ginput points as described above):
%%running_example
close all
clear all
x = -500:50:500;
y = -2900:20:-2500;
h = scatter(x',y');
hold on
img = flipud(imread('profiles.jpg'));
ax = gca;
xlim = ax.XLim;
ylim = ax.YLim;
im = image(xlim,ylim,img);
im.AlphaData = 0.5;
moving_points = ginput(3);
[xfix,yfix,~] = MagnetGInput(h,length(moving_points));
A = [xfix' yfix'];
B = moving_points;
tform = fitgeotrans(B,A,'similarity');
warped = imwarp(img,tform);
delete(im);
im = image(warped);
im.AlphaData = 0.5;
I know this seems not very accurate but the actual data and images I plan to use in the future are way more accurate. I will be able to register each datapoint to a specific point in the image. This image is just used to get the program running. Cheers!

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 3-D Volumetric Image Processing 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by