image alignment and stitching

41 views (last 30 days)
Ben
Ben on 5 Dec 2012
Commented: siqian yang on 12 Sep 2020
I'm trying to align several images so I can stitch them together.
My idea is to filter then to enhance the contrast so that matlab can then properly align them using a rigid transformation. I've tried aligning only parts of them and that doesn't work very well.
For filtering I've been trying local adaptive thresholding (<http://www.mathworks.com/matlabcentral/fileexchange/8647-local-adaptive-thresholding>) with median and wiener2 filters.
Here are the images I'm trying to align: http://imageshack.us/g/1/9903605/
Tomorrow I'm going to try to remove the dark spots that are in every picture and replace them with the median of the surrounding pixels on the perimeter.
On an somewhat related note, does anyone have some articles or guides I could have a look at to understand when I should apply which kind of filter? Everything I find on the subject explains how the filters work but not when to apply which so I've been just trying different things and seeing how it looks.
Thanks in advance for your help!
  3 Comments
Image Analyst
Image Analyst on 5 Dec 2012
Sure - give it a shot. You could also try normxcorr2() - search Answers for a demo I posted.
Ben
Ben on 5 Dec 2012
Didn't have any lug with normxcorr2() but I also wasn't able to find your demo. Can you point me in the right direction?
I wrote a script to take the big black spots and replace them with the median of the values around the perimeter and that improved the alignment. I was able to get them to almost align using imregister().
I've posted more pictures of my images after various filters and things here.

Sign in to comment.

Answers (2)

Image Analyst
Image Analyst on 5 Dec 2012
Well I'm no expert in the stitching field but I don't see anything that you've listed that would do the stitching or even help with the stitching at all. But I can refer you to this page which has dozens of different published algorithm from the past 15 years: 18.4.1 Mosaic Generation, Image Stitching, Photomosaic If I were you I'd pick one of those successful algorithms and try to program it up.
  5 Comments
Image Analyst
Image Analyst on 11 Sep 2020
Same answer/suggestion.
siqian yang
siqian yang on 12 Sep 2020
Thank you so much.

Sign in to comment.


Image Analyst
Image Analyst on 5 Dec 2012
Ben: Here's my demo on normxcorr2():
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
imtool close all; % Close all imtool figures.
clear; % Erase all existing variables.
workspace; % Make sure the workspace panel is showing.
format longg;
format compact;
fontSize = 20;
% Check that user has the Image Processing Toolbox installed.
hasIPT = license('test', 'image_toolbox');
if ~hasIPT
% User does not have the toolbox installed.
message = sprintf('Sorry, but you do not seem to have the Image Processing Toolbox.\nDo you want to try to continue anyway?');
reply = questdlg(message, 'Toolbox missing', 'Yes', 'No', 'Yes');
if strcmpi(reply, 'No')
% User said No, so exit.
return;
end
end
% Read in a standard MATLAB color demo image.
folder = fullfile(matlabroot, '\toolbox\images\imdemos');
baseFileName = 'peppers.png';
% Get the full filename, with path prepended.
fullFileName = fullfile(folder, baseFileName);
if ~exist(fullFileName, 'file')
% Didn't find it there. Check the search path for it.
fullFileName = baseFileName; % No path this time.
if ~exist(fullFileName, 'file')
% Still didn't find it. Alert user.
errorMessage = sprintf('Error: %s does not exist.', fullFileName);
uiwait(warndlg(errorMessage));
return;
end
end
rgbImage = imread(fullFileName);
% Get the dimensions of the image. numberOfColorBands should be = 3.
[rows columns numberOfColorBands] = size(rgbImage);
% Display the original color image.
subplot(2, 2, 1);
imshow(rgbImage, []);
axis on;
title('Original Color Image', 'FontSize', fontSize);
% Enlarge figure to full screen.
set(gcf, 'units','normalized','outerposition',[0 0 1 1]);
smallSubImage = imcrop(rgbImage, [192 82 60 52]);
subplot(2, 2, 2);
imshow(smallSubImage, []);
axis on;
title('Template Image to Search For', 'FontSize', fontSize);
% Search the red channel for a match.
correlationOutput = normxcorr2(smallSubImage(:,:,1), rgbImage(:,:,1));
subplot(2, 2, 3);
imshow(correlationOutput, []);
title('Correlation Output', 'FontSize', fontSize);
[maxCorrValue, maxIndex] = max(abs(correlationOutput(:)));
[ypeak, xpeak] = ind2sub(size(correlationOutput),maxIndex(1));
corr_offset = [(xpeak-size(smallSubImage,2)) (ypeak-size(smallSubImage,1))];
subplot(2, 2, 4);
imshow(rgbImage);
hold on;
rectangle('position',[corr_offset(1) corr_offset(2) 50 50],...
'edgecolor','g','linewidth',2);
title('Template Image Found in Original Image', 'FontSize', fontSize);

Community Treasure Hunt

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

Start Hunting!