Page 1 of 1
Adjusting Lab values for an image
Posted: 2012-11-09T08:05:47-07:00
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"
Re: Adjusting Lab values for an image
Posted: 2012-11-09T11:40:00-07:00
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)
Re: Adjusting Lab values for an image
Posted: 2012-11-09T12:01:42-07:00
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.
Re: Adjusting Lab values for an image
Posted: 2012-11-09T12:09:51-07:00
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.
Re: Adjusting Lab values for an image
Posted: 2012-11-09T13:15:20-07:00
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
Re: Adjusting Lab values for an image
Posted: 2012-11-09T13:42:24-07:00
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.
Re: Adjusting Lab values for an image
Posted: 2012-11-10T01:19:18-07:00
by mikhail
Thanks a lot for your replies! I'll check it at Monday.
Re: Adjusting Lab values for an image
Posted: 2012-11-10T11:28:58-07:00
by fmw42
Note bug in HCL -modulate being worked on now. see
viewtopic.php?f=3&t=22244
Re: Adjusting Lab values for an image
Posted: 2012-11-12T02:40:25-07:00
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!