how im do a color blending?

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
haibara
Posts: 10
Joined: 2008-05-06T02:30:15-07:00

how im do a color blending?

Post by haibara »

here i have a icon in a green background without alpha and another background

i want to do a color blending to produce the icon in the background

like this:
a icon in a green background(no alpha)
Image

another white background(in fact i want any background)
Image

the icon in the white background
Image

which command can i use?

regards
Last edited by haibara on 2008-12-20T05:41:35-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: how im do a color blending?

Post by fmw42 »

one way is to translate the green into white

convert green.jpg -fuzz XX -fill white -opaque green1 white.jpg

you need to know the exact or near green color components as rgb values or color name or hexcolor

see color definitions at http://imagemagick.org/script/color.php

the -fuzz XX where XX is some percent say 40% allows other colors near green to be converted to white.


You can also try floodfilling:

convert green.jpg -fill white -fuzz 40% -floodfill +0+0 "rgb(0,255,2)" green_white40.jpg

Alternately, you may need to use some masking technique to extract the face from the green background and then composite it back onto a white background.
haibara
Posts: 10
Joined: 2008-05-06T02:30:15-07:00

Re: how im do a color blending?

Post by haibara »

daer fmw42, thx for your reply

but point of my question is that i want any background

your method is suitable for background created by myself or manipulated by IM
in my requirement, background should be freewill, from real photo or computer graphics, not only described by IM

in fact, i try use ChangeMask mode in composite to get 32-bit image with alpha, then composite with any background
---i thinks it's alternate way mentioned by you

but i worried about this method whether is exact. i heard about color blending which is technically for my demand, but i don't know this operation whether has same effect as color blending
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: how im do a color blending?

Post by fmw42 »

I don't know what you mean by color blending. IM can blend two images, but that won't change one background to another. The only way I know to change the background to another picture is to make the green background transparent and compose that image over a new background image. Or make a binary mask image and use that to control the overlay of the one image with a new background.

You can try:

convert newbackgroundimage \( green.jpg -fuzz 40% -transparent green1 \) -compose over -composite image_on_newbackground

Otherwise you need to make a binary mask image (white for the face and black for the background), then

convert newbackgroundimage green.jpg maskimage -compose multiply -composite image_on_newbackground

But since your face has both black and white areas, it may not be easy to process the mask. I tried doing so from one of the red, or green or blue channels of the image, but with no good results. You may have to trace the outline manually in some other program to make the mask.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: how im do a color blending?

Post by anthony »

Instead of replacing the color with white replace it with transparency.

See IM exmaples, Color replacement
http://www.imagemagick.org/Usage/color/#replace

However if you want to try to present any anti-aliased or 'blended' pixels (is this what you mean by blending?) Then you may have to do some more advanced color replacements, involving splitting the image into 'definate foreground' 'definate background' and 'blended or anti-aliased pixels'.

With that tree image separation you can do any special handling needed for the blended pixels.

One such example of a VERY complex problem is given in IM examples,
Masking with Anti-Aliased Edges
http://www.imagemagick.org/Usage/channe ... antialised
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply