Solved

Image Processing/Filtering VB (Visual Basic)

Posted on 2002-03-27
5
258 Views
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
free

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

Thanks and kind regards.

PS:

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)
0
Comment
Question by:GuruVB
5 Comments
 
LVL 6

Expert Comment

by:VK
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
    Next

    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
    Next

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

V.K.
0
 
LVL 22

Expert Comment

by:rspahitz
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.
0
 
LVL 18

Expert Comment

by:mdougan
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.
0
 
LVL 49

Expert Comment

by:DanRollins
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
0
 

Accepted Solution

by:
SpideyMod earned 0 total points
ID: 7754798
per recommendation

SpideyMod
Community Support Moderator @Experts Exchange
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

705 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now