Page 1 of 1

Requested Enhancement To List of String Formats

Posted: 2008-02-25T18:05:59-07:00
by fmw42
I know you all are busy, so this is not a high priority, but a when you can request (or add to enhancement list) as there are workarounds, but I use them frequently when doing scripting. Would it be possible to add a few more string formats to the list you have to be able to retrieve the min, max, mean and standard deviation from an image channel or a grayscale image? These could potentially be %L, %H, %M and %S (or whatever you want) so that I could do something like:

mean=`convert <rgbimage> -channel Red -separate -format "%M" info:`

mean=`convert <grayscaleimage> -format "%M" info:`

to get and store the mean of the image, etc for std and min and max.

Or however that would be implemented appropriately.

Thanks for considering this.

Fred

P.S. My workaround for a grayscale image is as follows (with help from Anthony):

function imagestats
{
data=`convert $infile -verbose info:`
min=`echo "$data" | sed -n '/^.*Min:.*[(]\([0-9.]*\).*$/{ s//\1/; p; q; }'`
max=`echo "$data" | sed -n '/^.*Max:.*[(]\([0-9.]*\).*$/{ s//\1/; p; q; }'`
mean=`echo "$data" | sed -n '/^.*Mean:.*[(]\([0-9.]*\).*$/{ s//\1/; p; q; }'`
std=`echo "$data" | sed -n '/^.*Standard.*[(]\([0-9.]*\).*$/{ s//\1/; p; q; }'`
}

Re: Requested Enhancement To List of String Formats

Posted: 2008-02-25T18:44:56-07:00
by magick
The following enhancements are available in ImageMagick 6.3.9-1 Beta:
  • convert image.jpg -format '%[mean]' info:
    convert image.jpg -format '%[standard-deviation]' info:
    convert image.jpg -format '%[min]' info:
    convert image.jpg -format '%[max]' info:

Re: Requested Enhancement To List of String Formats

Posted: 2008-02-25T21:34:08-07:00
by fmw42
Wow! That was fast? You are terrific!

What happens if the image is RGB not grayscale? Do you get multiple values that need to be separated?

Not to look a "gift-horse" in the mouth, but would it make sense to shorten the %[standard-deviation] to %[std] (for less typing) or do you think that would not be understood by most people?

Re: Requested Enhancement To List of String Formats

Posted: 2008-02-26T07:26:02-07:00
by magick
The ImageMagick designer preference is to use descriptive names whenever possible as a form of self-documenting. We documented the names in the web pages under -format.

The values returned are based on the setting of -channel. If you do not set -channel, you get the mean, for example, for red, green, and blue combined.

Re: Requested Enhancement To List of String Formats

Posted: 2008-02-26T18:59:47-07:00
by fmw42
Thanks. I understand with regard to your naming conventions. I will test this out at my earliest possibility. I look forward to using it. Thanks for the heads-up about the -channel setting. This should work just fine.