|
-
Aug 12th, 2003, 03:56 AM
#1
Thread Starter
Member
Image Comparison
Image Comparison
Hello, I currently develop an OCR program.
I found that compare the image pixel by pixel is very slow. Is that any solution can solve this kind of problem.
Regards, James
-
Aug 12th, 2003, 05:05 AM
#2
Frenzied Member
What is your ultimate goal of comparing images?
'Heading for the automatic overload'
Marillion, Brave, The Great Escape, 1994
'How will WE stand the FIRE TOMORROW?'
Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979
-
Aug 12th, 2003, 08:45 AM
#3
Addicted Member
If the image size is not the same, don't do the pixel by pixel comparision. If they are the same size, then you could take a selected sample of pixels, at various places on your 2 images. Only if these match do you then do the full pixel by pixel comparision.
I too am just thinking about creating an OCR application. I need to be able to scan colums of data (from paper in various table formats) and put the data into a database. Do you have any advice? Are there any 3rd party tools you can recommend?
-
Aug 12th, 2003, 08:53 AM
#4
Hyperactive Member
Uhm... Could you try with jpeg compression? It works with colors... Just compress both images, and now can do a comparison like PeteD said. Doing the compression before, accentuate the difference between the two images, but I also know that compressing the images will also take a lot of time... It's a suggestion.
Xmas79.
Learn, this is the Keyword...
-
Aug 12th, 2003, 09:18 AM
#5
Frenzied Member
If you want to test if the two images are exactly the same first check for the file size, then compare the images MD5 digest. if they are the same then the images are the same. This is a generic method for comparing files. Read this thread .
'Heading for the automatic overload'
Marillion, Brave, The Great Escape, 1994
'How will WE stand the FIRE TOMORROW?'
Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979
-
Aug 12th, 2003, 01:28 PM
#6
-
Aug 12th, 2003, 03:48 PM
#7
Originally posted by Lunatic3
If you want to test if the two images are exactly the same first check for the file size, then compare the images MD5 digest. if they are the same then the images are the same. This is a generic method for comparing files. Read this thread .
I wouldn't compare file sizes because if the images are not the same, they could still be the same size.
I'd suggest selecting several sections of pixels like what was mentioned and testing them
-
Aug 12th, 2003, 03:55 PM
#8
Frenzied Member
Originally posted by kasracer
I wouldn't compare file sizes because if the images are not the same, they could still be the same size.
But i was talking about the other side: if they are not equal in size then they are not the same. If the same size then you should apply a method to compare them, and what i suggest doesnt check for pixels or that sort of thing. It checks if the whole content of image file (or memory stream) is the same, in a very simple way.
'Heading for the automatic overload'
Marillion, Brave, The Great Escape, 1994
'How will WE stand the FIRE TOMORROW?'
Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979
-
Aug 12th, 2003, 03:58 PM
#9
Originally posted by Lunatic3
But i was talking about the other side: if they are not equal in size then they are not the same. If the same size then you should apply a method to compare them, and what i suggest doesnt check for pixels or that sort of thing. It checks if the whole content of image file (or memory stream) is the same, in a very simple way.
If you check it to see if they are NOT the same size, then you have the same exact program, they can still be the same image.
Different compressions format different, programs can save differently making someone larger or smaller
-
Aug 12th, 2003, 04:07 PM
#10
Frenzied Member
Originally posted by kasracer
Different compressions format different, programs can save differently making someone larger or smaller
In my opinion if you change the compression of an image then that wont be the same as the original image, although changes may not be visible to us. So comparing two images of different compression even if they origin from one source is useless, they are not the same anyway.
'Heading for the automatic overload'
Marillion, Brave, The Great Escape, 1994
'How will WE stand the FIRE TOMORROW?'
Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979
-
Aug 12th, 2003, 04:37 PM
#11
Addicted Member
the answer is surely to check the things that are the fastest to check 1st. You could check not only the size of the image (width and height) but also the file size. If these don't match up then you don't have to do any further pixel checking. If file sizes and image sizes are the same, then take a sample of pixels (maybe just 1 pixel in each corner, and one in the middle). If these all match then you could then increase the number of samples if you wanted to before you go and check every pixel. It would take bit longer when you have identical images, but the time taken to check non-idental images would be much much faster.
-
Aug 12th, 2003, 09:23 PM
#12
Thread Starter
Member
Image Comparison
Thax for your reply. Attach herewith my sample application.
I understand the solution you give to me, but if I do in this method, I need to have a lot of prabability text pattern. Anyway, is that still got any solution?
For my case
First: Grap the text from image "ABC"
Second: After get A, i will change it to dimension 10*10 and compare with my knowledge base.
Function toArt(ByRef initialBitmap As Bitmap, ByRef art(,) As Char)
Dim x, y, r, g, b, col As Integer
Dim gray As Bitmap = initialBitmap
'values used for ascii art
Dim c0, c1, c2, c3, c4 As Char
c0 = "0"
c1 = "1"
c2 = "1"
c3 = "1"
c4 = "1"
Value2.totalPixel = 0
For y = 0 To 9 Step 1
For x = 0 To 9 Step 1
Dim c As Color = initialBitmap.GetPixel(x, y)
r = c.R
g = c.G
b = c.B
col = (r + g + b) / 3
gray.SetPixel(x, y, Color.FromArgb(col, col, col))
If col >= 0 And col <= 70 Then
art(x, y) = c4
Value2.totalPixel += 1
End If
If col > 70 And col <= 255 Then art(x, y) = c0
TextBox1.AppendText(art(x, y))
'Me.PictureBox1.Image = initialBitmap
strBinary = TextBox1.Text
Next
Next
Return art
End Function
Dim fs As FileStream = New FileStream("Data.bin", FileMode.OpenOrCreate, FileAccess.ReadWrite)
Dim sr As StreamReader = New StreamReader(fs)
Dim datacharTN As String
Dim dataBinary As String
Dim i As Integer
Dim j As Integer
Dim k As Integer
Dim arrayCharData(10, 10) As String
Dim arrayCharGrap(10, 10) As String
Dim countMax As Double = 0
Dim countBestPixel As Double = 0
Dim charDisplay As String
Dim tempData As String
Dim tempGrap As String
Dim countError As Double = 0
Dim countTotalPixel As Double = 0
Dim tmpString As String = ""
While (sr.Peek() > -1)
tmpString = sr.ReadLine
datacharTN = Mid(tmpString, 1, 1)
dataBinary = Mid(tmpString, 3, 100)
For i = 0 To Len(dataBinary) - 1 Step 10
tempData = Mid(dataBinary, i + 1, 10)
tempGrap = Mid(TextBox1.Text, i + 1, 10)
k = 0
For j = 0 To Len(tempData) - 1 Step 1
arrayCharData(k, j) = Mid(tempData, j + 1, 1)
arrayCharGrap(k, j) = Mid(tempGrap, j + 1, 1)
If arrayCharData(k, j) = CStr(1) Then
countTotalPixel += 1
If arrayCharData(k, j) = arrayCharGrap(k, j) Then
countMax += 1
If check_proper = True Then
If CDbl(countMax / ((Value2.totalPixel))) > 0.95 Then
charDisplay = datacharTN
GoTo Line3
End If
End If
ElseIf arrayCharData(k, j) <> arrayCharGrap(k, j) Then
countMax -= 1
countError += 1
If check_proper = True Then
If countError > 40 Then
GoTo Line2
End If
ElseIf check_proper = False Then
If countError > 80 Then
GoTo Line2
End If
End If
End If
'ElseIf arrayCharGrap(k, j) = CStr(1) Then
' countTotalPixel += 1
' If arrayCharData(k, j) = arrayCharGrap(k, j) Then
' countMax += 1
' ElseIf arrayCharData(k, j) <> arrayCharGrap(k, j) Then
' countMax -= 1
' End If
End If
Next
k += 1
Next
Line1:
If CDbl(countMax / countTotalPixel) > 9.5 Then
charDisplay = datacharTN
countBestPixel = countMax
GoTo Line3
ElseIf CDbl(countMax / countTotalPixel) > 0.7 Then
If countBestPixel < countMax Then
charDisplay = datacharTN
countBestPixel = countMax
End If
End If
Line2:
countMax = 0
countTotalPixel = 0
countError = 0
End While
-
Aug 13th, 2003, 02:58 AM
#13
Frenzied Member
Still i think you dont have to compare pixels.After initial checks, Just check if the content of image files (those binary craps) are the same, and this is extrelemy simple to do.
'Heading for the automatic overload'
Marillion, Brave, The Great Escape, 1994
'How will WE stand the FIRE TOMORROW?'
Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|