Requested Enhancement To List of String Formats

Questions and postings pertaining to the development of ImageMagick, feature enhancements, and ImageMagick internals. ImageMagick source code and algorithms are discussed here. Usage questions which are too arcane for the normal user list should also be posted here.
Post Reply
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Requested Enhancement To List of String Formats

Post 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; }'`
}
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Requested Enhancement To List of String Formats

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

Re: Requested Enhancement To List of String Formats

Post 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?
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Requested Enhancement To List of String Formats

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

Re: Requested Enhancement To List of String Formats

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