Question

Assume that I have a grayscale image. Consider a circular neighborhood window around each pixel. I need to calculate the variance of the pixel values in those circular neighborhoods.

How can I efficiently implement circular neighborhood operations in MatLab?

Was it helpful?

Solution

use matlab's stdfilt to get the local variance.

 J = stdfilt(I, NHOOD)

calculates the local standard deviation of the input image I, where you specify the neighborhood in NHOOD. NHOOD is a multidimensional array of zeros and ones where the nonzero elements specify the neighbors. NHOOD's size must be odd in each dimension. So for circular neighborhood you can use the disk filter with a >0 condition that makes it binary:

 NHOOD = fspecial('disk',radius)>0; 

where radius is some number, the bigger the number the more "circular" the filter, play with it and see...

Last, the local variance is just J.^2

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top