Monday 15 March 2010

Inverse transform image in matlab -



Inverse transform image in matlab -

i using code translate image when apply inverse on image did not show whole image shows 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 grayness ot=imtransform(out, ttform, 'xdata',[0 size(out,0)],'ydata',[0 size(out,0)]); figure; imagesc(ot); title ('inverse translated image'); colormap grayness

i think problem comes size of xdata , ydata provide imtransform. since correspond size of original image , later translated, matlab padds 0 fill blanks since specify want particular dimension image seem part of image.

here workaround show translation work:

1) create canvas containing original image; canvas big plenty contain image , rest black. utilize coins image ships matlab.

img = imread('coins.png'); %// size of original image [height,width,~] = size(img) canvas = zeros(2*size(img),'like',img); %// set image in canvas. canvas(height+1:end,width+1:end) = img; figure; imagesc(canvas) colormap grayness title('original image','fontsize',16)

looking this:

then apply code translate image. notice alter in xdata , ydata in imtransform:

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(canvas, tform, 'xdata',[1 size(canvas,2)],'ydata',[1 size(canvas,1)]); %// size important! figure; imagesc(out); title ('translated image','fontsize',16); colormap grayness ot=imtransform(out, ttform, 'xdata',[1 size(canvas,2)],'ydata',[1 size(canvas,1)]); figure; imagesc(ot); title ('inverse translated image','fontsize',16); colormap grayness

which gives next translated image:

and inverse-translated image:

which looks original. note preferable utilize affine2d combined imwarp instead of maketform , imtransform, that's call.

hope helps!

matlab matlab-figure image-scaling

No comments:

Post a Comment