I am not sure I understand. Imagemagick can replace the input colors with the nearest colors from the palette image. I am not sure where the red comes in. In any event please always provide your IM version and platform, if you already use it and your images. You may post to some free image hosting service such as dropbox.com that won't change your image format and put the URLs here.
Correct me if I am wrong. If your image contains exactly the same colors as in the palette, you want to write red to the image, no matter what the palette color is. Is that correct?
You could do that as follows, but it needs a bit of scripting. Here is a unix script:
# create image of several colors
convert -size 100x100 xc:black xc:red xc:yellow xc:green1 xc:cyan xc:blue xc:magenta +append image.png
# create palette from only red, green1 and blue
convert -size 10x10 xc:red xc:green1 xc:blue +append palette_rgb.png
# just to show the results of -unique-colors txt:
Code: Select all
convert palette_rgb.png -unique-colors txt:
Code: Select all
# ImageMagick pixel enumeration: 3,1,65535,srgb
0,0: (65535,0,0) #FF0000 red
1,0: (0,65535,0) #00FF00 lime
2,0: (0,0,65535) #0000FF blue
#So the next line filters that output to just retain the hex values in the colorList
Code: Select all
colorList=$(convert palette_rgb.png -unique-colors txt: | tail -n +2 | sed 's/[ ][ ]*/ /g' | cut -d\ -f 3)
convert image.png new_image.png
for color in $colorList; do
convert new_image.png -fill red -opaque "$color" new_image.png
done
If you want nearby colors that are slightly different from your palette colors to be red, then add -fuzz XX% before the -fill red.