Page 1 of 1

Replacing a set of colors with another set of colors

Posted: 2013-05-29T14:53:58-07:00
by thekamz
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!

Re: Replacing a set of colors with another set of colors

Posted: 2013-05-29T15:03:41-07:00
by fmw42
do the blobs overlay with mixed colors?

see my bash unix script, mapcolors or separate, at the link below.

Re: Replacing a set of colors with another set of colors

Posted: 2013-05-29T15:10:44-07:00
by thekamz
fmw42 wrote:do the blobs overlay with mixed colors?

see my bash unix script, mapcolors or separate, at the link below.
Thank you very much - I'm looking at your scripts now.

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

Posted: 2013-05-29T15:22:37-07:00
by thekamz
fmw42 wrote:see my bash unix script, mapcolors or separate, at the link below.
Your mapcolors looks perfect. Do you have any ideas on how I might list all the colors present in a set of images?

Re: Replacing a set of colors with another set of colors

Posted: 2013-05-29T15:29:17-07:00
by fmw42
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

Re: Replacing a set of colors with another set of colors

Posted: 2013-05-29T16:26:37-07:00
by thekamz
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?

Re: Replacing a set of colors with another set of colors

Posted: 2013-05-29T16:58:49-07:00
by thekamz
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?
I got it now. Thanks for all your help and for pointing out your website and scripts. You are a genius!

Re: Replacing a set of colors with another set of colors

Posted: 2013-05-29T17:37:04-07:00
by fmw42
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