How to emulate Photoshop's "Color" blend mode?

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?".
Locked
User avatar
anthony
Posts: 8884
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Post by anthony »

Color blend is generally not overlay. The blend is implemented in IM as -blend. http://www.cit.gu.edu.au/~anthony/graph ... 6/compose/
This merges two images by picking a percentage of each image to
do a sort of 'weighted average'. This is probably what Photoshop is doing.

If this does not do what you want, by overlay is nearly right, my suggestion is to DIY it.

If you look at the SVG Composition Math manual pointer
http://www.w3.org/TR/2004/WD-SVG12-2004 ... mp-op-prop
I have in my Alpha Composition Example Page
http://www.cit.gu.edu.au/~anthony/graph ... 6/compose/
You can use those formulas to implement the overlay using -fx in a IM API.
(just ignore the transparent parts).

From there you can add a 'blend' percentage to adjust the results.

If this works well. perhaps you would like to look at the "compose.c" source in the IM core, and implement a 'overlay-blend' type of composition of others to use.

IM is really needing more programmers to add and improve features.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/

User avatar
anthony
Posts: 8884
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Post by anthony »

Don't dismiss the first suggestion -blend
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/

User avatar
anthony
Posts: 8884
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Post by anthony »

That is certainaly posible, (see -dissolve) though may not look as good.

Overlaying images with the addition of transparency is handled by the -dissolve composite operator.

Question did you try swapping the overlay images?

Overlay does NOT operlay images equally. One is used to modify the colors of the other. I find that sometimes swaping the source and destination images for -compose overlay produces much better effects than the normal method.

PS: do not use IM version5 with overlay, it is broken in that release.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/

User avatar
anthony
Posts: 8884
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Post by anthony »

Not in composite. and -dissolve is only in composite.

However their are other ways to make images semi-transparent.

convert image1 -matte -fill '#00000080' -draw 'matte 0,0 reset' \
image2 -compose overlay -composite result_image

The -fill sets a semi-transparent color and the "-draw color reset"
replaces the matte channel to the transparency of the fill color.
The -matte ensures a matte or alpha channel is present in the image.

To do two images with seperate transparency levels, use parenthesis. See the IM examples "basics" for 'Image Sequence handling' and parenthesis, and the "draw" area for the 'matte' draw primative, and "channel" for specificing semi-transparent colors.

Alturnativally use -fx (see "transforms") for a slower but simplier method of
setting an images transparency level.

Basically. I would suggest you go though the examples :-)
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/

User avatar
anthony
Posts: 8884
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: How to emulate Photoshop's "Color" blend mode?

Post by anthony »

If you just want to modify the luminosity of an image you can do this...

Code: Select all

convert image.png -colorspace HSL -separate \
At this point the channels are in separate greyscale images. the last 'L'
is the luminosity channel (also look at HSV colorspace). So clone it into a
separate image sequence (parenthesis) and work on it. I'll just normalize the
channel for this demo.

Code: Select all

         \( +clone  -normalize \) \
Now I have the original and the corrected versions, so swap the image and delete the original. Then re-combine the image. convert t

Code: Select all

         +swap +delete  ...combine somehow... \
         -colorspace RGB  image_Lnorm.png
Unfortnateally there is a BUG in combining non-RGB channel images. There is a workaround, but it is complex. See IM Examples channels
http://www.imagemagick.org/Usage/channels/#combine

Here is the full command with the 'combine' complexity I worked out.

Code: Select all

   convert image.png -colorspace HSL -separate \
         \( +clone  -normalize \) +swap +delete \
         \( +clone -colorspace HSL \
            -clone 0 -compose CopyRed    -composite \
            -clone 1 -compose CopyGreen -composite \
            -clone 2 -compose CopyBlue   -composite \
         \) -delete 0-2  -colorspace RGB   image_Lnorm.png
Remember red channel is the same data channel as the Hue channel in HSL color space.

However -normalize, and a lot of other IM commands (such as -fx, -levels, etc etc etc) can modify just one channel without needing to separate the channels.

Code: Select all

   convert image.png -colorspace HSL -channel B -normalize +channel \
               -colorspace RGB  image_Lnorm.png
And yes BOTH methods do work, and works VERY well.

You may however also be interested in the script work the Fred Weinhaus is doing with image hostogram correction. This includes auto-levels in 'lumunisity'.
http://www.fmwconcepts.com/imagemagick/
I am hoping to use his work to eventually incorporate and overhaul the histogram color handling core IM over then next year or so, once my work with distortions are finished.

If we had more people working on IM development, things would go faster!
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/

Locked