Image Reistration
Image Reistration
fixedImage = imread('cameraman.tif');
movingImage = imread('peppers.png');
% Normalize images
fixedImage = im2double(fixedImage);
movingImage = im2double(movingImage);
% Selection
[~, sortedIdx] = sort(fitness);
population = population(sortedIdx, :);
% Crossover
for i = 1:2:popSize
if i + 1 <= popSize
alpha = rand;
population(i, :) = alpha * population(i, :) + (1 - alpha) *
population(i + 1, :);
population(i + 1, :) = (1 - alpha) * population(i, :) + alpha *
population(i + 1, :);
end
end
% Mutation
mutationRate = 0.1;
mutationMask = rand(popSize, numParams) < mutationRate;
population = population + mutationMask .* (rand(popSize, numParams) .*
repmat((ub - lb), popSize, 1) - repmat((ub - lb)/2, popSize, 1));
% Enforce bounds
population = max(min(population, ub), lb);
end
% Parameters for GA
numGenerations = 50;
popSize = 20;
subplot(2,2,2);
imshow(movingImage);
title('Moving Image');
subplot(2,2,3);
imshow(movingRegisteredOptimalGA);
title('Registered Image using GA');
subplot(2,2,4);
imshow(movingRegisteredOptimalACO);
title('Registered Image using ACO');
subplot(1,2,2);
errorImageACO = abs(fixedImage - movingRegisteredOptimalACO);
imshow(errorImageACO, []);
title('Error Image using ACO');
colorbar;