Adjusting Lab values for an image

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
mikhail
Posts: 4
Joined: 2012-11-09T07:55:42-07:00
Authentication code: 67789

Adjusting Lab values for an image

Post by mikhail »

I want to change chroma (in the sense of the LCHab color space) of an image with some command-line utility. I think ImageMagick is suitable for this task.

I see the modulate command, but it operates only with HSB, HSL and HWB color spaces and affects saturation, not chroma.

It can be done manually, by converting an image to the Lab color space, multiplying a and b coordinates with a given factor, and converting back to the sRGB color space. But is it possible to directly operate the Lab coordinates with ImageMagick? I found only profile conversion functions.

I also see the -fx option, but the documentation is a little frustrating. There is a color function like srgb() and lab(), but it also says that "The -fx operator evaluates the given expression for each channel of each pixel in the first image (u) in the sequence". How to apply those color function if an image is processed for each channel separately?

Or how to convert to Lab colorspace before the processing? I see the -colorspace option, and it works for RGB or Gray values, but not for Lab or XYZ values. At least when used like: "convert.exe src.jpg -colorspace Lab dst.png"
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Adjusting Lab values for an image

Post by fmw42 »

I believe that modulate has been modified recently (IM 6.7.9.0) to allow it to work in HCL colorspace using -define modulate:colorspace=HCL

see
http://www.imagemagick.org/Usage/color_ ... colorspace


If this does not work, then get back and I will help decompose HCL colorspace to modify the C channel. But you need a fairly new version of IM to work with HCL (6.7.9.0) or LAB (6.7.8-2)
mikhail
Posts: 4
Joined: 2012-11-09T07:55:42-07:00
Authentication code: 67789

Re: Adjusting Lab values for an image

Post by mikhail »

fmw42 wrote:I believe that modulate has been modified recently (IM 6.7.9.0) to allow it to work in HCL colorspace using -define modulate:colorspace=HCL
see http://www.imagemagick.org/Usage/color_ ... colorspace
If this does not work, then get back and I will help decompose HCL colorspace to modify the C channel. But you need a fairly new version of IM to work with HCL (6.7.9.0) or LAB (6.7.8-2)
I've tried the HCL color space, but have experienced strange artifacts, where whole image was processed ok, but the white pixels turned black :( I've used "-set option:modulate:colorspace hcl -modulate 100,80" to decrease chroma.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Adjusting Lab values for an image

Post by fmw42 »

Can you post a link to your before and after images, so that they can be analyzed and used to test.

What version of IM and platform are you using?

You may also like to try my script, enhancelab, at the link below, if you are on Linux, Mac OSX or Windows w/Cygwin.
Last edited by fmw42 on 2012-11-09T13:44:51-07:00, edited 1 time in total.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Adjusting Lab values for an image

Post by fmw42 »

OK. I can verify that there does seem to be something odd with modulate in HCL. I will report a possible bug on the Bugs forum.

see possible bug HCL -modulate IM 6.8.0.4 Q16
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Adjusting Lab values for an image

Post by fmw42 »

But is it possible to directly operate the Lab coordinates with ImageMagick? I found only profile conversion functions.
convert image -colorspace LAB \
-channel G -evaluate multiply $afactor +channel \
-channel B -evaluate multiply $bfactor +channel \
-colorspace sRGB resultimage

Note channel R is 0th channel or L, channel G is 1st channel or A, channel B is 2nd channel or B.

You can also try

convert image -colorspace HCL \
-channel G -evaluate multiply 0.8 +channel \
-colorspace sRGB resultimage

See my script, enhancelab, at the link below if you are on Linux, Mac OSX, Window w/Cygwin.
mikhail
Posts: 4
Joined: 2012-11-09T07:55:42-07:00
Authentication code: 67789

Re: Adjusting Lab values for an image

Post by mikhail »

Thanks a lot for your replies! I'll check it at Monday.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Adjusting Lab values for an image

Post by fmw42 »

Note bug in HCL -modulate being worked on now. see viewtopic.php?f=3&t=22244
mikhail
Posts: 4
Joined: 2012-11-09T07:55:42-07:00
Authentication code: 67789

Re: Adjusting Lab values for an image

Post by mikhail »

fmw42 wrote: convert image -colorspace LAB \
-channel G -evaluate multiply $afactor +channel \
-channel B -evaluate multiply $bfactor +channel \
-colorspace sRGB resultimage

You can also try

convert image -colorspace HCL \
-channel G -evaluate multiply 0.8 +channel \
-colorspace sRGB resultimage
The first snipped doesn't work right. I tried the degenerate case with both afactor and bfactor equal to 0 and I expected to acquire a grayscale image. However, the image was of constant blue hue. Apparently, IM's Lab is not CIE Lab.

The second snipped works perfect. It doesn't suffer from strange artifacts on white pixels and operates with pixel's chroma, not saturation. Thanks a lot for your help!
Post Reply