Click here to Skip to main content
15,860,844 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have this code, but while using small bitmaps always return 50% ( error)
VB
Public Function Equality(ByVal I1 As Image, ByVal I2 As Image, ByVal Resize As Boolean, ByVal colorsenser As Boolean) As String
       Dim BM1 As Bitmap
       Dim BM2 As Bitmap

       Dim different_pixel As Integer = 0
       Dim BM1Area As Integer = (I1.Width * I1.Height)
       Dim BM2Area As Integer = (I2.Width * I2.Height)
       Dim total As Integer = BM1Area + BM2Area
       
       Dim remove_pixel_Width As Integer = 1
       Dim remove_pixel_height As Integer = 1
       If Resize = True Then
           BM1 = ResizeBitmap(I1, 200, 300)
           BM2 = ResizeBitmap(I2, 200, 300)
       Else
           BM1 = I1
           BM2 = I2
       End If
       If BM1.Width <> BM2.Width Then
           If BM1.Width > BM2.Width Then
               remove_pixel_Width = BM1.Width - BM2.Width
           Else
               remove_pixel_Width = BM2.Width - BM2.Width

           End If

       End If
       If BM1.Height <> BM2.Height Then
           If BM1.Height > BM2.Height Then
               remove_pixel_Width = BM1.Height - BM2.Height
           Else
               remove_pixel_Width = BM2.Height - BM2.Height

           End If

       End If
       If BM1Area <> BM2Area Then
           If BM1Area < BM2Area Then
               different_pixel += BM2Area - BM1Area


           Else
               different_pixel += BM1Area - BM2Area
           End If
       End If


       For X = 0 To BM1.Width - remove_pixel_Width
           For y = 0 To BM2.Height - remove_pixel_height

               If BM1.GetPixel(X, y) <> (BM2.GetPixel(X, y)) Then
                   If colorsenser = True Then
                       Dim redr As Integer = 0

                       Dim greenr As Integer = 0
                       Dim bluer As Integer = 0
                       Dim somer As Integer = 0

                       Dim geto1 As Color = BM1.GetPixel(X, y)
                       Dim geto2 As Color = BM2.GetPixel(X, y)

                       somer = 0


                       If geto1.R - 2 < geto2.R < geto1.R + 2 Then
                       Else : somer += 1
                       End If
                       If geto1.B - 2 < geto2.B < geto1.B + 2 Then
                       Else : somer += 1
                       End If
                       If geto1.G - 2 < geto2.G < geto1.G + 2 Then
                       Else : somer += 1
                       End If

                       If somer <> 0 Then
                           different_pixel += 1
                       End If


                   Else
                       different_pixel += 1
                   End If


               End If

           Next
       Next
       Return 100 - ((different_pixel * 100) / total)

   End Function
Posted
Updated 22-Dec-13 12:51pm
v5
Comments
Sergey Alexandrovich Kryukov 22-Dec-13 20:04pm    
First of all, you should describe the definition of similarity measure, what you wanted to expect. Most simple criteria a very useless, by the way.
—SA

Coding is secondary here, you need an algorithm first. There is a good advice here.

For calculation of similarity measure, there is the simpler Euclidean distance based, and the more complicated Gaussian function based depending on the problem and the nature of the data set, just to mention 2 of them. You should try them out to compare their accuraries using the same data set. Ask google for more information on this area.
 
Share this answer
 
Have a look at past answers[^].
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900