Results 1 to 9 of 9

Thread: Image comparison

Threaded View

  1. #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

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