How can I align an image according to another image?

2 visualizzazioni (ultimi 30 giorni)
I am trying to align an image according to a base image and according to the position of 2 circles on the left of each page.
The link for unregistered image: http://tinypic.com/view.php?pic=2zsbmuu&s=6
The code I have so far is listed below but the only thing I have a problem with is how to use imtransfrom function to register the image.
  1 Commento
Vic
Vic il 27 Gen 2013
I1 = imread('C:\Users\Victoras\Desktop\answertest.bmp');
J1= imread('C:\Users\Victoras\Desktop\studenttest.bmp');
I2= rgb2gray(I1); %convert colour images to grayscale
J2= rgb2gray(J1);
BWI = im2bw(I2);% convert grayscale images to binary
BWJ = im2bw(J2);
IMI = imcomplement(BWI); % invert colours, black to white and white to black
IMJ = imcomplement(BWJ);
%imshow(IMI);
%imshow(IMJ);
BWIremove = bwareaopen(IMI, 5000); % remove objects less that 4500 pixels
BWJremove = bwareaopen(IMJ, 5000);
%imshow(BWIremove);
%imshow(BWJremove);
[LI, numI] = bwlabel(BWIremove);
[LJ, numJ] = bwlabel(BWJremove);
centroidsI = regionprops(LI,'Centroid');
centroidsJ = regionprops(LJ,'Centroid');
% Create a transformation structure for an affine % transformation.
t_concord = cp2tform(centroidsI,centroidsJ,'affine');
% Get the width and height of the orthophoto and perform % the transformation.
info = imfinfo(I1);
registered = imtransform(IMJ,t_concord,'XData',[1 info.Width], 'YData',[1 info.Height]);
figure, imshow(registered)

Accedi per commentare.

Risposta accettata

Image Analyst
Image Analyst il 27 Gen 2013
Have you tried imregister()? It will condense all that code down into a single line of code. Go ahead, make it easy on yourself.
  11 Commenti
Image Analyst
Image Analyst il 27 Gen 2013
That said, if you could figure out a transform, tformfwd() would probably be faster than calling imregister() three times.
Matt J
Matt J il 27 Gen 2013
Modificato: Matt J il 27 Gen 2013
Seems like a fluke to me. What if all the 'A' answers had been filled out in the first image and all the 'D' Answers had been filled out in the second? The alignment of the blue channels would have been heavily inconsistent with the other channels.

Accedi per commentare.

Più risposte (1)

Matt J
Matt J il 27 Gen 2013
Modificato: Matt J il 27 Gen 2013
Here's a modification of the original approach using ABSOR, available here
[LI, numI] = bwlabel( imfill(BWIremove,'holes') );
[LJ, numJ] = bwlabel( imfill(BWJremove,'holes') );
centroidsI = regionprops(LI,'Centroid');
centroidsJ = regionprops(LJ,'Centroid');
% Create a transformation structure for an affine % transformation.
cI=vertcat(centroidsI.Centroid);
cJ=vertcat(centroidsJ.Centroid);
S=absor(cJ.', cI.');
t_concord=maketform('affine', S.M(1:2,:).');
registered = imtransform(IMJ,t_concord,....);
Because you're only using 2 landmarks to perform the registration, the alignment will probably not be as perfect as with imregister, although as I've said, I have my doubts about how well imregister would work across a larger population of questionnaires.
There are things you could do to improve the tilt angle estimate though, like find more landmarks, or use regionprops(...,'Orientation') on the answer boxes.

Community Treasure Hunt

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

Start Hunting!

Translated by