How to find the argmax value of multiple images

8 views (last 30 days)
I have multiple images. First I want to find the correlation between each images like image 1 and image2 then image2 and image3 then to add offset by finding the location of the maximum correlation value following the below equation:
Basically I want to follow the algorithm attached as correlation1 . And I want to perform this procedure between each pair of consecutive frames for the entire sequence. My code is given below:
close all;clc;
% read all images from your folder and making them of same dimension
myFolder = 'folder path';
filePattern = fullfile(myFolder, '*.jpg');% change the extension according to your file extension
jpgFiles = dir(filePattern);
for k = 1:length(jpgFiles)
baseFileName = jpgFiles(k).name;
fullFileName = fullfile(myFolder, baseFileName);
fprintf(1, 'Now reading %s\n', fullFileName);
temp = double(imread(fullFileName));
[r,c,d]=size(temp);
if d==3
temp=rgb2gray(temp);
end
if r~=256 && c~=256
temp=imresize(temp,[256,256],'bicubic');
end
imageArray{k} =temp;
end
% calculate correlation for every image combinations
for i=1:size(imageArray,2)
for j=1:size(imageArray,2)
corr_cell{i,j}=normxcorr2(imageArray{i},imageArray{j});
[argvalue, argmax] = max(corr_cell{i,j});
end
end
Suppose we have 11 images so after this we are supposed to get 10 independent array of argvalue and 10 independent array of argmax. But only two vectors are obtained here only. Kindly help

Accepted Answer

Image Analyst
Image Analyst on 15 Sep 2022
corr_cell{i,j} is an image. Thus max() will give the max of each column in the image, not the max of the entire image. You'd either have to use (:)
thisImage = normxcorr2(imageArray{i},imageArray{j});
corr_cell{i,j} = thisImage;
[maxValue, indexOfMax] = max(thisImage(:));
maxValues(i, j) = maxValue;
or use the 'all' option (if you have a fairly recent version of MATLAB).
thisImage = normxcorr2(imageArray{i},imageArray{j});
corr_cell{i,j} = thisImage;
[maxValue, indexOfMax] = max(thisImage, 'all');
maxValues(i, j) = maxValue;
to get the max of the entire matrix.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!

Translated by