Creating a loop for aligning multiple images based off of one original image

1 view (last 30 days)
I am trying to automate the process of aligining images for my final year project at University where I have to automate the process of anlaysisng photoelastic images via Phase Stepping, in this process I have to align the six images from the first image taken. I have taken the reference code from the MATLAB image registration estimator and made some modifications:
I have tried storing my images in a cell array and then running the code using a for loop with parantheses however I have not been successful. I think the key might be the way in which I can store the image data and then manipulate it to create a loop but I have no idea what to do.
% Default spatial referencing objects
fixed_image = imref2d(size(image_1));
movingimage_2 = imref2d(size(image_2));
% Detect MSER features
fixedPoints = detectMSERFeatures(image_1,'ThresholdDelta',1.466667,'RegionAreaRange',[14 25083],'MaxAreaVariation',0.812500);
movingPoints = detectMSERFeatures(image_2,'ThresholdDelta',1.466667,'RegionAreaRange',[14 25083],'MaxAreaVariation',0.812500);
% Extract features
[fixedFeatures,fixedValidPoints] = extractFeatures(image_1,fixedPoints,'Upright',false);
[movingFeatures,movingValidPoints] = extractFeatures(image_2,movingPoints,'Upright',false);
% Match features
indexPairs = matchFeatures(fixedFeatures,movingFeatures,'MatchThreshold',20.833333,'MaxRatio',0.208333);
fixedMatchedPoints = fixedValidPoints(indexPairs(:,1));
movingMatchedPoints = movingValidPoints(indexPairs(:,2));
MOVINGREG.FixedMatchedFeatures = fixedMatchedPoints;
MOVINGREG.MovingMatchedFeatures = movingMatchedPoints;
% Apply transformation - Results may not be identical between runs because of the randomized nature of the algorithm
tform = estimateGeometricTransform(movingMatchedPoints,fixedMatchedPoints,'affine');
MOVINGREG.Transformation = tform;
MOVINGREG.RegisteredImage = imwarp(image_2, movingimage_2, tform, 'OutputView', fixed_image, 'SmoothEdges', true);
% Store spatial referencing object
MOVINGREG.SpatialRefObj = fixed_image;

Accepted Answer

Ananya Tewari
Ananya Tewari on 24 Mar 2021
For aligning multiple images, a possible solution is as follows:
  • Convert all the six images to grayscale using rgb2gray
image1 = imread("<Insert image name>");
image1 = rgb2gray(image1);
  • Create a 3-D matrix for storing all the images
% assuming size of all images is same
[m,n] = size(image1);
imgs = zeros(m,n,6);
imgs(:,:,1) = image1;
  • Iterate through the matrix for the number of images and align two images in each iteration. First image will be the fixed image(or output of the last iteration) and second image will be new image from the matrix.
Please refer to this blog for aligning multiple images.

More Answers (0)

Products


Release

R2019b

Community Treasure Hunt

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

Start Hunting!