Robert Westbury
Robert Westbury

Reputation: 64

ImageMagick Extract Two Colors of text frm image

I have this image here: enter image description here

And I want to remove everything but the blue and red text (so I can do effective OCR) on the top left. I have tried a couple things, but none of them have worked very effectively.

Preferably using the convert command.

Upvotes: 0

Views: 219

Answers (1)

fmw42
fmw42

Reputation: 53071

Here is one way to do that. Basically, we color threshold on the blue color. Then color threshold on the red color. Then add the two threshold results together and multiply that by the input image. You can try modifying the color values to improve the result. See -color-threshold (only available in ImageMagick 7) at https://imagemagick.org/script/command-line-options.php#color-threshold and https://imagemagick.org/discourse-server/viewtopic.php?f=4&t=37620

Input:

enter image description here

magick twotone.png +write mpr:img \
\( \( mpr:img -color-threshold "rgb(0,0,90)-rgb(90,130,170)" \) \
   \( mpr:img -color-threshold "rgb(95,0,0)-rgb(140,90,90)"  \) \
   -compose plus -composite \) \
-compose multiply -composite \
twotone_text.png

enter image description here

Upvotes: 3

Related Questions