如何获得两幅图像的相似度百分比 [英] How to get percentage of similarity of two images

查看:386
本文介绍了如何获得两幅图像的相似度百分比的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个代码,但是使用小位图时总是返回50%(错误)

I have this code, but while using small bitmaps always return 50% ( error)

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

推荐答案

编码是次要的,你需要先算法。有一个很好的建议这里



对于相似性度量的计算,有更简单的欧几里德距离,更复杂的高斯函数取决于问题和数据集的性质,提到其中2个。您应该尝试使用相同的数据集来比较它们的控制。询问谷歌有关该领域的更多信息。
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.


看看过去的答案 [ ^ ]。


这篇关于如何获得两幅图像的相似度百分比的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆