• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 282
  • 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
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
GuruVB
Asked:
GuruVB
1 Solution
 
VKCommented:
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
 
rspahitzCommented:
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
 
mdouganCommented:
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
 
DanRollinsCommented:
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
 
SpideyModCommented:
per recommendation

SpideyMod
Community Support Moderator @Experts Exchange
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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