Change color of images without changing the texture

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.
Son13
Posts: 12
Joined: 2016-04-18T13:04:23-07:00
Authentication code: 1151

Re: Change color of images without changing the texture

Post by Son13 »

Hi Snibgo, fmw42:
Thanks for your inputs and overall patience. I should have done a better good job in detailing the problem.

The need is to change the two different images to RED - maintaining the same RED tone.

When command (convert SAMPLE#.png -colorspace gray -auto-level +level-colors red,white RESULT#.png) is used on two different images the resultant IMAGES (RESULT1 & RESULT2) have two different shades of RED. Can the color shade be same instead of golden/red?

SAMPLE1:
https://www.dropbox.com/s/0finrl3539i7zwd/2.png?dl=0
RESULT1:
https://www.dropbox.com/s/x1f1yg4b09flwsu/21.png?dl=0

in two different shades of red. I want to preserve the tone of RED.
SAMPLE2
https://www.dropbox.com/s/mzd66hscv4njg8d/3.png?dl=0
RESULT2
https://www.dropbox.com/s/s1coo9yzi86rb85/31.png?dl=0
Last edited by Son13 on 2016-04-19T08:07:46-07:00, edited 3 times in total.
Son13
Posts: 12
Joined: 2016-04-18T13:04:23-07:00
Authentication code: 1151

Re: Change color of images without changing the texture

Post by Son13 »

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

Re: Change color of images without changing the texture

Post by fmw42 »

Son13 wrote:11
What does this mean?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Change color of images without changing the texture

Post by fmw42 »

try -modulate and adjust the hue (and saturation and brightness) as desired

Code: Select all

convert 2.png -modulate 100,100,80 2_mod.png

NOTE: Proprietary mages have been deleted by request
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Change color of images without changing the texture

Post by snibgo »

Some red wigs:

[Moderator note: wig pictures removed at OP's request.]

wig2_red:
wig3_red:
wig3_red2:

wig3_shade, used to create shading in wig3_red2:

The Windows BAT script that made them:

Code: Select all

%IM%convert ^
  wig2.png ^
  -colorspace HSL ^
  -channel R -evaluate Set 0 ^
  -channel G -evaluate Multiply 3 ^
  +channel ^
  -colorspace sRGB ^
  wig2_red.png

%IM%convert ^
  wig3.png ^
  +level-colors red,white ^
  wig3_red.png

%IM%convert ^
  wig3.png ^
  -colorspace Gray ^
  -evaluate Pow 0.25 ^
  wig3_shade.png

%IM%convert ^
  wig3_red.png ^
  ( +clone -alpha extract +write mpr:ALPH +delete ) ^
  -colorspace HSL ^
  -separate ^
  wig3_shade.png ^
  -delete 2 ^
  -combine ^
  -set colorspace HSL -colorspace sRGB ^
  mpr:ALPH ^
  -alpha off ^
  -compose CopyOpacity -composite ^
  wig3_red2.png

%IM%convert wig2_red.png -background White -flatten -quality 40 wig2_red.jpg
%IM%convert wig3_red.png -background White -flatten -quality 40 wig3_red.jpg
%IM%convert wig3_shade.png -background White -flatten -quality 40 wig3_shade.jpg
%IM%convert wig3_red2.png -background White -flatten -quality 40 wig3_red2.jpg
I converted to low-quality JPEGs purely for web speed.
snibgo's IM pages: im.snibgo.com
Son13
Posts: 12
Joined: 2016-04-18T13:04:23-07:00
Authentication code: 1151

Re: Change color of images without changing the texture

Post by Son13 »

you guys are awesome.

Is there any way to automate this batch script.... based on the source image color? Since the source images can be a combination of any of these colors? http://beckerlelumber.com/zar.htm
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Change color of images without changing the texture

Post by snibgo »

What does the wood stain have to do with the wigs? Do you want the wigs to have the colour of the wood stain? If so, you can find the mean colour of the stain sample, and use that instead of "red".
snibgo's IM pages: im.snibgo.com
Son13
Posts: 12
Joined: 2016-04-18T13:04:23-07:00
Authentication code: 1151

Re: Change color of images without changing the texture

Post by Son13 »

[quote][/quote]
Last edited by Son13 on 2016-04-19T13:47:49-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: Change color of images without changing the texture

Post by fmw42 »

What platform and version of IM are you using? Please always provide that, since syntax may differ as well as scripting.

I do not script for Window, only Unix. So you may need help from one of the Windows users. But I would get the average hue of your original wig, then compute how much to shift the hue to get to red or whatever color you want from your color chart.
Son13
Posts: 12
Joined: 2016-04-18T13:04:23-07:00
Authentication code: 1151

Re: Change color of images without changing the texture

Post by Son13 »

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

Re: Change color of images without changing the texture

Post by fmw42 »

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

Re: Change color of images without changing the texture

Post by fmw42 »

fmw42 wrote:I would get the average hue of your original wig, then compute how much to shift the hue to get to red or whatever color you want from your color chart.
You will likely have to adjust the brightness and contrast and saturation as well, since you won't get a light colored wig from a dark one.
Post Reply