
Neighborhood Processing 115
p
B
D
A
C
FIGURE 5.22: Alternative neighborhoods for a Kuwahara filter
MATLAB/Octave
>> cd = float(c);
>> cdm = imfilter(cd,ones(3)/9,’symmetric’);
>> cd2f = imfilter(cd.^2,ones(3)/9,’symmetric’);
>> cdv = cd2f - cdm.^2;
Python
In: cd = float32(c)
In: cdm = ndi.uniform
_
filter(cd,(3,3))
In: cd2f = ndi.uniform
_
filter(cd
**
2,(3,3))
In: cdv = cd2f - cdm
**
2
At this stage, the array cdm contains all the mean values, and cdv contains all the variances.
At every point (i, j) in the image then:
1. Compute the list
vars = [cdv(i − 1, j − 1), cdv( i − 1, j + 1), cdv(i + 1, j − 1), cdv(i + 1, j + 1)] .
2. Also compute the list
means = [cdm(i − 1,