Page 1 of 1

misleading string format for standard_deviation

Posted: 2010-08-04T12:52:33-07:00
by fmw42
IM 6.6.3.2 Q16 Mac OSX Tiger

If one uses string formats to get the global std of an image with constant color, then it is not zero as it should be.

Example:

convert -size 100x100 xc:"rgb(230,246,255)" -depth 8 color_230_246_255.gif
convert color_230_246_255.gif -format "%[standard_deviation]" info:
2657.05

I think this is because all channels are combined and global stats are found. This makes sense for min, max and mean (as they are linear functions and can be combine this way), but not for std, which I believe is now generally incorrect in all if not most cases.

I believe that a correct formula is:

std=sqrt(variance_red + variance_green + variance_blue)

where variance for a given channel can be computed as the (mean of the square of the channel values) less the (square of the mean of the channel values), i.e.

channel variance = mean(channel*channel) - mean(channel)*mean(channel)

or (since variance = std^2):

std = sqrt( red_std^2 + green_std^2 + blue_std^2)

Thus a workaround is as follows:

convert image -format \
"%[fx: sqrt(standard_deviation.r^2 + standard_deviation.g^2 + standard_deviation.g^2)]" info:


If the developers decide to leave the string format computation for std as is, so as to keep all computations done in a consistently simplistic manner, then it might be a good idea to post some note about this issue with the std.

If the developers decide not to change the way the std string format works, then I would be willing to post some notes. Let me know.

Re: misleading string format for standard_deviation

Posted: 2010-08-08T09:17:43-07:00
by magick
We can reproduce the problem you posted and have a patch in ImageMagick-6.6.3-4 Beta available by sometime tomorrow. Thanks.

Re: misleading string format for standard_deviation

Posted: 2010-08-08T21:45:28-07:00
by fmw42
Thanks. This now works in IM 6.6.3.4

convert -size 100x100 xc:"rgb(230,246,255)" -depth 8 color_230_246_255.gif
convert color_230_246_255.gif -format "%[standard_deviation]" info:
0

Re: misleading string format for standard_deviation

Posted: 2010-08-09T23:25:43-07:00
by anthony
I think this change is related but am not certain.

Previously this example (from IM Examples, Compare)

Code: Select all

   convert granite: granite.jpg
   convert granite.jpg -solarize 50% -colorspace Gray  granite_bw_test.png
   identify -verbose -alpha off granite_bw_test.png | \
     sed -n '/Histogram/q; /Colormap/q; /statistics:/,$ p' > granite_stats.txt
produced...
Channel statistics:
gray:
min: 56 (0.219608)
max: 106 (0.415686)
mean: 77.8123 (0.305146)
standard deviation: 7.88841 (0.0309349)
kurtosis: -0.2523
skewness: 0.298392
Now it produces
Channel statistics:
Gray:
min: 56 (0.219608)
max: 106 (0.415686)
mean: 77.8123 (0.305146)
standard deviation: 7.88841 (0.0309349)
kurtosis: 39049.1
skewness: 0.298392
note the change in the kurtosis value.

Now I don't know what kurtosis actuall really means, but the fact that the value changes means one of them was wrong. It isn't even a 'normalized' difference.

So the question is... Is it now right, or is it now wrong?

Re: misleading string format for standard_deviation

Posted: 2010-08-15T12:49:36-07:00
by fmw42
Anthony:

In IM 6.6.3.6 Q16 (HDRI), it now shows:


Channel statistics:
Gray:
min: 56 (0.219608)
max: 106 (0.415686)
mean: 77.8123 (0.305146)
standard deviation: 7.88841 (0.0309349)
kurtosis: -0.2523
skewness: 0.298392

Re: misleading string format for standard_deviation

Posted: 2010-08-15T20:52:04-07:00
by anthony
Looks like it has returned to the old result.