|
-
Apr 2nd, 2002, 02:27 AM
#1
Thread Starter
New Member
Image comparison
I want to know how to compare the image through vb code.
My requirement is that When I scan a same page many times, the scanned image has different file size. So when i try to compare the scanned images of the same page , I get the result that the images are differrent. So by opening the image file and comparing bit by bit does not work.
I want to know how to compare the two images without depending upon the file size.
Thanks in advance.
Sriharsha
-
Apr 24th, 2005, 08:33 PM
#2
Fanatic Member
Re: Image comparison
I have posted the same thread today
-
Apr 24th, 2005, 08:39 PM
#3
Re: Image comparison
You cannot compare something with 2000 dots to something with 4000 dots. They will always be different. The images must be the same size to compare the bits.
-
Apr 24th, 2005, 09:03 PM
#4
Re: Image comparison
If you were to compare images of the same size, you would do something like this:
VB Code:
Option Explicit
Private Type Picture_Type
Size As Long
Width As Long
Height As Long
End Type
Private Sub Command1_Click()
Dim Pic(1) As Picture_Type
Dim X As Long, Y As Long
Dim Is_The_Same As Long
Dim Comparison As Single
With Picture1
.BorderStyle = False
.Picture = LoadPicture("C:\Jacob's Stuff\Pics\Alice.jpg")
.AutoSize = True
.AutoRedraw = True
.ScaleMode = 3
End With
With Picture2
.BorderStyle = False
.Picture = LoadPicture("C:\Jacob's Stuff\Pics\whiterabbit.jpg")
.AutoSize = True
.AutoRedraw = True
.ScaleMode = 3
End With
With Pic(0)
.Size = Picture1.ScaleWidth * Picture1.ScaleHeight
.Width = Picture1.ScaleWidth
.Height = Picture1.ScaleHeight
End With
With Pic(1)
.Size = Picture2.ScaleWidth * Picture1.ScaleHeight
.Width = Picture2.ScaleWidth
.Height = Picture2.ScaleHeight
End With
If Pic(0).Size = Pic(1).Size Then
For Y = 0 To Pic(0).Height - 1
For X = 0 To Pic(0).Width - 1
If Picture1.Point(X, Y) = Picture2.Point(X, Y) Then
Is_The_Same = Is_The_Same + 1
End If
Next X
Next Y
Comparison = (Is_The_Same / Pic(0).Size) * 100
MsgBox "Both images are " & Comparison & "% the same", vbInformation
Else
MsgBox "The pictures are not the same size, so no comparison will be made.", vbCritical
End If
Last edited by Jacob Roman; Apr 24th, 2005 at 09:17 PM.
-
Apr 24th, 2005, 09:16 PM
#5
Fanatic Member
Re: Image comparison
hmm Jacob
thx 4 code Smart Code.
thx David as well.
I think if both images are not of same size.
then we can restrict our
2 for statements to the smaller value of both images.
like
1st image 100 X 100
2nd image 200 X 50
then we can restrict our For statements as
for X 100
for Y 50

-
Apr 24th, 2005, 09:22 PM
#6
Re: Image comparison
that wouldn't work, either.
-
Apr 24th, 2005, 09:30 PM
#7
Re: Image comparison
 Originally Posted by vbPoet
hmm Jacob
thx 4 code Smart Code.
thx David as well.
I think if both images are not of same size.
then we can restrict our
2 for statements to the smaller value of both images.
like
1st image 100 X 100
2nd image 200 X 50
then we can restrict our For statements as
for X 100
for Y 50

It obviously wouldn't be the same image if the images were a different size, so there would be no point in comparing them. Think what would happen if you were to compare a horizontal rectangle with a vertical one. It just can't happen.
-
Apr 24th, 2005, 09:53 PM
#8
-
Apr 24th, 2005, 10:38 PM
#9
Re: Image comparison
I think it would only be 100% match or not. If the color was different it would be different, the same picture would be different if the sun was shining at different times of the day, for instance.
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
|