Hi all - sorry if this has been asked before, but I couldn't find an answer using search.
I'm using Imagemagick on Linux (Xubuntu). I have a folder of pngs (named with numbers, e.g., 3096.png) which are just colored blobs on a transparent background. The blobs are different colors, with several blobs of each color. Each image has anywhere from 1 to 10 colors.
I'm trying to do the following:
If the image has blobs of only 1 color, convert to red (#FF0000)
If the image has blobs of two colors, convert blobs of the first to red and blobs of the second to green (#00FF00)
If the image has blobs of three colors, convert blobs of the first to red, the second to green, and the third to blue (#0000FF)
... and so on. I don't care what the existing colors are - I just want them to be replaced with colors from my specified set of colors so that I can work on them for a project.
Is this possible? I'd really appreciate any help.
Thanks!
Replacing a set of colors with another set of colors
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Replacing a set of colors with another set of colors
do the blobs overlay with mixed colors?
see my bash unix script, mapcolors or separate, at the link below.
see my bash unix script, mapcolors or separate, at the link below.
Re: Replacing a set of colors with another set of colors
Thank you very much - I'm looking at your scripts now.fmw42 wrote:do the blobs overlay with mixed colors?
see my bash unix script, mapcolors or separate, at the link below.
To answer the question, each blob is a single color and none of the blobs touch. Is this what you meant?
Re: Replacing a set of colors with another set of colors
Your mapcolors looks perfect. Do you have any ideas on how I might list all the colors present in a set of images?fmw42 wrote:see my bash unix script, mapcolors or separate, at the link below.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Replacing a set of colors with another set of colors
You can get the histogram or the list of unique colors.
see
http://www.imagemagick.org/Usage/files/#histogram
http://www.imagemagick.org/Usage/quantize/#extract
The histogram should be in the verbose info as well
identify -verbose yourimage
see
http://www.imagemagick.org/Usage/files/#histogram
http://www.imagemagick.org/Usage/quantize/#extract
The histogram should be in the verbose info as well
identify -verbose yourimage
Re: Replacing a set of colors with another set of colors
Thank you once again. I really appreciate all the help - I'm a bit lost as I'm new to both IM and bash scripting, so just trying to wrap my head around all this.
Reading up on these commands, it seems these do exactly as I asked, but for a single image. Do I need to find a way to make a bash script to do it for all files, or is there an easier way to get an output listing the all colors present in a set (directory) of images?
Reading up on these commands, it seems these do exactly as I asked, but for a single image. Do I need to find a way to make a bash script to do it for all files, or is there an easier way to get an output listing the all colors present in a set (directory) of images?
Re: Replacing a set of colors with another set of colors
I got it now. Thanks for all your help and for pointing out your website and scripts. You are a genius!thekamz wrote:Thank you once again. I really appreciate all the help - I'm a bit lost as I'm new to both IM and bash scripting, so just trying to wrap my head around all this.
Reading up on these commands, it seems these do exactly as I asked, but for a single image. Do I need to find a way to make a bash script to do it for all files, or is there an easier way to get an output listing the all colors present in a set (directory) of images?
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Replacing a set of colors with another set of colors
This will make a .txt file for each gif image in the directory
cd yourdirectory
mogrify -format txt -unique-colors *.gif
change the suffix or leave it off for other formats
cd yourdirectory
mogrify -format txt -unique-colors *.gif
change the suffix or leave it off for other formats