Posts Tagged ‘affine transformation’

Playing with Matlab

06/21/2013

Image registration using ga (genetic algorithm)

Given two images, A and B, try to find affine transformation to maximize correlation between the to images.

This simple code works on simple images with simple transformations.

function res=reg1()
 clear all;
 close all;

 global A B
 A=imread('/home/komap/Desktop/SuperResolutionMatlab/Data/IMAG0446.jpg');
 B=imread('/home/komap/Desktop/SuperResolutionMatlab/Data/IMAG0447.jpg');

 A=rgb2gray(A);
 B=rgb2gray(B)

 options = gaoptimset('Generations',50);
 options = gaoptimset(options,'MutationFcn',@mutationadaptfeasible);
 options = gaoptimset(options,'PlotFcns',{@gaplotbestf,@gaplotmaxconstr}, 'Display','iter');
 options = gaoptimset(options,'InitialPopulation',[1 0 0 0 1 0]);
 [a,fval] = ga(ObjectiveFunction,6, options);
end;

function a = cor(alfa)
 global A B
 alfa = reshape(alfa, 3, 2);
 t_n = maketform('affine', alfa);
 D = imtransform(A,t_n);
 D = imresize(D, size(B));

 a = 1-corr2(B, D);
end
Advertisements