Why Colorize/Hue/Saturation/Luminize operators HSB-based?

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
ippei
Posts: 5
Joined: 2012-08-13T04:26:41-07:00
Authentication code: 67789
Location: Tokyo, JAPAN

Why Colorize/Hue/Saturation/Luminize operators HSB-based?

Post by ippei »

I want HueHSL/SaturationHSL/ColorizeHSL/LuminizeHSL composite operators. Are there any answers or suggestions?

I utilize ImageMagick to process a lot of PSD files created by various tools, mostly Adobe Photoshop series.
Adobe Photoshop has non-RGB-based (nor CMY-based) blending modes i.e. hue/saturation/color/luminosity,
and ImageMagick alike provides Hue/Saturation/Colorize/Luminize composite operators.

I believe most of the PSD managing tools including Adobe Photoshop work with HSL-like colorspace when blending layers with modes above,
in fact, a white pixel will never be color-ed with `color' blending mode.
(Strictly speaking, it's a variant of HSL. See http://en.wikipedia.org/wiki/HSL_and_HS ... r_software)

but I found that ones of ImageMagick are hard-coded to work with HSB colorspace in magick/composite.c,
for example, a white pixel may be color-ed by Colorize composition.

I think the development team has been conscious of Adobe Photoshop's blending modes, especially when designing its composite operators.
They are mostly work as other PSD managing tools do -- except these four operators...
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Why Colorize/Hue/Saturation/Luminize operators HSB-based

Post by magick »

We can get a patch into the next point release of ImageMagick to use the HSL colorspace.
ippei
Posts: 5
Joined: 2012-08-13T04:26:41-07:00
Authentication code: 67789
Location: Tokyo, JAPAN

Re: Why Colorize/Hue/Saturation/Luminize operators HSB-based

Post by ippei »

I got branches/ImageMagick-6 @ r8922-r8923, working well. Thank you, but...

It's hard for me to say,
now I know that it's better to use HCL from the point of view of Photoshop compatibility.
As of yesterday, I never believed ImageMagick supported HCL...

I sat down and explored the Subversion repository and finally I found HCL support was just added. (r8836 for trunk, r8838 for branches/ImageMagick-6)
The colorspace on which Photpshop's blending modes are based, I mentioned as a variant of HSL (Hue/Saturation/Lightness) yesterday, is luma/chroma/hue model. Yes it's called HCL in ImageMagick.

Thanks committers and contributors!
ippei
Posts: 5
Joined: 2012-08-13T04:26:41-07:00
Authentication code: 67789
Location: Tokyo, JAPAN

Re: Why Colorize/Hue/Saturation/Luminize operators HSB-based

Post by ippei »

ConvertRGBToHCL()/ConvertHCLToRGB() doesn't work correctly!

I myself tried to replace the composite code with HCL version, then referring gem.c to copy & paste, and found it.
Here is a patch for branches/ImageMagick-6. I've not checked trunk yet.

Code: Select all

--- a/magick/gem.c
+++ b/magick/gem.c
@@ -142,5 +142,5 @@
                 b=x;
               }
-  m=luma-0.298839*r+0.586811*g+0.114350*b;
+  m=luma-(0.298839*r+0.586811*g+0.114350*b);
   *red=ClampToQuantum(QuantumRange*(r+m));
   *green=ClampToQuantum(QuantumRange*(g+m));
@@ -476,5 +476,5 @@
   else
     if (red == (Quantum) max)
-      h=fmod((g-b)/c,6.0);
+      h=fmod(6.0+(g-b)/c,6.0);
     else
       if (green == (Quantum) max)
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Why Colorize/Hue/Saturation/Luminize operators HSB-based

Post by magick »

Can you revisit the HCL => RGB and RGB => HCL conversion? This command causes some white to improperly go to black:
  • convert rose: -define modulate:colorspace=HCL -modulate 150,100,100 show:
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Why Colorize/Hue/Saturation/Luminize operators HSB-based

Post by fmw42 »

With respect to this topic, has the -compose luminize/saturation/colorize methods been changed to use the new HCL colorspace?

It would seem so from some of my testing with -compose luminize that this is the case.

If so, can someone tell me in what release that change was made? I cannot see any comments in the changelog?

Also my results come closer to those of Photoshop using HCL than HSL or HSB, but they do not match perfectly. However, this is testing a script to emulate PS photofilters and not the conversion directly. If I can find a way to test that more directly, I will report back.



P.S. Is there a -define (similar to -define modulate:colorspace=HSL) to allow one to choose which colorspace to do the -compose luminize/saturation/colorize
michalfapso
Posts: 3
Joined: 2014-06-16T07:10:21-07:00
Authentication code: 6789

Re: Why Colorize/Hue/Saturation/Luminize operators HSB-based

Post by michalfapso »

Hi everyone, I just wanted to thank you all for contributing to ImageMagick. We needed to implement the color blending modes in our application, but ImageMagick produced different result than Gimp or Photoshop. I just had a quick look at the ImageMagick color blending (Hue, Saturate, Colorize, Luminize composite oprators), but it seems that alpha is not properly handled there. If you want to have a look at the Gimp-like color blending, I wrote the code here: http://stackoverflow.com/a/24207818/1341914.

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

Re: Why Colorize/Hue/Saturation/Luminize operators HSB-based

Post by fmw42 »

I believe that Photoshop uses something like IM HCLp. HCLp is as close as we have been able to reproduce the exact colorspace that PS uses. But they are not exactly the same. Until some one can tell us the exact colorspace that PS uses, an exact duplication is not possible.

see
viewtopic.php?f=1&t=23803&hilit=HCLp
viewtopic.php?f=2&t=21663

Does GIMP match Photoshop?
Post Reply