Lab Implementation

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
stupid
Posts: 51
Joined: 2010-02-12T07:30:34-07:00
Authentication code: 8675308

Lab Implementation

Post by stupid »

Hi all.

I've just been attempting to sharpen images using the L channel of Lab. This should be straightforward but the overall brightness/gamma is substantially altered. An example:

Running -colorspace Lab -channel R -unsharp "0x0.8" +channel on

Image

produces...

Image

I've tried this same method using HSB, HSL, YUV, brightness and lightness channels and everything works normally. Is this an oddity in your implementation of Lab, something to do with the USM, or contention between the two?

Thanks.



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

Re: Lab Implementation

Post by fmw42 »

I am not an expert on this, so take with a grain of salt. see http://en.wikipedia.org/wiki/Lab_color_space

LAB may not be totally reversible when transforming to RGB (as LAB has a larger gamut than RGB), and L may not be linear. One or both may be the cause of your results, which I verified on IM 6.6.1-9 Q16 Mac OSX Tiger.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Lab Implementation

Post by fmw42 »

I tried a simple round trip RGB to LAB to RGB and got the same color change.

convert img2641d.jpg -colorspace LAB -separate -set colorspace LAB -combine -colorspace RGB img2641d_test3.jpg

convert img2641d.jpg -strip -colorspace LAB -separate -set colorspace LAB -combine -colorspace RGB img2641d_test4.jpg

convert img2641d.jpg -colorspace LAB -set colorspace LAB -colorspace RGB img2641d_test5.jpg

convert img2641d.jpg -colorspace LAB miff:- | convert - -set colorspace LAB -colorspace RGB img2641d_test6.jpg

All of these produced the same color change you noticed.

I don't know if this a problem with LAB colorspace large gamut or a bug with IM.
stupid
Posts: 51
Joined: 2010-02-12T07:30:34-07:00
Authentication code: 8675308

Re: Lab Implementation

Post by stupid »

Hey, fmw42. Thanks for the response.

Yup, I understand the difference between Lab and RGB; but the result of flipping modes should be barely perceptible - if at all - to the human eye. Photoshop manages translations Lab/RGB - RGB/Lab well enough so I expected ImageMagick to be similar - swapping to Lab is a fairly standard trick to avoid shifting hues (and noise) when sharpening. Looks like I'm back to two-layer sharpening then!


Thanks again!



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

Re: Lab Implementation

Post by fmw42 »

I understand what you are saying and I would expect a round trip to be reversible.

Post a message in the Bugs forum at viewforum.php?f=3 pointing back to this topic in the User's forum and it will likely get looked at by the IM folks as a potential bug.

As you are offline, I have gone ahead and posted to the bugs forum
stupid
Posts: 51
Joined: 2010-02-12T07:30:34-07:00
Authentication code: 8675308

Re: Lab Implementation

Post by stupid »

Yes. Not a bad idea.



Jo
Post Reply