Page 1 of 1

Setting pixels to a new colour, if a specific channel value is dominant

Posted: 2016-05-20T10:34:47-07:00
by Erik
Hello,

I process scanned pages of text. Some of these pages show blue pen notes, which I want to replace with another colour.

Every pixel within a blue pen note shows a higher value in the Blue channel, compared to Red and Green channels. I'd like to use this ratio as a pixel selector, as this is the common denominator with respect to the whole page.

I already tried alternatives like below, but at some point, parts of the black text become filled with red.

I figure I need to separate the channels and then compare the values via fx, but I am not sure how to do that.

Code: Select all

convert image.jpg -fuzz 45% -fill red -opaque 'srgb(0,0,255)' 0672.jpg
Test Image:

https://drive.google.com/file/d/0BxivpP ... sp=sharing

Re: Setting pixels to a new colour, if a specific channel value is dominant

Posted: 2016-05-20T10:55:41-07:00
by snibgo
You can do things like this:

Code: Select all

convert blue-pen-note.png -separate -delete 1 -compose MinusDst -composite -threshold 0% m.png
This creates a mask:
1. Separate input into R,G,B.
2. Delete image number 1, which leaves images just the R and B channels.
3. Subtract Dst from Src, ie find (B-R).
4. Where this is grater than 0%, make the result white. A different threshold may work better.

Use the mask to replace pixels with "red":

Code: Select all

convert blue-pen-note.png ( +clone -fill Red -colorize 100 ) m.png -compose Over -composite c.png