LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Auto Thresholding an image for text extraction

Solved!
Go to solution

Hello Community,

Greetings Smiley Happy

I'm working on a Text Extraction algorithm in which I need some assistance with thresholding an image. I'm using the "AutoBThreshold2.vi" from Vision Development Module 2015. I decided to go with Otsu's Algorithm for thresholding which is available as "Inter Class Variance" algorithm. Now, The problem is that I need to specify the "Look for" option to extract the text! Unfortunately, my input images will not be always be same.

Kindly refer the attached images. My question is that Is there any way to find whether the image has Dark objects/Bright Objects on Dark Background/Bright Background? Meanwhile I'm also playing with Histogram to find out the BG & FG type!

I'd really appreciate your help... 

0 Kudos
Message 1 of 5
(2,881 Views)

Found a short post over on Lava: https://lavag.org/topic/3305-dark-characters-on-a-light-background-or-light-characters-on-a-dark-bac...

 

A histogram should help determine the background.  In combination with a Color Threshold operation, you may be able to extract what you need. 

---------------------
Patrick Allen: FunctionalityUnlimited.ca
Message 2 of 5
(2,866 Views)

Hello Mr. Allen,

Thank you so much for the quick reply! The link saved me a ton of time and good to know I was on right track!  Smiley Happy

 

I went through the link, and I'm quoting his reply below,

"You could try a histogram across the whole ROI which should give you two distinct peaks (one for the background colour and one for the text colour), and then look at the intensity just inside the border of the ROI - if it's the same as the darker peak then you've got light text on a dark background, and if it's the same as the lighter peak then you've got dark text on a light background (this assumes that the area just inside the border is the background - depending on your image, that's a fairly safe assumption). Do you have any example images that you can post for us to look at?"

I have one doubt on the above method!

* By border of the ROI [Highlighted], he means the first row & column in the ROI?

 

Can you also comment on the below questions?

1. What if my background is of gradient image?

2. What if my ROI has border sometimes?[Actually it has Smiley Sad Refer the attached Image]

 

Since I forgot to attach my code, I'm attaching here with this reply!

Thanks again Mr. Allen, I really appreciate your help 🙂

Download All
0 Kudos
Message 3 of 5
(2,848 Views)
Solution
Accepted by topic author Achuthaperumal

Can't clustering threshold solve your problem ?

Message 4 of 5
(2,826 Views)
Solution
Accepted by topic author Achuthaperumal

Hello @zxcpavel,

Thanks for the reply! Your VI gave me a great insight! Smiley Happy

Actually, Regardless of the "Method", AutoBThreshold2.vi thresholds most of my images perfectly! The problem is that I was using IMAQ RejectBorder.vi which rejected the background if its white! So before rejecting the borders, I used the method in your Clusterng.vi which is checking the maximum pixel value after threshold from histogram and inverse the image based on the need. Now I'm able to proceed to the next level which is character segmentation.

once again thanks for your help!

 

P.S:  You don't need to wire "Look for" terminal if your input image going to have both dark objects and bright objects. The AutoBthreshold2.vi will threshold your Image and may give 2 types of output:

    1. White Background and Black Foreground

    2. Black Background and White Foreground

I'd suggest you to make all your output to option (2). To do that you can refer the Highlighted Text above or you can refer Clustering.vi from the previous reply!

0 Kudos
Message 5 of 5
(2,802 Views)