Results 1 to 9 of 9

Thread: Image comparison

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2002
    Location
    india
    Posts
    1

    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

  2. #2
    Fanatic Member vbPoet's Avatar
    Join Date
    Feb 2005
    Location
    Searching ..
    Posts
    669

    Re: Image comparison

    I have posted the same thread today

  3. #3
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    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.

  4. #4
    Elite Hacker Jacob Roman's Avatar
    Join Date
    Aug 2004
    Location
    Miami Beach, FL
    Posts
    5,349

    Re: Image comparison

    If you were to compare images of the same size, you would do something like this:

    VB Code:
    1. Option Explicit
    2.  
    3. Private Type Picture_Type
    4.  
    5.     Size As Long
    6.     Width As Long
    7.     Height As Long
    8.  
    9. End Type
    10.  
    11. Private Sub Command1_Click()
    12.    
    13.     Dim Pic(1) As Picture_Type
    14.    
    15.     Dim X As Long, Y As Long
    16.    
    17.     Dim Is_The_Same As Long
    18.    
    19.     Dim Comparison As Single
    20.    
    21.     With Picture1
    22.        
    23.         .BorderStyle = False
    24.         .Picture = LoadPicture("C:\Jacob's Stuff\Pics\Alice.jpg")
    25.         .AutoSize = True
    26.         .AutoRedraw = True
    27.         .ScaleMode = 3
    28.            
    29.     End With
    30.    
    31.     With Picture2
    32.        
    33.         .BorderStyle = False
    34.         .Picture = LoadPicture("C:\Jacob's Stuff\Pics\whiterabbit.jpg")
    35.         .AutoSize = True
    36.         .AutoRedraw = True
    37.         .ScaleMode = 3
    38.        
    39.     End With
    40.    
    41.     With Pic(0)
    42.    
    43.         .Size = Picture1.ScaleWidth * Picture1.ScaleHeight
    44.         .Width = Picture1.ScaleWidth
    45.         .Height = Picture1.ScaleHeight
    46.            
    47.     End With
    48.    
    49.     With Pic(1)
    50.    
    51.         .Size = Picture2.ScaleWidth * Picture1.ScaleHeight
    52.         .Width = Picture2.ScaleWidth
    53.         .Height = Picture2.ScaleHeight
    54.            
    55.     End With
    56.    
    57.     If Pic(0).Size = Pic(1).Size Then
    58.    
    59.         For Y = 0 To Pic(0).Height - 1
    60.        
    61.             For X = 0 To Pic(0).Width - 1
    62.            
    63.                 If Picture1.Point(X, Y) = Picture2.Point(X, Y) Then
    64.                
    65.                     Is_The_Same = Is_The_Same + 1
    66.                
    67.                 End If
    68.            
    69.             Next X
    70.            
    71.         Next Y
    72.        
    73.         Comparison = (Is_The_Same / Pic(0).Size) * 100
    74.        
    75.         MsgBox "Both images are " & Comparison & "% the same", vbInformation
    76.    
    77.     Else
    78.    
    79.         MsgBox "The pictures are not the same size, so no comparison will be made.", vbCritical
    80.    
    81.     End If

  5. #5
    Fanatic Member vbPoet's Avatar
    Join Date
    Feb 2005
    Location
    Searching ..
    Posts
    669

    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


  6. #6
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Image comparison

    that wouldn't work, either.

  7. #7
    Elite Hacker Jacob Roman's Avatar
    Join Date
    Aug 2004
    Location
    Miami Beach, FL
    Posts
    5,349

    Re: Image comparison

    Quote 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.

  8. #8
    Fanatic Member vbPoet's Avatar
    Join Date
    Feb 2005
    Location
    Searching ..
    Posts
    669

    Re: Image comparison


    Oh yeah
    But if you look right at the top of this thread
    it is nearly 3 years OLD thread.

    But today in my original thread i have also edited that i want to know
    how much % both are same.
    100 %
    50%
    1 % only ......

  9. #9
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    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
  •  



Click Here to Expand Forum to Full Width