How to get %[fx:standard_deviation] from PerlMagick?

PerlMagick is an object-oriented Perl interface to ImageMagick. Use this forum to discuss, make suggestions about, or report bugs concerning PerlMagick.
Post Reply
kbro
Posts: 6
Joined: 2011-05-31T13:01:17-07:00
Authentication code: 8675308

How to get %[fx:standard_deviation] from PerlMagick?

Post by kbro » 2011-05-31T13:46:12-07:00

I've been experimenting with commandline ImageMagick, and

Code: Select all

identify -format "%[fx:standard_deviation]" file.jpg
tells me the value I'm interested in. However, I can't see how to get the same info from PerlMagick.

Code: Select all

img->Fx(expression=>'standard_deviation')
doesn't do it, and

Code: Select all

img->Statistics()
returns a list which includes standard deviation, but separately for each colour channel.

So is there a way to get the standard_deviation value directly, or maybe calculate it from the per-channel values (maybe I can square each one, add them together and take the square root? Stats was a loooong time ago!)

Thanks

kbro
Posts: 6
Joined: 2011-05-31T13:01:17-07:00
Authentication code: 8675308

Re: How to get %[fx:standard_deviation] from PerlMagick?

Post by kbro » 2011-06-02T15:10:51-07:00

I was close with my guess about calculating it from the stddev for the separate channels. It seems that if I square each stddev, add them together, divide by the number of channels, then take the square root, then I get something close to the overall stddev reported by identify.

This sorta makes sense, because the variance is the mean of the squares of the differences between each value and the mean for the population, but my hack can't be completely right because each channel has its own mean.

User avatar
fmw42
Posts: 25566
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How to get %[fx:standard_deviation] from PerlMagick?

Post by fmw42 » 2011-06-02T15:34:31-07:00

I don't know Perlmagick at all. But try lumping all the channel data together and use

std=sqrt( ave(G^2) - square(ave(G)) )

ie. std= sqrt(variance)

where G is graylevel value

see http://en.wikipedia.org/wiki/Variance#Definition

or

append all the channels together and use -fx to get the standard_deviation

Post Reply