how to change skin color to some hex or RGB color?

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
ravikum
Posts: 34
Joined: 2013-03-20T05:35:37-07:00
Authentication code: 6789

how to change skin color to some hex or RGB color?

Post by ravikum »

Hello,
I have a "face in hole" type of application.

I have cut hole in the place of monalisa's face and feathered it. (PNG)
Users upload their photos and adjust the faces in hole.
And, I send the monalisa's PNG and users photo to my script and using imagemagick, it composes them into a JPG.

I know the Hex and RGB color of monalisa's face.
So, whatever may be the color of the user's face, I want to replace that with the color of monalisa.

I have tried

Code: Select all

-fill tint -tint 100
and

Code: Select all

-fill tint -colorize 50%
and

Code: Select all

\( +clone +matte -fill monalisacolor -colorize 100% \) -compose overlay -composite
I tried to do this using -modulate hue. but hue is in %.
So, don't understand how to use this.

are there any other commands I can use to replace the skin color

Please suggest me various commands that I can use to do this effectively.

Thanks.
(using the latest IM version on linux centos 6)
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: how to change skin color to some hex or RGB color?

Post by snibgo »

ravikum wrote:I have cut hole in the place of monalisa's face and feathered it. (PNG)
I suppose you have made the monalisa's face transparent, so you can "-compose Over -composite" that PNG over the user's photo. But I don't understand what you are doing.

Can you upload a sample monolisa face and user photo to somewhere like dropbox.com and paste the URLs here?
snibgo's IM pages: im.snibgo.com
ravikum
Posts: 34
Joined: 2013-03-20T05:35:37-07:00
Authentication code: 6789

Re: how to change skin color to some hex or RGB color?

Post by ravikum »

Thanks for the reply here are the example images.
Image
and
Image

the girl face is kept behind monalisa face and
monalisa girl -geometry left top -compose DstOver -composite output.

Thanks
(using the latest IM version on linux centos 6)
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: how to change skin color to some hex or RGB color?

Post by fmw42 »

You could try -remap or if on Linux/MacOSX or Windows with Cygwin, you could try my script histmatch at the my signature link below this topic. You might need to crop the two photos to just around the faces to remove excess colors. For remap, use -unique-colors of the Mona Lisa face to create the colormap image.

What colors do you have for the monalisa image?

see
http://www.imagemagick.org/Usage/quantize/#remap

In the future, please provide your IM version and platform.

If you cannot figure this out, then please supply the original Mona Lisa image before the transparency.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: how to change skin color to some hex or RGB color?

Post by fmw42 »

Neither of the above seemed to work very well. But this seems to work. You can adjust the hex color and/or the saturation in -modulate. I have added some noise to emulate the mona lisa image, but you can remove that if you want.

try this

Code: Select all

convert face.jpg +sigmoidal-contrast 3,100 -seed 100 -attenuate 0.75 +noise gaussian \
\( -clone 0 -fill "#86491A" -colorize 100 \) -compose colorize -composite -modulate 100,110,100 face_result.jpg
I cannot say that the same arguments will work for every face image. Some tuning of the modulate and/or hex value may be needed depending upon skin tones in the face image.
Post Reply