imtransform had shift my center

9 views (last 30 days)
Marco Yu
Marco Yu on 8 Aug 2016
Answered: Marco Yu on 9 Aug 2016
Hi, I had 3 images which size 200*200. I would want to aggregate those image with same center after they have been imtransform. Those 3 images are eye scanning. so let's say there is a optic disc, assume it is a circle and I had it's center coordinate. So for example the first image center is 100,100 (this is perfect),2nd is 101,101(so I had to shift -1,-1 to aggregate the 2nd image with the 1st), the last one is 130,130. However, I had calculate that even the optic disc(the circle) had it own center, the image is not scan properly. Therefore I had to rotate my images. I had a Tform and tried to use imtransform. It look okay after the images transform, and I know the image will have difference size, since the I don't want any information lose. Then I change the image size to 300,300. Since I need to aggregate those 3 images to center 150,150 which is the middle of the images. I had try to use imtranslate, which should be fine. However, everytime I try to aggregate the image, the shifting/center is not correct. Below is the code which I had tried.
for n=1:no_of_pics
temp_recover=cell2mat(T(n,1));
%if it is left eye, it need to be fliped
if analyzingEye=='OS'
temp_recover=flipdim(temp_thickness,2);
end
temp_recover(isnan(temp_recover))=0;
%peaks is the center detected by hough method
temp_xcenter=ceil(peaks(1,n)*200/668);
temp_ycenter=ceil(peaks(2,n)*200/668);
% matrix below is trying to rotate the image about the certain center not the origin
temp_tocenter=[1 0 0;0 1 0;-(150-temp_xcenter) -(150-temp_ycenter) 1];
temp_back=[1 0 0;0 1 0;150-temp_xcenter 150-temp_ycenter 1];
temp_recover=imtransform(temp_recover,maketform('affine',temp_tocenter*cell2mat(TTFORM(n,1))*temp_back),'XData',[1 301],'YData',[1 301]);
end
However by using this method, the center is shifted to somewhere I don't know. Therefore, I had use another code;
for n=1:no_of_pics
temp_recover=cell2mat(T(n,1));
if analyzingEye=='OS'
temp_recover=flipdim(temp_thickness,2);
end
temp_recover(isnan(temp_recover))=0;
temp_xcenter=ceil(peaks(1,n)*200/668);
temp_ycenter=ceil(peaks(2,n)*200/668);
temp_recover=imtransform(temp_recover,maketform('affine',cell2mat(TTFORM(n,1))));
%I am trying to expand the matrix to 300*300 so that I can aggregate the center and no information lost
temp_recover(300,300)=0;
temp_recover=imtranslate(temp_recover,[151-temp_xcenter,151-temp_ycenter],'fillvalue',0);
end
It did better, but still the circle is not perfectly match. I am very frustrated on this. Can someone point out where I had done wrong? Thank you very much

Accepted Answer

Marco Yu
Marco Yu on 9 Aug 2016
Right for anyone have same problem with me. Here is the better solution. Firstly, you create a translation matrix i.e.
%dx dy are the length that you need to translate
shift=[1 0 0;0 1 0;dx dy 1]
then you need a matrix to transform to origin
%so if you want to rotate at point(150,150)
to_center=[1 0 0;0 1 0;-150 -150 1]
then you need your rotation matrix which is
%theta is the angle
rotation=[cosd(theta) -sind(theta) 0;sind(theta) cosd(theta) 0;0 0 1]
then you need to transform back
back=[1 0 0;0 1 0;150 150 1]
therefore, the overall matrix will be
final=shift*to_center*rotation*back
hope this can help you :)

More Answers (1)

Marco Yu
Marco Yu on 9 Aug 2016
I have an low rank solutions: firstly, I had use pure translation to aggregate the center and expand the image to size 300*300
if analyzingEye=='OD'
temp_recover=imtransform(temp_recover,maketform('affine',[1 0 0;0 1 0;151-peaks(1,n)*200/668 151-peaks(2,n)*200/668 1]),'XData',[1 300],'YData',[1 300]);
else
temp_recover=imtransform(temp_recover,maketform('affine',[1 0 0;0 1 0;151-(200)+peaks(1,n)*200/668 151-peaks(2,n)*200/668 1]),'XData',[1 300],'YData',[1 300]);
end
then I do the rotation with imtransform, however since imtransform will rotate the image from origin, therefore I had to do some matrix multiplication.
temp_tocenter=[1 0 0;0 1 0;-151 -151 1];
temp_back=[1 0 0;0 1 0;151 151 1];
temp_recover=imtransform(temp_recover,maketform('affine',temp_tocenter*cell2mat(TTFORM(n,1))*temp_back),'XData',[1 300],'YData',[1 300]);
The reason I call this low rank is because this will do the interpolation twice. I suppose this will reduce the accuracy and quality of the image.I did try to merge the code above to see the result. However, it is not good. I am not sure whether it is because of the function(imtransform) problems nor I am lack of mathematical knowledge. If anyone can give a help, I would be very appreciated.

Categories

Find more on Simulink in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!