• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 283
  • Last Modified:

Image Processing/Filtering VB (Visual Basic)

Same question I had posted long time back, again with Increased points:

Please visit http://user.domaindlx.com/GuruVb/ for more information and for sample images.

I want to filter the above images  so that only number will appear on the image with black background.
i.e. numbers numbers in white having black background.
What I have tried up till now is Sobel operator and other edge detecting techniques but I am not satisfied
with the result. (coz that operator requires the tolerance or threshold and I want to automate it without
any user input. i.e. i am looking for something (algorithm) , which will calculate the tolerance/threshold
 depending upon image quality (eg. Image 4 having tolerance 157, but for image 3 it may be less.)
Please help me.
I need the algorithm or program in VB for the Image processing. If you have any questions please feel

Please visit http://user.domaindlx.com/GuruVb/ for more information and for sample images.

Thanks and kind regards.


I can convert it to B/W, that’s no problem. But while converting to B/W I loose image data. (As
I have image in Gray scale or color, I want the data from the white part, which are numbers, but not
always picture quality is good. So on the web page I have put some different images for that. [try converting
those images , you will loose the number (white) part L.].
Is there is any way we can find out programmatically the quality of the image?

If so please please please please let me know.

Thanks and kind regards,
--- (MCSD)
1 Solution
Hello GuruVB !

--> Is there is any way we can find out programmatically the quality of the image?

I think this is the crucial point. Making a B/W image from a color image when a threshold is given isn't difficult.

You want to get the best threshold value in dependency of the image quality.

If the below conditions are true i would have a possible solution:

1. What you have to filter out are character or digis
2. You can find free OCR-Software or Code or you can purchase it

Algorithm (only principle):

Private Function GetThreshold() As Byte
    Dim myOCR As New myOCRClass
    Dim LowVal As Byte
    Dim HighVal As Byte
    For LowVal = 0 To 255
        Set Picture1.Picture = LoadPicture("C:\TEMP\Test.BMP")
        Call SetPictureLuminosity(Picture1, LowVal)
        If myOCR.GetText(Picture1.Picture) <> "" Then Exit For

    For HighVal = 255 To 0 Step -1
        Set Picture1.Picture = LoadPicture("C:\TEMP\Test.BMP")
        Call SetPictureLuminosity(Picture1, HighVal)
        If myOCR.GetText(Picture1.Picture) <> "" Then Exit For

    GetThreshold = (HighVal + LowVal) / 2
    Set myOCR = Nothing
End Function

Although I have not explored this too deeply, what comes to mind is a two-part scan.  The first part builds an array or all color values, ranging from (0,0,0) to (255,255,255).  (Obviously this will take much less memory if dealing with a 256-color image since most of the combinations will not occur.)

Once you have the array, rank the high end such that you can determine what would be a good threshhold.  For example, take 10% of the high-end numbers (based on some criterion that you determine, like the sum of the RGB components > 255+127 or if any one component is above 240 then it's good) and use that as your threshhold.

In the second scan, anything in the 10% range gets turned white, and anything else gets turned black.

Try adjusting the 10% so it meets your expected level...maybe 25% or even 50%.

For very bright pictures, the 10% will be a lot of near-white combinations; for very dark pictures, the 10% will be a lot of low-valued combinations.

I think the hardest part is determining how to combine the R,G,B components to determine a ranking, but if you find a color-to-grayscale algorithm, it probably becomes easy.
I tried a few things on the samples from your website, and while most things worked pretty well on the big sample, non of the other samples worked well at all.  This is because there is so much glare or refracted light on the numbers that it's very difficult to distinguish between the number and the glare in the glass.

The technique that I tried was to go pixel by pixel to see if the long pixel color value was closer to vbWhite or vbBlack.  Depending on which it was, I'd set it to white or black. If you move the cuttoff point around then you can distinguish between different shades of white, turning one shade to black and others to white.  The problem in your images is that many of the pixels in the glare areas of your sample pictures are brighter than some of the pixels in the number area, so, it will be difficult to ever get a clean image from these samples.

As far as suggestions about picture quality, you could possilby save the darkest dark value, the lighest white value and the average color value of all pixels to get an overall idea of contrast.

The other thought that I had, but never got around to trying, would be to first put the image through some filters to rachet up the contrast, so that there would be a greater distinction for the light areas and dark areas, but you'll still have problems if your photos are going to include glare, I just don't see a way around it.
Hi GuruVB,
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will ask a Community Support Moderator to:

    Save as PAQ -- No Refund.

GuruVB, Please DO NOT accept this comment as an answer.
EXPERTS: Post a comment if you are certain that an expert deserves credit.  Explain why.
DanRollins -- EE database cleanup volunteer
per recommendation

Community Support Moderator @Experts Exchange
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

7 new features that'll make your work life better

It’s our mission to create a product that solves the huge challenges you face at work every day. In case you missed it, here are 7 delightful things we've added recently to monday to make it even more awesome.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now