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.
Identifying red-bordered numbers separately
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Identifying red-bordered numbers separately
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
see
http://www.imagemagick.org/Usage/files/#txt
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: Identifying red-bordered numbers separately
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.
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/
https://imagemagick.org/Usage/