ImageMagick channel mean with Rmagick

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
novito
Posts: 30
Joined: 2013-11-26T17:37:36-07:00
Authentication code: 6789

ImageMagick channel mean with Rmagick

Post 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.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: ImageMagick channel mean with Rmagick

Post 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.
novito
Posts: 30
Joined: 2013-11-26T17:37:36-07:00
Authentication code: 6789

Re: ImageMagick channel mean with Rmagick

Post 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.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: ImageMagick channel mean with Rmagick

Post 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.
novito
Posts: 30
Joined: 2013-11-26T17:37:36-07:00
Authentication code: 6789

Re: ImageMagick channel mean with Rmagick

Post 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?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: ImageMagick channel mean with Rmagick

Post 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.
novito
Posts: 30
Joined: 2013-11-26T17:37:36-07:00
Authentication code: 6789

Re: ImageMagick channel mean with Rmagick

Post 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?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: ImageMagick channel mean with Rmagick

Post by snibgo »

Probably: divide it by 65535.
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: ImageMagick channel mean with Rmagick

Post 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.
Post Reply