[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now


Image Processing/Filtering VB (Visual Basic)

Posted on 2002-03-27
Medium Priority
Last Modified: 2013-11-25
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)
Question by:GuruVB
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Expert Comment

ID: 6899670
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

LVL 22

Expert Comment

ID: 6899761
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.
LVL 18

Expert Comment

ID: 6899839
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.
LVL 49

Expert Comment

ID: 7637900
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

Accepted Solution

SpideyMod earned 0 total points
ID: 7754798
per recommendation

Community Support Moderator @Experts Exchange

Featured Post

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question