|
On 14 Okt., 14:18, "kees de Kapper" <kees_de_kap...@hotmail.com>
wrote:
> Dear all,
>
> probably an easy question for the diehards but I'm struggling a while already.
>
> I'm trying to transform an image using imtransform. The main idea is that I've got a large image, which I will register/match to another image. Therefore I just select a small ROI to perform the registration (using an optimization). Subsequently, this found transformation is applied to the entire (large) image. However, the resulting image is not matched, even if rotations were not taken into account.
>
> To demonstrate my problem, I simplified my code to the following:
> I. first cropping, then imtransform,
> II. first imtransform (use the same transformation), then cropping.
>
> Why doesn't give the two (apparently similar) routes the same result? And how can I solve this?
>
> Many thanks in advance,
> Kees.
>
> %***************************************************************
> function main()
> Img = zeros(400,500); Img(100:200,200:400) = 1; % test image
>
> ClipBox = [50,size(Img,1)-50;50,size(Img,2)-50]; %[vert0,vert1,hor0.hor1]
> dx = 100;
> dy = -100;
> dr = 0;
> Ax1 = 1:size(Img,1); % coordinates of the axes
> Ax2 = 1:size(Img,2);
>
> % Transform image and then do clipbox
> ImgT0 = TransformImage(Img, dx,dy,dr, Ax1,Ax2);
> ImgT0 = ImgT0(ClipBox(1,1):ClipBox(1,2),ClipBox(2,1):ClipBox(2,2));
>
> % Do clipbox and then transform image
> Img = Img(ClipBox(1,1):ClipBox(1,2),ClipBox(2,1):ClipBox(2,2));
> Ax1 = Ax1(ClipBox(1,1):ClipBox(1,2));
> Ax2 = Ax2(ClipBox(2,1):ClipBox(2,2));
> ImgT1 = TransformImage(Img, dx,dy,dr, Ax1,Ax2);
>
> figure(2);
> subplot(3,2,1); imagesc(Img); colormap(gray); title('original image cropped')
> subplot(3,2,3); imagesc(ImgT0); colormap(gray); title('transformed image then cropped')
> subplot(3,2,5); imagesc(ImgT1); colormap(gray); title('cropped original image then transformed')
> subplot(3,2,6); imagesc(ImgT0-ImgT1); colormap(gray); title('difference two transf. images');
>
> function ImgT = TransformImage(Img, dx,dy,dr, Ax1, Ax2)
> udata = [Ax1(1), Ax1(end)];
> vdata = [Ax2(1), Ax2(end)];
>
> tform = maketform('affine',[cos(dr/180*pi) -sin(dr/180*pi) 0; ...
> sin(dr/180*pi) cos(dr/180*pi) 0; ...
> dx dy 1]);
> [ImgT] = imtransform(Img, tform, 'linear', ...
> 'udata', udata,'vdata', vdata,...
> 'xdata', udata,'ydata', vdata,...
> 'size', size(Img), 'fill', NaN);
>
> %***************************************************************
Have you tried the cpselect tool? It's really good for finding
Transformation points.
|