Can IM define output levels as in Photoshop?

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
the-ninth
Posts: 27
Joined: 2010-12-25T09:22:24-07:00
Authentication code: 8675308

Can IM define output levels as in Photoshop?

Post by the-ninth »

Hi,

The Levels filter from Photoshop can define Output Levels, i.e. the highest and lowest luminance values to be used in the image.

The ImageMagick -level parameter does not have these settings. Is there any other way to achieve them?

Thanks, Robert
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Can IM define output levels as in Photoshop?

Post by fmw42 »

the-ninth
Posts: 27
Joined: 2010-12-25T09:22:24-07:00
Authentication code: 8675308

Re: Can IM define output levels as in Photoshop?

Post by the-ninth »

Hi Fred,

How would I have to use these functions to achieve the Photoshop Output Level result? These functions seem to focus on the stretching aspect of the Levels filter, but the Output Level is more a compression. For example, take the whole luminance range of 0-255 of a given a picture and compress it to a window of 0-215. In this example there would not be any real white in the picture any more.

Cheers, Robert
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Can IM define output levels as in Photoshop?

Post by fmw42 »

Robert,

I am not sure what you wanted to do. I thought you wanted to specify the clip values so as to stretch the image. If you don't want to stretch the image, but compress the values, then use -level to increase contrast or +level to decrease contrast. It works on raw graylevel values or percent graylevel values (not percent counts as does -contrast-stretch). And they both allow a gamma value

I believe from what you are asking you need to use +level

However, the raw graylevel values are dependent upon your IM compile Q value. For Q16 those values would be 0 to 65535. For Q8 they would be 0 to 25. So the best thing would be to convert your values to percent, i.e. 100x215/255=84%. So you would use +level 0x84%

see
http://www.imagemagick.org/script/comma ... .php#level
http://www.imagemagick.org/Usage/color_mods/#level
http://www.imagemagick.org/Usage/color_mods/#level_plus
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Can IM define output levels as in Photoshop?

Post by anthony »

To only level luminance, convert the image to a colorspace with luminance, and level just that!

For example...

Code: Select all

   convert rose: -colorspace HSL -channel B -level 25,75% +channel -colorspace RGB rose_level_luminance.png
NOTE in HSL colorspace luminance is stored in the 'Blue' channel.
See Separating Channels.
http://www.imagemagick.org/Usage/color_basics/#separate

I don't have a section specifically taking about HSL/HSB colorspace as yet, just indirectly as part of various operators.

Also see Modulate Operator
http://www.imagemagick.org/Usage/color_mods/#modulate
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Can IM define output levels as in Photoshop?

Post by fmw42 »

Better to use YUV or YCbCr to get the luminance channel to level. The luminance channel is the Y or first channel in both cases.

see
http://www.imagemagick.org/script/comma ... colorspace
Last edited by fmw42 on 2011-10-10T17:52:48-07:00, edited 1 time in total.
the-ninth
Posts: 27
Joined: 2010-12-25T09:22:24-07:00
Authentication code: 8675308

Re: Can IM define output levels as in Photoshop?

Post by the-ninth »

Thanks guys, I'll try these commands.

Cheers, Robert
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Can IM define output levels as in Photoshop?

Post by fmw42 »

To adjust the input and output levels, you probably need to use a combination of -level followed by +level.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Can IM define output levels as in Photoshop?

Post by fmw42 »

I have uploaded a new script, levels, to my web site below, to simulate the Photoshop-like levels processing.
the-ninth
Posts: 27
Joined: 2010-12-25T09:22:24-07:00
Authentication code: 8675308

Re: Can IM define output levels as in Photoshop?

Post by the-ninth »

Hi Fred,

Thanks a lot, that is very useful!

Cheers, Robert
Post Reply