misleading string format for standard_deviation
Posted: 2010-08-04T12:52:33-07:00
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.
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.