Yul
Yul

Reputation: 25

Control Point Registration with Matlab

I'm new to Matlab and I'm trying to do a Control Point Registration using their guide: http://www.mathworks.com/help/images/point-mapping.html

The result I get is two pictures one on top of the other but they are misaligned though they should be aligned according to the guide.

Can you please tell me what am I doing wrong ?

Thank you.

Here is the code:

function [Y] =EBL

ReferenceImg=imread('GFI.jpg'); %This is the fixed image
CroppedImg=imcrop(ReferenceImg); %Crop fixed image
close %close the imcrop window
MovingImg = imread('GF.bmp'); %This is the moving picture

ResizedIReferenceImg= imresize(CroppedImg,[1000 1000]); %resize the fixed image
ResizedMovingImg= imresize(MovingImg,[1000 1000]);%resize the moving image


[input_points,base_points] = cpselect(ResizedMovingImg,ResizedIReferenceImg,'Wait',  true);%Estimate   transformation

tform = fitgeotrans(input_points,base_points,'projective');

B = imwarp(ResizedMovingImg,tform);

imshow(B)
hold on
t=imagesc(ResizedIReferenceImg);%Set transparency of fixed image
set(t,'AlphaData',0.5);

end

Upvotes: 0

Views: 800

Answers (1)

nkjt
nkjt

Reputation: 7817

You need to read through this example from Mathworks (Register Two Images Using Spatial Referencing to Enhance Display). When they first talk about how to display the result, they note this same problem:

Notice how the two images appear misregistered. This happens because imshowpair assumes that the images are both in the default intrinsic coordinate system.

Although you're not using imshowpair to display, this would also apply to your example where you overlay your two images. You're assuming that after cropping and resizing your reference image, then applying a transform to your moving image, that they have the same "start point" - that pixel (1,1) in each image is the same location. In practice they're in slightly different coordinate systems, and you have to take that into account. Adapting one of their solutions to your code would look something like this:

Rfixed = imref2d(size(ResizedIReferenceImg));
B = imwarp(ResizedMovingImg,tform, 'OutputView',Rfixed);

This will clip off parts of the moving image which are outside the bounds of your fixed image after the transform is applied.

Upvotes: 1

Related Questions