Page 1 of 1

ImageMagick channel mean with Rmagick

Posted: 2014-01-03T15:47:30-07:00
by novito
Hi there,

I have used identify verbose in order to get standard deviation of a grayscale channel and it has worked great (values between 0 and 1).

Right now I have tried doing the following:

Code: Select all

def standard_deviation
   # Image is a RMagick object
    grayscale = @image.quantize(number_colors=256, colorspace=Magick::GRAYColorspace)
    p grayscale.channel_mean
    grayscale.write('grayscaled.png')
end
And I see the following values:

[16068.833636363637, 2110.3275912339077]

How is it possible that the standard deviation is above 1? Here is the documentation for #channel_mean: http://rubydoc.info/github/rmagick/rmag ... annel_mean

I am not sure what am I missing here.

Re: ImageMagick channel mean with Rmagick

Posted: 2014-01-03T15:52:45-07:00
by fmw42
IM statistics are given in two forms. One is in the range 0 to Quantumrange (0 to 255 or 0 to 65535 depending upon IM compile Qvalue). The other is normalized to the range 0 to 1. It is the one in parenthesis.

The value of the standard deviation is not limited to 0 to 1. It depends upon the range of values supplied. If the values are raw values 0 to 255 (8-bit) or 0 to 65535 (16-bit), then they will likely always be larger than one.

In command line, you can use string format %[standard_deviation]. see http://www.imagemagick.org/script/escape.php, which I believe returns the std in the range 0 to Quantumrange. You can also use %[fx:standard_deviation] and get the results in the range 0 to 1. see http://www.imagemagick.org/script/fx.php

To be honest, I do not have any idea what you are getting returned and why two values. I do not use Rmagick. You seem to be getting the mean and not the standard deviation. I do not see where you would be getting the std from your code.

Re: ImageMagick channel mean with Rmagick

Posted: 2014-01-03T16:07:56-07:00
by novito
Thanks for the quick reply.

According to the documentation, channel_mean method would return the following: "Return an array of the mean and standard deviation for the channel." First would be the mean, and second the standard deviation.

Re: ImageMagick channel mean with Rmagick

Posted: 2014-01-03T17:01:17-07:00
by fmw42
novito wrote:Thanks for the quick reply.

According to the documentation, channel_mean method would return the following: "Return an array of the mean and standard deviation for the channel." First would be the mean, and second the standard deviation.

OK. Thanks for the update. I do not use Rmagick, so that is new to me. So your values would indicate that you are using Q16 IM and getting the mean and std in the range 0 to 65535.

Re: ImageMagick channel mean with Rmagick

Posted: 2014-01-06T11:36:10-07:00
by novito
Oh ok...

I am a little bit confused then. How would I get the values in the same range that I used to get with Mogrify and verbose mode?

Re: ImageMagick channel mean with Rmagick

Posted: 2014-01-06T12:53:28-07:00
by fmw42
identify -verbose yourimage

or

convert yourimage -verbose info:

give the same range of values. IM statistics from -verbose are presented two ways. Raw values in the range 0 to Quantumrange and in parenthesis in the range 0 to 1.

If that does not answer your question, then please clarify. But again I know nothing about Rmagick.

I am puzzle where does mogrify come in. You have not mentioned that before. I am not sure mogrify is even appropriate as it expects one output image for each input image. If -verbose is valid for mogrify, then the results should be the same as for convert or identify.

Re: ImageMagick channel mean with Rmagick

Posted: 2014-01-06T16:25:05-07:00
by novito
Sorry, I meant identify.

My question was more like, how could I convert the range that Rmagick gives me, to the range that identify gives me?

Re: ImageMagick channel mean with Rmagick

Posted: 2014-01-06T16:29:08-07:00
by snibgo
Probably: divide it by 65535.

Re: ImageMagick channel mean with Rmagick

Posted: 2014-01-06T17:31:29-07:00
by fmw42
novito wrote:Sorry, I meant identify.

My question was more like, how could I convert the range that Rmagick gives me, to the range that identify gives me?
They both give the same values. They are in the range 0 to quantum range which for Q16 compile is 0 to 65535, if you use the values from the verbose statistics in identify that is not in parenthesis.