Adjust Channel Levels

The MagickWand interface is a new high-level C API interface to ImageMagick core methods. We discourage the use of the core methods and encourage the use of this API instead. Post MagickWand questions, bug reports, and suggestions to this forum.
Post Reply
sanmarcos
Posts: 3
Joined: 2011-06-03T11:09:16-07:00
Authentication code: 8675308

Adjust Channel Levels

Post by sanmarcos »

I am trying to replicate a Photoshop effect. Image > Adjustments > Levels

Settings:
red: 0, 1.11, 230
green: 0, 1.14, 238
blue: 29, .81, 255
combined: 11, 1.29, 247

Input image:
Image

Output image:

Image

I tried doing something like

Code: Select all

MagickSepiaToneImage(magick_wand, 0.8 * QuantumRange);
But this isn't really a sepia effect, it is more of a 'washed' look
el_supremo
Posts: 1015
Joined: 2005-03-21T21:16:57-07:00

Re: Adjust Channel Levels

Post by el_supremo »

Sorry, my ISP shutdown all personal webspace so my MagickWand Examples in C is offline.
See my message in this topic for a link to a zip of all the files.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Adjust Channel Levels

Post by fmw42 »

In command line mode, try this (the conversion by quantum range is not needed if you are running Q8 IM otherwise you need to specify colors within the full quantumrange 0-65535 for Q16 or convert to 0-100 percent values):


r1=0
r2=`convert xc: -format "%[fx:quantumrange*230/255]" info:`
g1=0
g2=`convert xc: -format "%[fx:quantumrange*238/255]" info:`
b1=`convert xc: -format "%[fx:quantumrange*29/255]" info:`
b2=255
convert dWe0q.png \
-channel r -level $r1,$r2,1.11 +channel \
-channel g -level $g1,$g2,1.14 +channel \
-channel b -level $b1,$b2,0.81 +channel \
dWe0q_result.png


see -level at http://www.imagemagick.org/Usage/color_mods/#levels

Note I edited the values to correct some copying mistakes on the values.
Last edited by fmw42 on 2011-06-03T16:23:11-07:00, edited 5 times in total.
sanmarcos
Posts: 3
Joined: 2011-06-03T11:09:16-07:00
Authentication code: 8675308

Re: Adjust Channel Levels

Post by sanmarcos »

I used this, which gets a pretty close result to what I needed.
MagickLevelImageChannel(magick_wand, RedChannel, 0.0, 1.11, 230);
MagickLevelImageChannel(magick_wand, GreenChannel, 0.0, 1.14, 238);
MagickLevelImageChannel(magick_wand, BlueChannel, 29, 0.81, 255);
Targetted image:
Image

ImageMagick produced image:
Image

I must point out that Photoshop is doing this with its level corrections, not sure if ImageMagick has any counterparts to this:
Image
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Adjust Channel Levels

Post by fmw42 »

try adding -contrast-stretch 1% or 2% (or the equivalent -- adjust as needed) after the -level to account for the clipping included in PS
el_supremo
Posts: 1015
Joined: 2005-03-21T21:16:57-07:00

Re: Adjust Channel Levels

Post by el_supremo »

I tried this out with MagickWand and when I add a MagickLevelImage to do the "combined" parameters you gave, it seems to be pretty close to your target image.
Add this after the others:

Code: Select all

MagickLevelImage(magick_wand,11,1.29,247);
Pete
Sorry, my ISP shutdown all personal webspace so my MagickWand Examples in C is offline.
See my message in this topic for a link to a zip of all the files.
sanmarcos
Posts: 3
Joined: 2011-06-03T11:09:16-07:00
Authentication code: 8675308

Re: Adjust Channel Levels

Post by sanmarcos »

I have made some adjustments, and it is so close that if it I did not have the images side by side, I could not tell the difference. One of them looks slightly darker/lighter, no big deal.

Thanks for your help!

Code: Select all

        MagickLevelImageChannel(magick_wand, RedChannel, 0.0, 1.11, 230);
        MagickLevelImageChannel(magick_wand, GreenChannel, 0.0, 1.14, 238);
        MagickLevelImageChannel(magick_wand, BlueChannel, 29, 0.81, 255);                
        MagickLevelImage(magick_wand, 11, 1.29, 247);
        MagickContrastStretchImage(magick_wand, 0.10, 0.10);
Post Reply