Please use CIE LCH for transfer modes Colorize, Luminize etc

Questions and postings pertaining to the development of ImageMagick, feature enhancements, and ImageMagick internals. ImageMagick source code and algorithms are discussed here. Usage questions which are too arcane for the normal user list should also be posted here.
Post Reply
KonfuseKitty
Posts: 18
Joined: 2010-07-16T15:54:28-07:00
Authentication code: 8675308

Please use CIE LCH for transfer modes Colorize, Luminize etc

Post by KonfuseKitty »

As soon as I started using Colorize and Luminize transfer modes that ImageMagick provides, I noticed that the output is of the same rather poor quality as Color and Value transfer modes in GIMP 2.6.8, the current stable version. I use Colorize for reducing colour noise, by blurring a copy of the image and merging it with the original using Colorize. However, the procedure accentuates luminance noise. I joined up with the Gimp developer mailing list, posted about it, and was directed to this bug report:

http://bugzilla.gnome.org/show_bug.cgi?id=325564

It is clear from the discussion in the comments of the bug report, and from the samples that the posters provided, that better results are achieved if the CIE LCH mode is used for these transfer modes. If you read that discussion, you will note that the bug is considered fixed, since GIMP is moving to using GEGL projection, which does use CIE LCH.

So I'd like to make a plea to the ImageMagick developers to effect a similar improvement in IM. It is a sad fact, that at this point in time, as we wait for the next stable release of GIMP, there is simply no application on Linux that offers a correctly functioning Color(ize) transfer mode. Krita suffers from the same problem.

Thank you for listening! :)
KonfuseKitty
Posts: 18
Joined: 2010-07-16T15:54:28-07:00
Authentication code: 8675308

Re: Please use CIE LCH for transfer modes Colorize, Luminize

Post by KonfuseKitty »

I've been able to hack a useable workaround:

Code: Select all

convert test.tif -colorspace lab -channel r -separate test-L.tif
convert test-L.tif \( test.tif -gaussian-blur 0x2 -colorspace lab -separate \) -delete 1 -set colorspace lab -channel rgb -combine -colorspace rgb - | display -
As you can see, this takes the image where I want to reduce colour noise and saves out the L component of its Lab colour space; then, after blurring the original RGB image, combines the blurred A and B Lab components with the saved non-blurred L component. It produces the correct result, it doesn't accentuate luma noise, even at very high blur settings.

Still, it would be good if Colorize and Luminize (from different ends of the string, so to speak) performed the feat. It would be faster as it wouldn't entail writing the initial L component to disk. I haven't been able to avoid that.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Please use CIE LCH for transfer modes Colorize, Luminize

Post by fmw42 »

try this


convert tmp.tif \
\( -clone 0 -colorspace lab -channel r -separate \) \
\( -clone 0 -gaussian-blur 0x2 -colorspace lab -separate -delete 0 \) \
-delete 0 -set colorspace lab -channel rgb -combine - | display -
KonfuseKitty
Posts: 18
Joined: 2010-07-16T15:54:28-07:00
Authentication code: 8675308

Re: Please use CIE LCH for transfer modes Colorize, Luminize

Post by KonfuseKitty »

Thank you, the script looked promising as I hadn't tried the -delete 0 within the parenthesis, but I'm afraid I get the same result as with my previous attempts: a slightly sepia tinted grayscale image. Does it work correctly for you? I'm using IM 6.6.2-6 Q16.

Edit: the output is cyan with the script as is, sepia grayscale if I end it with ... "-combine -colorspace rgb - | display -"
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Please use CIE LCH for transfer modes Colorize, Luminize

Post by fmw42 »

It was interesting with the example I tried, if I used ... -combine - | display -, I got sepia, but if I used ... -combine show:, I got cyan.

If I just save a file, I get the same sepia tone result.
Last edited by fmw42 on 2010-07-27T12:20:53-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: Please use CIE LCH for transfer modes Colorize, Luminize

Post by fmw42 »

This is the correction. I forgot the -respect-parenthesis


convert test.tif -respect-parenthesis \
\( -clone 0 -colorspace lab -channel r -separate \) \
\( -clone 0 -gaussian-blur 0x2 -colorspace lab -separate -delete 0 \) \
-delete 0 -set colorspace lab -combine -colorspace rgb show:

Or replace show: with miff:- | display -


By the way, your -channel rgb before the combine is not needed.
KonfuseKitty
Posts: 18
Joined: 2010-07-16T15:54:28-07:00
Authentication code: 8675308

Re: Please use CIE LCH for transfer modes Colorize, Luminize

Post by KonfuseKitty »

Beautiful! Just the kind of automagic I like... thank you!

Hang on though, does that mean Colorize/Luminize now won't be improved? :shock:
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Please use CIE LCH for transfer modes Colorize, Luminize

Post by fmw42 »

Sorry, I cannot answer that. I don't make those kinds of decisions. I just try to help answer questions where I think I know the answer. (Not always right, though).

P.Sl I hope you noticed my reply to your post at viewtopic.php?f=2&t=16651
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Please use CIE LCH for transfer modes Colorize, Luminize

Post by anthony »

KonfuseKitty wrote:Beautiful! Just the kind of automagic I like... thank you!

Hang on though, does that mean Colorize/Luminize now won't be improved? :shock:
It will get improved if you can get someone to recode it, so as to improve it. Simple as that.
ImageMagick is open source.

These were about the only parts of Compose I have not worked on. The code for them is in "magick/compose.c". Go for it.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
KonfuseKitty
Posts: 18
Joined: 2010-07-16T15:54:28-07:00
Authentication code: 8675308

Re: Please use CIE LCH for transfer modes Colorize, Luminize

Post by KonfuseKitty »

I truly wish I could contribute code, alas, I'm not capable of learning a language such as C or C++. Every time I tried I fell into a coma!

I dream of an application, a high level language, that could be used to easily create code, and then the application would translate it into a lower level language such as C etc. Does such an application exist? If only!

Thanks for listening though, it's appreciated. I'll see if I can find a coder somewhere and interest them in working on a fix. You never know, stranger things have happened. 8)
Post Reply