Page 1 of 1

Colorize areas of image by hue

Posted: 2009-08-20T15:09:26-07:00
by TiZ
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?

Re: Colorize areas of image by hue

Posted: 2009-08-20T15:35:21-07:00
by fmw42
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!

Re: Colorize areas of image by hue

Posted: 2009-08-20T15:37:54-07:00
by TiZ
No, I'm on Linux. WE Ergo Blue is ported to GTK.

Re: Colorize areas of image by hue

Posted: 2009-08-20T15:40:12-07:00
by fmw42
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.

Re: Colorize areas of image by hue

Posted: 2009-08-20T16:09:27-07:00
by TiZ
Here is a before and after of what I'm trying to accomplish.

Image -> Image

Notice how the arrow in the center is unmodified. I want to do that kind of operation to many more images, in batch.

Re: Colorize areas of image by hue

Posted: 2009-08-20T16:17:02-07:00
by fmw42
are they all the same size and have the same center?

Re: Colorize areas of image by hue

Posted: 2009-08-20T16:20:01-07:00
by TiZ
No, they are not.

Re: Colorize areas of image by hue

Posted: 2009-08-20T17:20:24-07:00
by fmw42
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)

Image

convert stepper_blue.png -alpha off -colorspace HSB -channel red -separate stepper_blue_hue.png
Image

#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
Image

# 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
Image

set
new_color="pink"
repeat
Image