Page 1 of 1

Photoshop/GIMP like "Levels" using ImageMagick

Posted: 2017-08-09T03:29:40-07:00
by andrixnet
The "Levels" command is well known to Photoshop or GIMP users, and quite useful.
ImageMagick supports the same function using the

Code: Select all

-level
command line option (not discussing APIs). This is documented here

According to the docs, one can specify

Code: Select all

-level black_point,white_point
(not interested in gamma at this point).
The range for these parameters is 0 to QuantumRange, or from 0 to 100%. "QuantumRange" being the maximum possible value according to pixel depth. For 8bit/channel RGB images (the usual), it would be 255.0.
It also says:
If a % sign is present anywhere in the string, both black and white points are percentages of the full color range.
Now here is my problem:

This works fine, when using percentages:

Code: Select all

convert SOME_IMAGE -level 10%,90% OUTPUT_IMAGE
When using actual values, like I would specify in Photoshop or GIMP, all I get is a white image:

Code: Select all

convert SOME_IMAGE -level 92,243 OUTPUT_IMAGE
Am I doing something wrong?
I've also looked here but all examples are using percentages.

How can I apply a "Levels" with ImageMagick, preferably without resorting to bc to perform floating point percentage calculations from my actual numerical values?

Thank you.

Tested with
Version: ImageMagick 6.8.6-10 2016-05-30 Q16

Re: Photoshop/GIMP like "Levels" using ImageMagick

Posted: 2017-08-09T04:26:16-07:00
by snibgo
andrixnet wrote:For 8bit/channel RGB images (the usual), it would be 255.0. ... Q16
QuantumRange is determined not by the image but by the build of your IM, which is "Q16", so quantum is 63335.

As a general rule, percentages are easier.