Identifying red-bordered numbers separately

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
Manish
Posts: 1
Joined: 2012-06-13T21:20:16-07:00
Authentication code: 13

Identifying red-bordered numbers separately

Post by Manish »

Hi,

I am using the image at http://test.mpustak.com/imagetest/red-box-numbers.jpg

I want to separate out this into two images - one with numbers surrounded by red, and the other with numbers on the left (and not surrounded by red).

Any hints on how to achieve this using IM?

Thanks.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Identifying red-bordered numbers separately

Post by fmw42 »

Separate out the red channel. Then use -scale to average the image to one row and output as txt: format. Then look for the largest transition between the dark and light. Get that coordinate, then crop your image into two parts at that X coordinate

see
http://www.imagemagick.org/Usage/files/#txt
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Identifying red-bordered numbers separately

Post by anthony »

Applying that test to just the red channel will not separate red colors from white colors.

I suggest you color replace red, and make everything else black, before doing that search.
http://www.imagemagick.org/Usage/color_basics/#replace

One you have the separation your can then mask for white rather than red, to find the digits, and more specifically the spacing between the digits. This can be difficult due to the amount of dirt and grim in the image.

As you would not have a location for the 'comma' that can also be masked out.

Fred scripts can probably help do that separation of digits.

Morphology can be used to determine what each digit is, but so can most OCR (optical character reconition) systems, once you remove as much of the grim as possible.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply