Page 1 of 1

How does one batch substitute colors based on criteria?

Posted: 2015-05-08T15:19:33-07:00
by PandoraBox
I'm stumped on this one as I really hate doing a for loop in dos to check all 16 million colors on a image.

What I am trying to do is for example if I have the color 237,23,23 I want to have 255,0,0.

The common rule is that if the color is 127 or more set to 255 if not set to 0.

To end up with only the possible colors 0,0,0 0,0,255 0,255,0 0,255,255 255,0,0 255,0,255 255,255,0 255,255,255.

currently I could split the channels and re-merge them once I've done my color loop which would reduce this to 768 steps however as far as I know or I just missed the information in regarding saving under the same file name.

Any help would be greatly appreciated.

This is what I'm currently using but it's a pain

convert image.png -fill Rgb(0,0,0) -opaque rgb(15,16,12) imageout.png

Re: How does one batch substitute colors based on criteria?

Posted: 2015-05-08T16:02:06-07:00
by snibgo
"-posterize 2", although I think the cut-off will be that more than 50% (128 or greater) will become maximim (eg 255).

Re: How does one batch substitute colors based on criteria?

Posted: 2015-05-08T16:49:13-07:00
by fmw42
"-separate -threshold 49.803% -combine" should work to get you your threshold at 127, but it still needs to be done in a loop. mogrify does not work by my testing.

Code: Select all

convert xc:"rgb(127,23,23)" -separate -threshold 49.803% -combine txt:
# ImageMagick pixel enumeration: 1,1,65535,srgb
0,0: (100%,0%,0%)  #FFFF00000000  red

Code: Select all

convert xc:"rgb(126,23,23)" -separate -threshold 49.803% -combine txt:
# ImageMagick pixel enumeration: 1,1,65535,srgb
0,0: (0%,0%,0%)  #000000000000  black

Re: How does one batch substitute colors based on criteria?

Posted: 2015-05-08T16:51:36-07:00
by fmw42
This also work with convert but not mogrify.

Code: Select all

convert xc:"rgb(127,23,23)" -channel rgb -threshold 49.803% +channel txt:
# ImageMagick pixel enumeration: 1,1,65535,srgb
0,0: (100%,0%,0%)  #FFFF00000000  red

Code: Select all

convert xc:"rgb(126,23,23)" -channel rgb -threshold 49.803% +channel txt:
# ImageMagick pixel enumeration: 1,1,65535,srgb
0,0: (0%,0%,0%)  #000000000000  black

Re: How does one batch substitute colors based on criteria?

Posted: 2015-05-08T17:18:19-07:00
by PandoraBox
The posterize command worked great that was exactly what I was looking for.

The reason why I needed those primary colors is that I am using a tool called PaperBa(c)k http://www.ollydbg.de/Paperbak/index.html and I was wishing to modify this code to work with colored bar codes the issue was no scanner is perfect in giving accurate colors to be able to re-split the channels to process the data.

And you both we're right it was 128 the cutting point I needed.

Well thanks you both for the quick reply once I get this source code to work with the colors properly I'll gladly donate it to who ever wants it.