Re: Array statistics [message #9776] |
Mon, 11 August 1997 00:00 |
J.D. Smith
Messages: 214 Registered: August 1996
|
Senior Member |
|
|
David R. Klassen wrote:
>
> I was wondering if there were an easy way to take a 2-D array
> and create a new array of the same size/dimension but where
> each pixel is the variance of some subset of itself and surrounding
> pixels.
>
> In other words, I'm looking for something akin to the SMOOTH
> function but instead of doing a boxcar average, does a "boxcar
> variance".
>
> --
> David R. Klassen
You can do this with the smooth method itself, since the variance is the
average of the square deviation (up to an n-1):
bw2=box_width^2
;; compute the boxcar average
avg=smooth(image,box_width)
;; compute square deviation
dev=(image-avg)^2
;; compute the boxcar variance (average square deviation)
var=smooth(dev,box_width)*bw2/(bw2-1)
I strongly suggest using the nasa routine filter_image in place of
smooth or median for boxcar statistics (average or median) since it
takes care of edges, given the keyword ALL_PIXELS. Note, if you want to
calculate variance *not including* the central pixel (my preferred
method):
avg=(smooth(image,box_width)*bw2-image)/(bw2-1)
dev=(image-avg)^2
var=(smooth(dev,box_width)*bw2-dev)/(bw2-2)
Good luck.
JD
|
|
|