03-15-2019 08:49 AM
Hello Community,
Greetings
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...
Solved! Go to Solution.
03-15-2019 09:17 AM
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.
03-15-2019 10:01 AM
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!
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 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 🙂
03-16-2019 10:19 AM
Can't clustering threshold solve your problem ?
03-18-2019 03:50 AM - edited 03-18-2019 04:05 AM
Hello @zxcpavel,
Thanks for the reply! Your VI gave me a great insight!
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!