Please help! How replicate the function of GIMP's "colorize"
Re: Please help! How replicate the function of GIMP's "color
Wow, I read the info on hald images three times and still don't understand it. Can't believe how much that went over my head and I like to think of myself as a rather bright guy.
I follow that there is a grid of colors, but what I don't understand is how they are used to skew an image.
For my needs, what I need to do is simply colorize a bunch of images. I would need for pure white and black to remain untouched and I need to be able to generate images that are colorized for either red, green, blue, purple or orange since those are the color mods I offer my followers.
What you are suggesting sounds like it would really be a better solution, however I am afraid I don't understand how to apply it.
I follow that there is a grid of colors, but what I don't understand is how they are used to skew an image.
For my needs, what I need to do is simply colorize a bunch of images. I would need for pure white and black to remain untouched and I need to be able to generate images that are colorized for either red, green, blue, purple or orange since those are the color mods I offer my followers.
What you are suggesting sounds like it would really be a better solution, however I am afraid I don't understand how to apply it.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Please help! How replicate the function of GIMP's "color
Create a hald image in IM
convert hald:8 hald.png
Go to GIMP and apply the colorize process that you want for one color, say red. Note the values.
Now open the hald.png image in GIMP and open the colorize window and set the same value to the hald image. Now save that hald image in GIMP as hald_red.png. Do not write over the hald.png image as you will need that later for other colors.
Now bring that image back to IM.
Now apply the hald_red image to all the images you want colorized as red or whenever you want to apply that colorization to any image
convert image.png hald_red.png -hald-clut redimage.png
Create as set of hald result image for each color, hald_red.png, hald_green.png, etc.
Choose whichever hald_color.png image that you want whenever you want to colorize some image with that effect.
convert hald:8 hald.png
Go to GIMP and apply the colorize process that you want for one color, say red. Note the values.
Now open the hald.png image in GIMP and open the colorize window and set the same value to the hald image. Now save that hald image in GIMP as hald_red.png. Do not write over the hald.png image as you will need that later for other colors.
Now bring that image back to IM.
Now apply the hald_red image to all the images you want colorized as red or whenever you want to apply that colorization to any image
convert image.png hald_red.png -hald-clut redimage.png
Create as set of hald result image for each color, hald_red.png, hald_green.png, etc.
Choose whichever hald_color.png image that you want whenever you want to colorize some image with that effect.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Please help! How replicate the function of GIMP's "color
My earlier approach was flawed as -tint does not colorize the same for all colors. The following is an improved version that is more consistent across colors. Tested with hue=0 (red) and hue=180 (cyan)
hue=0
sat=50
light=0
hue=`convert xc: -format "%[fx:100*$hue/360]" info:`
test=`convert xc: -format "%[fx:$light<0?0:1]" info:`
light=`convert xc: -format "%[fx:abs($light)]" info:`
if [ $test -eq 0 ]; then
fillcolor="black"
else
fillcolor="white"
fi
convert zelda3.png -set colorspace RGB -colorspace gray \
\( -size 1x1 xc:black xc:"hsl($hue%,$sat%,50%)" xc:white +append -filter cubic -resize 256x1! \) \
-clut -fill $fillcolor -colorize $light% show:
I will make this into a script with a few more features as soon as I can.
hue=0
sat=50
light=0
hue=`convert xc: -format "%[fx:100*$hue/360]" info:`
test=`convert xc: -format "%[fx:$light<0?0:1]" info:`
light=`convert xc: -format "%[fx:abs($light)]" info:`
if [ $test -eq 0 ]; then
fillcolor="black"
else
fillcolor="white"
fi
convert zelda3.png -set colorspace RGB -colorspace gray \
\( -size 1x1 xc:black xc:"hsl($hue%,$sat%,50%)" xc:white +append -filter cubic -resize 256x1! \) \
-clut -fill $fillcolor -colorize $light% show:
I will make this into a script with a few more features as soon as I can.
Last edited by fmw42 on 2012-11-09T19:17:48-07:00, edited 3 times in total.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Please help! How replicate the function of GIMP's "color
I have modified the code above to make it better match GIMP and uploaded it as a new script, coloration, on my web site linked below.
Re: Please help! How replicate the function of GIMP's "color
Thank you Fred, your dedication to the pursuit of code perfection is most appreciated. I look forward to trying this out.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Please help! How replicate the function of GIMP's "color
Note that I edited my code sample in the previous post above after working it out better in the script.
Re: Please help! How replicate the function of GIMP's "color
Fred, what did you name the new script?
Any chance you can tell me how to use the CygWin to execute one of these scripts?
What I need to do is be able to point the script to a directory and have it colorize all the files in that folder, ignoring all black in any image.
Any chance you can tell me how to use the CygWin to execute one of these scripts?
What I need to do is be able to point the script to a directory and have it colorize all the files in that folder, ignoring all black in any image.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Please help! How replicate the function of GIMP's "color
markdmac wrote:Fred, what did you name the new script?
Any chance you can tell me how to use the CygWin to execute one of these scripts?
What I need to do is be able to point the script to a directory and have it colorize all the files in that folder, ignoring all black in any image.
As above it is named, coloration. The script process only one image at a time. So you would need to write a script to loop over all your images and feed them one at a time in the loop to the script.
Sorry I am not a Windows user. I can only point you to http://www.imagemagick.org/Usage/windows/ and http://www.imagemagick.org/Usage/windows/#cygwin.
However, the command line I wrote above can be run on windows. You can put them in Bat file and convert the needed syntax appropriately as described at http://www.imagemagick.org/Usage/windows/
If you have the same values for all your images, then the easiest thing is to process it in GIMP. Record the settings. Create a hald image in IM. Take it to GIMP. Process the hald image with the same values. Bring the modified hald image back to IM and apply it to your images using -hald-clut. See http://www.imagemagick.org/Usage/color_mods/#hald-clut. More details are listed in an earlier post on this topic. You will still have to write a script or bat file to loop over all your images. -mogrify will not allow a second image for the -hald-clut.
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Please help! How replicate the function of GIMP's "color
Regarding Gimp: note that many of the settings can be saved. This simplifies the process of applying the same settings to a hald image as was applied to the original image.
The settings are saved in files (in %USERPROFILE%\.gimp-2.8\tool-options\) with greater precision than the 8 bits it will use for a hald file. This avoids small differences being quantised out, but of course needs some software to parse the settings files. I have only done this for curves, but doubtless it could be used for other settings.
The settings are saved in files (in %USERPROFILE%\.gimp-2.8\tool-options\) with greater precision than the 8 bits it will use for a hald file. This avoids small differences being quantised out, but of course needs some software to parse the settings files. I have only done this for curves, but doubtless it could be used for other settings.
snibgo's IM pages: im.snibgo.com
Re: Please help! How replicate the function of GIMP's "color
Hi Fred, I am back at it again now that work has given me a slight break for the Thanksgiving holiday. I am still trying to convert your script over for use in a Windows system. I am regrettably non-versed in the Linux batch syntax and having a problem. From your earlier example:
convert zelda3.png -set colorspace RGB -colorspace gray ( -size 1x1 xc:black xc:"hsl($hue%,$sat%,50%)" xc:white +append -filter cubic -resize 256x1! ) -clut -fill $fillcolor -colorize $light% show:
I am trying to get rid of all the variables and error checking from above as I will need to redo those in VBscript. Is the following a valid interpretation of the command assuming Hue is 270, Sat is 74 and light is 0?
convert zelda3.png -set colorspace RGB -colorspace gray ( -size 1x1 xc:black xc:"hsl(270,74,0)" xc:white +append -filter cubic -resize 256x1! ) -clut -fill black -colorize 0% show:
This example does show me a grayscale copy of my image, however it does not appear to colorize it nor save the results back to the original image.
I also tried the following (same command using percentages per the formula in your earlier example to convert hue to a percentage)
convert zelda3.png -set colorspace RGB -colorspace gray ( -size 1x1 xc:black xc:"hsl(7.5%,74%,0%)" xc:white +append -filter cubic -resize 256x1! ) -clut -fill black -colorize 0% show:
Wish I understood the linux scripting better so I could convert this easier to Windows. Once I have this working I will be happy to share my VBScript code which does successfully loop through each file in a folder and check for PNG files and then runs a convert command against that file. I just have to get the command to work for a single file and then the automation part is a breeze.
convert zelda3.png -set colorspace RGB -colorspace gray ( -size 1x1 xc:black xc:"hsl($hue%,$sat%,50%)" xc:white +append -filter cubic -resize 256x1! ) -clut -fill $fillcolor -colorize $light% show:
I am trying to get rid of all the variables and error checking from above as I will need to redo those in VBscript. Is the following a valid interpretation of the command assuming Hue is 270, Sat is 74 and light is 0?
convert zelda3.png -set colorspace RGB -colorspace gray ( -size 1x1 xc:black xc:"hsl(270,74,0)" xc:white +append -filter cubic -resize 256x1! ) -clut -fill black -colorize 0% show:
This example does show me a grayscale copy of my image, however it does not appear to colorize it nor save the results back to the original image.
I also tried the following (same command using percentages per the formula in your earlier example to convert hue to a percentage)
convert zelda3.png -set colorspace RGB -colorspace gray ( -size 1x1 xc:black xc:"hsl(7.5%,74%,0%)" xc:white +append -filter cubic -resize 256x1! ) -clut -fill black -colorize 0% show:
Wish I understood the linux scripting better so I could convert this easier to Windows. Once I have this working I will be happy to share my VBScript code which does successfully loop through each file in a folder and check for PNG files and then runs a convert command against that file. I just have to get the command to work for a single file and then the automation part is a breeze.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Please help! How replicate the function of GIMP's "color
show: is a unix display command. so you need to save the image and display it with some windows IM_display or viewer.convert zelda3.png -set colorspace RGB -colorspace gray ( -size 1x1 xc:black xc:"hsl(270,74,0)" xc:white +append -filter cubic -resize 256x1! ) -clut -fill black -colorize 0% show:
You need to escape the % with %%, and I believe you can leave the percent off with -colorize
so try this
convert zelda3.png -set colorspace RGB -colorspace gray ( -size 1x1 xc:black xc:"hsl(270,50%%,50%%)" xc:white +append -filter cubic -resize "256x1!" ) -clut -fill black -colorize 0 tmp.png
Note that the coloration script that I posted on my web site is a bit more complicated than this. But see if you can get this working.
Note that variable can be created and used in a BAT file using SET, I think. See
http://www.imagemagick.org/Usage/windows/#convert_issue
http://www.imagemagick.org/Usage/windows/#dos
http://www.imagemagick.org/Usage/windows/#calc_fx
Re: Please help! How replicate the function of GIMP's "color
Brilliant! It works perfectly. Now I just have to play around with the values to match up with the colors I am making in my Android themes.
Fred, thank you so much for all of your patience and perseverance.
I am going to create a bunch of images with different hue values so I can see how they translate to the Gimp values and when done will share my code for any other Windows users looking to accomplish the same goal.
Fred, thank you so much for all of your patience and perseverance.
I am going to create a bunch of images with different hue values so I can see how they translate to the Gimp values and when done will share my code for any other Windows users looking to accomplish the same goal.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Please help! How replicate the function of GIMP's "color
Note that the coloration script that I posted on my web site is a bit more complicated than this in order to match GIMP better.
I still feel that you would be better off just applying the colorizations you need to a Hald image in GIMP and save each one. Then you can just use the modified hald image with -hald-clut in IM to colorize any image with the selection from your pre-prepared colorization hald images.
I still feel that you would be better off just applying the colorizations you need to a Hald image in GIMP and save each one. Then you can just use the modified hald image with -hald-clut in IM to colorize any image with the selection from your pre-prepared colorization hald images.
Re: Please help! How replicate the function of GIMP's "color
I am sure you are right Fred, you haven't steered me wrong yet. I will likely try to circle back to that, but for the moment it is a bit too complex for me to understand to implement.
Most of the images I am dealing with will have only a single color or black/white and a single color. Essentially I am just tweaking the color of a bunch of icons for an Android phone. So the images I am dealing with are small and simple in general.
Most of the images I am dealing with will have only a single color or black/white and a single color. Essentially I am just tweaking the color of a bunch of icons for an Android phone. So the images I am dealing with are small and simple in general.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Please help! How replicate the function of GIMP's "color
For such images, you may be better using other IM techniques that are simpler. Can you post a link to an example before and after image. We may be able to suggest simpler means, such a +level-colors, -tint, etcmarkdmac wrote:I am sure you are right Fred, you haven't steered me wrong yet. I will likely try to circle back to that, but for the moment it is a bit too complex for me to understand to implement.
Most of the images I am dealing with will have only a single color or black/white and a single color. Essentially I am just tweaking the color of a bunch of icons for an Android phone. So the images I am dealing with are small and simple in general.