Page 1 of 1

how to convert gray color to a given color?

Posted: 2011-07-09T04:24:28-07:00
by linjuming
if the original color is not gray ,can use this method to do:
(modulate convert ,why the result is not the same color?)
viewtopic.php?f=1&t=19044

when the original color is gray ,the hsl (h=0,s=0,l=x) is not suitable for "hue/hue" compare ,then can not get the modulate hue or saturation.
Then how to do this covert?

Image

Re: how to convert gray color to a given color?

Posted: 2011-07-09T10:13:08-07:00
by fmw42
because gray has zero saturation, so -modulate cannot change 0 to something else by using a ratio

To recolor gray, either use -colorize (for solid gray) or +level-colors (for a gray gradient)

Re: how to convert gray color to a given color?

Posted: 2011-07-09T18:52:59-07:00
by linjuming
Image

Re: how to convert gray color to a given color?

Posted: 2011-07-09T20:25:00-07:00
by fmw42
you must first tell us how you created b_gd.png!

If I assume you have created them as:

gray gradient:
convert -size 100x100 gradient:"#b3b3b3-#4d4d4d" tmp1.png

blue gradient:
convert -size 100x100 gradient:"#0897ef-black" tmp2.png


gray to blue gradient:
convert tmp1.png -auto-level +level-colors "black,#0897ef" tmp1_2.png

tmp2.png and tmp1_2.png are the same

you have to stretch the gray gradient to full dynamic range before applying +level-colors with the proper color values.

note the order of the two colors in the gradient and in +level-colors are reversed.

to ensure the correct results you should specify both values. if you don't, then one will be assumed black and the other will be assumed white (at least in the gradient, if not both)

Re: how to convert gray color to a given color?

Posted: 2011-07-09T22:15:38-07:00
by linjuming
the b_gd.png is created approximately in photoshop.
the theory is similar with -modulate convert;
Image

and similar with Hue/Saturation in photoshop ,but select the colorize option.

Image

Re: how to convert gray color to a given color?

Posted: 2011-07-09T22:44:54-07:00
by fmw42
Sorry, you will have to show more steps and what functions in PS you are using. I only have an old PS CS and am not that familiar with it and perhaps it does not have the same functions you are using.

If I just do:

convert -size 100x100 gradient:"#0897ef-#b3b3b3" tmp3.png

I do not reproduce your image. I am not sure what you are doing exactly with hue and saturation. Are you using HSL or HSB? So I cannot even reproduce it in Photoshop. I don't see a colorize option in my old PS.

Does this reproduce your PS result?



h=$((100*243/360))
s=66
echo "h=$h; s=$s"
convert -size 100x100 gradient:"#b3b3b3-#0897ef" -colorspace hsl \
-channel r -evaluate set $h% +channel -channel g -evaluate set $s% \
+channel -colorspace rgb tmp6.png

Re: how to convert gray color to a given color?

Posted: 2011-07-09T23:15:35-07:00
by linjuming
1,i firstly ceate the #b3b3b3-#4d4d4d gradient in photoshop (ie:a.png)
2,then use Hue/Saturation tool to get some random color to get the colorize gradient (ie:b_gd.png)
3,the i pick the top color of the colorize gradient (ie:0897ef),and paste a square to get the pure color (ie:b.png)

my thinking is that if i had gray-scale img ,i want to colorize it base on a given color (ie :0897ef) ,the colored png is mainly close to my given color. no need very strick calculation,but seems trending to my given color.

it seems very hard to do this , sorry for my awkward request . if too wasting time ,pls ignore this topic.

Re: how to convert gray color to a given color?

Posted: 2011-07-09T23:19:40-07:00
by fmw42
Does this reproduce your PS result?

h=$((100*243/360))
s=66
echo "h=$h; s=$s"
convert -size 100x100 gradient:"#b3b3b3-#0897ef" -colorspace hsl \
-channel r -evaluate set $h% +channel -channel g -evaluate set $s% \
+channel -colorspace rgb tmp6.png

or perhaps this


h=$((100*243/360))
s=66
echo "h=$h; s=$s"
convert -size 100x100 gradient:"#0897ef-#b3b3b3" -colorspace hsb \
-channel r -evaluate set $h% +channel -channel g -evaluate set $s% \
+channel -colorspace rgb tmp6c.png

Re: how to convert gray color to a given color?

Posted: 2011-07-09T23:37:01-07:00
by linjuming
yes , great , that is what i want .
Thank you very much.

Re: how to convert gray color to a given color?

Posted: 2011-07-10T11:22:51-07:00
by fmw42
which example was it -- the first or the second?

Re: how to convert gray color to a given color?

Posted: 2011-07-10T19:07:42-07:00
by linjuming
h=$((100*243/360))
s=66
echo "h=$h; s=$s"
convert -size 100x100 gradient:"#b3b3b3-#0897ef" -colorspace hsl \
-channel r -evaluate set $h% +channel -channel g -evaluate set $s% \
+channel -colorspace rgb tmp6.png

this is good enough