Picture Transformation Finder

by

 

This function finds the transformation matrix of two images.

picTransformation(pic1, pic2)
%%
%%Purpose: 
%%The purpose of this function is to find the transformation matrix between
%%two images
%%
%%How it works:
%%This function first detects all of the "corners" in the two pictures.
%%Then the function estimates the transformational matrix between the two
%%images
%%
%%Inputs:
%%pic1 = The first JPEG image
%%pic2 = The second JPEG image. 
%%
%%Outputs:
%%pts1: the corner points on pic1
%%pts2: the corner points on pic2
%%tform: This is the transformational matrix from pic1 to pic2
%%
%%Comments: 
%%The images should be of relative objects in order for the
%%transformational matrix to have any meaning. Also please do not be too
%%harsh in the comments, this is my first computer vision toolbox function
%%and my first parallel computation toolbox function. Please note that if
%%you do not have the parallel computation tool, all you need to do is get
%%rid of the spmd construct but keep the statements. You will also need to get 
%%rid of pts1 = points1{1} and pts2 = points2{2} and rename the points1 and
%%points2 to pts1 and pts2 respectfully. 
%%
%%Version: 1.0 $  $Date: 7-Oct-2011
%%@author Alexander James Wallar
function [pts1 pts2 tform] = picTransformation(pic1, pic2)
hcornerdet = video.CornerDetector( ... 
    'Method', ...,
    'Local intensity comparison (Rosen & Drummond)', ... 
    'MaximumAngleThreshold', '135.0', ... 
    'MaximumCornerCount', 100);
hgte = video.GeometricTransformEstimator(...
    'Transform', 'Projective');
hdrawmarkers = video.MarkerInserter( ... 
 'Shape', 'Circle', ... 
 'BorderColor', 'Custom', ...
 'CustomBorderColor', [1 0 0]);
spmd
    if labindex == 1
        x = im2single(rgb2gray(imread(pic1)));  
        points1 = step(hcornerdet, x);
        subplot(2,1,1);imagesc(step(hdrawmarkers, cat(3,x,x,x), points1));
    elseif labindex == 2
        y = im2single(rgb2gray(imread(pic2)));
        points2 = step(hcornerdet, y);
        subplot(2,1,1);imagesc(step(hdrawmarkers, cat(3,y,y,y), points2));
    end
end
pts1 = points1{1};
pts2 = points2{2};
subplot(2,1,1);imagesc(step(hdrawmarkers, cat(3,x{1},x{1},x{1}), pts1));
subplot(2,1,2);imagesc(step(hdrawmarkers, cat(3,y{2},y{2},y{2}), pts2));
tform = step(hgte, pts1, pts2, uint8(5));

Contact us