How to align two images together automatically: Round 2

Hello!
I have my images closely aligned, but not close enough. Is there anyway I can improve object selection in an image or getting the centroid more accurately/ consistently? I have been using this script to locate the centroid of both images and Sean De's imtranslate to modify the image.
Thanks
-Frank
Image
Code
%First Image
i = imread('343TESTA.tif');
j = size(i);
imtool(i);
for k = 1:j(1)
for l = 1:j(2)
if i(k,l) > 160 & i(k,l) > 160
d(k,l) = 1;
else
d(k,l) = 0;
end
end
end
imtool(d);
labela = bwlabel(d);
imagesc(labela);
[labela,num] = bwlabel(d,4);
stats = regionprops(labela,'basic');
stats(1).Area
stats(1).Centroid
max_area = max([stats.Area]);
biggrain = find([stats.Area]== max_area);
p = stats(biggrain).Centroid
%Second Image
a = imread('343TESTB.tif');
b = size(a);
imtool(a);
for c = 1:b(1)
for l = 1:b(2)
if i(c,l) > 160 & a(c,l) > 160
e(c,l) = 1;
else
e(c,l) = 0;
end
end
end
imtool(e);
labelb = bwlabel(e);
imagesc(labelb);
[labelb,num] = bwlabel(e,4);
stats = regionprops(labelb,'basic');
stats(1).Area
stats(1).Centroid
max_area = max([stats.Area]);
biggrain = find([stats.Area]== max_area);
o = stats(biggrain).Centroid
%Calculates the differences in the centroid
displacement = p -o
%IM Translate
v = imread('343TESTA.tif');
u = imread('343TESTB.tif');
u2 = imtranslate(u, [0 -1.0376]); %Note: [y x] for imtranslate
subplot(1,2,1), imshow(v)
subplot(1,2,2), imshow(u2)
imwrite(u2, '343TESTC','tif');

1 Comment

I'm using Fiji (ImageJ variant) to see how this script aligns the images. Stackreg isn't good because it moves the image up and down, I only want left and right alignment.

Sign in to comment.

Answers (1)

You could try this, though I don't know how well it will work on binary images...
Also, how were these images acquired? Is there a chance that there is a change in thickness/density etc.?

2 Comments

Not likely, these images are probably the best acquisition of the subject that technology can get today.
Would brightness of the image help?
Maybe. Perhaps try the subpixel phase correlation on the original images, not the images converted to binary.

Sign in to comment.

Categories

Asked:

on 18 May 2011

Community Treasure Hunt

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

Start Hunting!