Cross Correlation Map for stack of images

18 vues (au cours des 30 derniers jours)
João Paulo Castro Zerba
João Paulo Castro Zerba le 20 Août 2019
Hello guys,
I am wondering if someone here could help me with correlation map.
Basically I have some stacks of images and I would like to cross correlate them using the Pearson
Correlation coefficient formula below.
Ai and Bi are the intensity values for a particular pixel in the pattern, Abar and Bbar are the
mean values of the intensities and sigmaA and sigmaB are the standard deviations for the two CXD
patterns, A and B. The sum is evaluated over the 3D stack of images.
Anything would be nice. I have ran out of clues to implement this properly.
Basically in my script I have the following, sending to my pearson correlation function the stack of pixels:
for i=1:size(crop_cell,2)%Running over the cell stacks
for j=1:size(crop_cell,2)%Running over the cell stacks
for k=1:size(crop_cell{1},1)%Running over the rows
for L=1:size(crop_cell{1},2)%Running over the columns
corr_matrix{i,j}(k,L) = pearson_corr_scores_pix(crop_cell{i}(k,L,:),crop_cell{j}(k,L,:));
end
end
end
end
And the correlation function:
function [p] = pearson_corr_scores_pix(a,b)
mean_a = mean(a);
mean_b = mean(b);
fac_a = a - mean_a;
fac_b = b - mean_b;
std_a = std2(a);
std_b = std2(b);
score_a = fac_a/std_a;
score_b = fac_b/std_b;
p = (1/(length(a)-1))*sum(score_a.*score_b);
end
Attached is my result(first) and a reference result (second) I would like to reach.
Mine is somehow not taking into account the correlation with all the stack of pixels
in the image? I don't know.
Thanks

Réponse acceptée

Subhadeep Koley
Subhadeep Koley le 23 Août 2019
Find the attached Pearson Correlation Coefficient function myPCC.m implemented in terms of covariance according to the documentation.
Run the following script to get the PCC Map.
close all;clc;
% read all images from your folder and making them of same dimension
myFolder = 'your_path';
if ~isfolder(myFolder)
errorMessage = sprintf('Error: The following folder does not exist:\n%s', myFolder);
uiwait(warndlg(errorMessage));
return;
end
filePattern = fullfile(myFolder, '*.tiff');% change the extension according to your file extension
tiffFiles = dir(filePattern);
for k = 1:length(tiffFiles)
baseFileName = tiffFiles(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 PCC for every image combinations
for i=1:size(imageArray,2)
for j=1:size(imageArray,2)
corr_cell(i,j)=myPCC(imageArray{i},imageArray{j});
end
end
% plotting the Pearson Cross Correlation Coefficient Matrix
imagesc(rot90(flipud(corr_cell)));
colormap(parula);
set(gca,'YDir','normal');
set(gca, 'XTick', 1:2:length(tiffFiles));
set(gca, 'YTick', 1:2:length(tiffFiles));
title('Pearson Cross Correlation Coefficient Matrix');
colorbar; axis square;
PCC_matrix.png

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by