Photoshop/GIMP like "Levels" using ImageMagick

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
Posts: 4
Joined: 2016-09-09T01:39:49-07:00
Authentication code: 1151

Photoshop/GIMP like "Levels" using ImageMagick

Post by andrixnet » 2017-08-09T03:29:40-07:00

The "Levels" command is well known to Photoshop or GIMP users, and quite useful.
ImageMagick supports the same function using the

Code: Select all

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

Posts: 10690
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Photoshop/GIMP like "Levels" using ImageMagick

Post by snibgo » 2017-08-09T04:26:16-07:00

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.
snibgo's IM pages:

Post Reply