Getting values used for -auto-level?

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
wildbug
Posts: 21
Joined: 2008-06-18T12:53:24-07:00

Getting values used for -auto-level?

Post by wildbug »

I'm working with some raw grayscale image data currently, and I'm a little new to reading raw data. While initially trying to read these files, I was getting solid black images, and I thought I had the wrong arguments until I added -auto-level and the image finally appeared.

That would be good enough, except that I'm working with a series of related images, and -auto-level generates slightly different levels for each of them. I'd like to use the same values for all of them so that they'll be consistent. Is there a way to see what -auto-level is doing or a way to find some sane values for -level that I can then apply to every image?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Getting values used for -auto-level?

Post by fmw42 »

-auto-level (by default) finds the min and max overall values (from the combined RGB channels) and then stretches the min to black and the max to white. (it also can be set to stretch each channel separately by prefacing with -channel RGB)

you can get the overall min and max from the verbose info of the image

convert image -verbose info:

or from string formats

convert image -format "%[min]" info:
convert image -format "%[max]" info:

see
http://www.imagemagick.org/script/escape.php


If you want to get the min and max of all your images, you can write a loop and collect the min and max values and find the min and max of them all. But easier would be to append all the images together and then get the min and max of the appended image.

Then you can just use -level min,max to stretch all the images with the same values.

see
http://www.imagemagick.org/script/comma ... php#append
http://www.imagemagick.org/Usage/layers/#append
http://www.imagemagick.org/Usage/color_mods/#level
wildbug
Posts: 21
Joined: 2008-06-18T12:53:24-07:00

Re: Getting values used for -auto-level?

Post by wildbug »

That's perfect; thank you!
Post Reply