I am using this code to translate an image but when I apply inverse on the image it did not show the whole image it shows only transformed image.
tran= [1 0 0; 0 1 0; -130 -100 1];
traninv= [1 0 0; 0 1 0; 130 100 1];
% apply translation
tform= maketform('affine', tran);
ttform=maketform('affine', traninv);
out=imtransform(img, tform, 'XData',[1 size(img,2)],'YData',[1 size(img,1)]);
figure;
imagesc(out);
title ('translated image');
colormap gray
ot=imtransform(out, ttform, 'XData',[0 size(out,0)],'YData',[0 size(out,0)]);
figure;
imagesc(ot);
title ('inverse translated image');
colormap gray
I think your problem comes from the size of the XData and YData you provide imtransform. Since they correspond to the size of the original image and the later is translated, MATLAB padds with 0 to fill the blanks but since you specify that you want a particular dimension for your image you seem to get only part of the image.
Here is a workaround to show you that your translation does work:
1) Create a canvas containing the original image; the canvas is large enough to contain the image and the rest is just black. I use the coins image that ships with MATLAB.
Looking like this:
Then apply your code to translate the image. Notice that change in XData and YData in imtransform:
which gives the following translated image:
and inverse-translated image:
which looks exactly like the original. Note that it is preferable to use
affine2d
combined withimwarp
instead ofmaketform
andimtransform
, but that's your call.Hope that helps!