Hi. I'm trying to batch modify a few images to change its blue-ish colors to cyan. Or maybe create a script that can re-color it freely. It's to modify a pixmap GTK theme.
To change one of the images the way I want it, I open it up in GIMP and do like so: I pick the wand tool, change its selection mode to hue, and click on a blue area on the image. Then I use the GIMP's colorize tool, and colorize it to hue 188, sat 50, lum -5. The result is that only the blue area is recolored.
It's simple enough to do, but there are LOTS of images to do it to. How would I do it with imagemagick so I can do it in batch?
Colorize areas of image by hue
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Colorize areas of image by hue
the fact that you use the GIMP wand to select means that you have to use masks and composite in IM, so more complicated. You have to process the whole image, then mask only the parts you want to change color. No way in IM to make a free-hand or magic wand mask, except possibly something like my script, magickwand, but it is Unix and I suspect you are on windows. The color changing processing is likely done in IM using -modulate.
see http://www.imagemagick.org/script/comma ... p#modulate and http://www.imagemagick.org/Usage/color/#modulate
As you have not provided any pictures as examples it is very hard to visualize what you really want to do!
see http://www.imagemagick.org/script/comma ... p#modulate and http://www.imagemagick.org/Usage/color/#modulate
As you have not provided any pictures as examples it is very hard to visualize what you really want to do!
Last edited by fmw42 on 2009-08-20T15:38:53-07:00, edited 1 time in total.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Colorize areas of image by hue
I have no idea what WE Ergo Blue is or what GTK is. I am on a Mac.
Best if you provide some links to examples of what you are trying to do.
Best if you provide some links to examples of what you are trying to do.
Re: Colorize areas of image by hue
Here is a before and after of what I'm trying to accomplish.
->
Notice how the arrow in the center is unmodified. I want to do that kind of operation to many more images, in batch.
->
Notice how the arrow in the center is unmodified. I want to do that kind of operation to many more images, in batch.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Colorize areas of image by hue
are they all the same size and have the same center?
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Colorize areas of image by hue
Here is one way to work with THIS image as I don't know how similar your other examples might be.
#convert the blue image to extract its hue (turn off your alpha channel to simulate your not having processed it in GIMP)
convert stepper_blue.png -alpha off -colorspace HSB -channel red -separate stepper_blue_hue.png
#look at the H channel histogram
identify -verbose stepper_blue_hue.png
Histogram:
1: ( 0, 0, 0) #000000 black
2: ( 25, 25, 25) #191919 rgb(25,25,25)
6: ( 26, 26, 26) #1A1A1A grey10
6: ( 29, 29, 29) #1D1D1D rgb(29,29,29)
1: ( 31, 31, 31) #1F1F1F grey12
240: (149,149,149) #959595 rgb(149,149,149)
Note that the center area that is yellow-gold is at graylevel 149 and the blue is at low values. This amounts to 149/255=58%
# threshold at this value to make a mask image
convert stepper_blue_hue.png -threshold 58% stepper_blue_hue_t58.png
# define new color
new_color="turquoise"
# convert blur image to grayscale, then recolor using -level-color to whatever new color you want.
# put the mask in that image as an alpha channel
# then composite that with the original to get the original yellow-gold back in the middle
convert \( stepper_blue.png -alpha off \) \
\( -clone 0 -colorspace gray +level-colors ${new_color},white \
stepper_blue_hue_t58.png -compose copy_opacity -composite \) \
-compose over -composite stepper_${new_color}.png
set
new_color="pink"
repeat
#convert the blue image to extract its hue (turn off your alpha channel to simulate your not having processed it in GIMP)
convert stepper_blue.png -alpha off -colorspace HSB -channel red -separate stepper_blue_hue.png
#look at the H channel histogram
identify -verbose stepper_blue_hue.png
Histogram:
1: ( 0, 0, 0) #000000 black
2: ( 25, 25, 25) #191919 rgb(25,25,25)
6: ( 26, 26, 26) #1A1A1A grey10
6: ( 29, 29, 29) #1D1D1D rgb(29,29,29)
1: ( 31, 31, 31) #1F1F1F grey12
240: (149,149,149) #959595 rgb(149,149,149)
Note that the center area that is yellow-gold is at graylevel 149 and the blue is at low values. This amounts to 149/255=58%
# threshold at this value to make a mask image
convert stepper_blue_hue.png -threshold 58% stepper_blue_hue_t58.png
# define new color
new_color="turquoise"
# convert blur image to grayscale, then recolor using -level-color to whatever new color you want.
# put the mask in that image as an alpha channel
# then composite that with the original to get the original yellow-gold back in the middle
convert \( stepper_blue.png -alpha off \) \
\( -clone 0 -colorspace gray +level-colors ${new_color},white \
stepper_blue_hue_t58.png -compose copy_opacity -composite \) \
-compose over -composite stepper_${new_color}.png
set
new_color="pink"
repeat