Page 1 of 1

Get only red and black

PostPosted: Tue Apr 30, 2019 7:48 pm
by gustavooka
Hi all,

I am trying to improve my ocr algorithm and to do that I need to pre processing the image with AForge. I would like to know a sequence filters to "get only the red and black text". I tried a lot of filter but no success with any.

Re: Get only red and black

PostPosted: Tue Apr 30, 2019 11:28 pm
by bigbomber
easy to do
Absolute Black means the R & G & B value are 0.
but in a photo they never reach to 0, but have a very low value like 10 or 20.

I recommend you read the photo pixel by pixel and check if the pixels have low value for RGB or not. you can define a range like 0~50 to check too.

Also it is possible with Aforge.net libraries.

Re: Get only red and black

PostPosted: Wed May 01, 2019 2:03 am
by gustavooka
Thanks for the response. Which way do you think that I can get the best performance of ocr (I want to read only black/grey and red letters)?

Re: Get only red and black

PostPosted: Wed May 01, 2019 6:54 am
by bigbomber
gustavooka wrote:Thanks for the response. Which way do you think that I can get the best performance of ocr (I want to read only black/grey and red letters)?

i'm not a professional programmer.
but you can read letters with a special color by pixel to pixel reading method. it is easy to do.
but if your images have huge size, the code can get slow. you can try to check it.

Re: Get only red and black

PostPosted: Wed May 01, 2019 7:57 am
by andrew.kirillov
Hello,

Check pixel filtering by color. You can set a range for black-ish pixels and then fill everything out of that range with white color, for example.

Re: Get only red and black

PostPosted: Wed May 01, 2019 1:57 pm
by gustavooka
andrew.kirillov wrote:Hello,

Check pixel filtering by color. You can set a range for black-ish pixels and then fill everything out of that range with white color, for example.


Thanks Andrew, but I tried with all of the filters and the best result that I had is with Euclidean filter but I am having problem with the first line of the document "VALIDA EM TODO TERRITORIO NACIONAL" .

Re: Get only red and black

PostPosted: Wed May 01, 2019 2:36 pm
by andrew.kirillov
If you always have same type/structure of documents, then you know roughly position of the first line, which has slightly different color. In this case you may apply different filter (or same filter with different settings) to that rectangle. Later you can combine both results.

Re: Get only red and black

PostPosted: Wed May 01, 2019 2:41 pm
by gustavooka
andrew.kirillov wrote:If you always have same type/structure of documents, then you know roughly position of the first line, which has slightly different color. In this case you may apply different filter (or same filter with different settings) to that rectangle. Later you can combine both results.


Hi Andrew,

Thanks, but It's not the same image. The user capture those images (I attached two images to clarify).