Correlation between 1 number and set of numbers

4 次查看(过去 30 天)
Hello,
I have a 500x500 matrix of numbers and NaN values. I want to determine the average correlation coefficient between a pixel and its nearest 8 neighbors (3x3 grid) while omitting NaN values from the calculation. My output will then be a 500x500 matrix of correlation coefficients and NaN values. When calculating values on the edge of the matrix, I will use however many neighbors surround the pixel of interest in the 3x3 grid.
Any ideas on how to do this? I am aware of the corrcoef command, but I don't know how to make it work for the comparison of multiple numbers.
Thanks in advance.
MATLAB Version: 9.5.0.944444 (R2018b)

回答(1 个)

Image Analyst
Image Analyst 2019-12-13
One way to do it is to use nlfilter(). I'm attaching a demo. Inside your custom function you'd take the local neighborhood and extract only the non-nan values with isnan(), then call corrcoeff() on those non-nan values only.
Attach your image in a .mat file, and your code if you can't figure out how to adapt it.

Community Treasure Hunt

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

Start Hunting!

Translated by