Posts Tagged ‘matlab’

Image registration with genetic algorithms, again


Given two images, we want to “reigster” them.

After resizing (pyramid, to speed-up the algorithm) and normalizing (to improve the registration) I’ve tried to find shift + rotation (3 degrees of freedom) using algorithms in matlab’s global optimization toolbox.

  • genetic-algorithm – results are good only if initial guess is good/ image offset is small, even with customized parameters.
  • Direct Search – very good results (but the offset is integer, for some reason)
  • Simulated Annealing – poor results

In all cases, the following function was used:

%try to make B similar to A
function a = cor(alfa1)
 global A B 
 global roi

 b1=imChange(B, alfa1);
 a1=imcrop(A, roi);
 a = 1-corr2(a1,b1);

%vector of form [offset-x, offset-y, angle]
function out = imChange(im, vector)
 global roi
 alfa = vector(3);
 offset = vector(1:2);
 B1=imrotate(im, alfa,'bicubic', 'crop');
 out=imcrop(B1, roi+[offset 0 0]);

Playing with Matlab


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


 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);

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);