MATLAB Answers

Correlation coefficient in 3D

조회 수: 34(최근 30일)
Alexander Collins
Alexander Collins 15 Jun 2020
편집: the cyclist 16 Jun 2020
I need to calculate the correlation between two 3D volumes. I've tried implementing Pearson's coefficient since it's well recognised in the literature but it only seems to spit out meaningless answers (see code snippet below):
A = volume1 - mean(volume1, 'all');
B = volume2 - mean(volume2, 'all');
num = sum(A .* B, 'all');
den1 = sum(A.^2, 'all');
den2 = sum(B.^2, 'all');
r = num ./ (den1 .* den2)^0.5;
Is there something I'm doing wrong here? What alternative correlations metrics might work in this context?

  댓글 수: 0

댓글을 달려면 로그인하십시오.

답변(1개)

the cyclist
the cyclist 15 Jun 2020
편집: the cyclist 15 Jun 2020
Your formulas for den1 and den2 are not symmetric. It looks like den2 does not correspond to the formula in the screenshot, and should instead be
den2 = sum(B.^2, 'all');

  댓글 수: 4

표시 이전 댓글 수: 1
the cyclist
the cyclist 15 Jun 2020
OK. In that case, can you upload your data, or a sample that exhibits the problem? (Please upload the data in a MAT file, using the paper clip icon, not just an image.)
Also, please be more specific about what you mean by "meaningless" answers.
Alexander Collins
Alexander Collins 16 Jun 2020
No problem. The correlation coefficient should =+1 for perfectly correlated data (i.e. identical volumes/images), 0 for completely uncorrelated data, and -1 for perfectly anti-correlated data.
I found that with this naive implementation I would get coefficients wildly outside this range.
Really my question was trying to get more at the theoretical side of things than the way I've written the code above - what's the best way to find a correlation coefficient between two 3D matrices?
the cyclist
the cyclist 16 Jun 2020
Again, it would be useful if you uploaded your data, or small sample that shows a value outside the range [-1,1].
That is the correct formula for the Pearson correlation coefficient, and you have coded it correctly. So it must be something in the data. Did you convert the data to column vectors, so that volume1 and volume2 both column vectors? If not, then I'm guessing your formula is doing an implicit expansion that you are not expecting, which means the formula is not calculating what you want.

댓글을 달려면 로그인하십시오.

Community Treasure Hunt

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

Start Hunting!

Translated by