如何获得2个图像中过滤对象的百分比相似度 [英] How do I get the percentage similarity of filtered objects in 2 images

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

问题描述

我正在开发一个项目,使用AForge算法过滤图像中我需要的对象,并将它们与相同格式的另一个图像进行比较,以查看对象的百分比相似性。我有下面的代码,但它只给出了整个图像的百分比相似度或差异。我真的不关心整个图像,但我的兴趣只是我在图像中过滤的对象。请各位朋友,我如何在C#或VB.Net中进行此操作?下面的代码仅显示两个图像的相似性和差异,但不显示过滤的感兴趣对象。



I'm working on a project using AForge algorithm to filter objects i need in an image and use them in comparison to another image of the same format to see the percentage similarity of the objects. I have the code below but it only gives me the percentage similarity or difference of the whole image. I really don't care about the whole image but my interest is just the objects i filtered in the image. Please friends, how do i go about this in C# or VB.Net? Here is the code below that shows only similarity and difference of both images but not the filtered objects of interest.

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Dim bmp1 As Bitmap = Image.FromFile("C:\Temp\ImageCompare\chill.jpg")
    Dim bmp2 As Bitmap = Image.FromFile("C:\Temp\ImageCompare\chill1.jpg")

    Dim sameCount As Integer = 0
    Dim diffCount As Integer = 0

    For x As Integer = 0 To (bmp1.Width) - 1
        For y As Integer = 0 To (bmp1.Height) - 1
            If bmp1.GetPixel(x, y).Equals(bmp2.GetPixel(x, y)) Then
                sameCount += 1
            Else
                diffCount += 1
            End If
        Next
    Next

    Dim total As Integer = sameCount + diffCount

    MessageBox.Show(String.Format("Same Percentage: {0}{1}Difference Percentage: {2}", _
                                  (sameCount / total).ToString("p"), Environment.NewLine, (diffCount / total).ToString("p")))
End Sub

推荐答案

请参阅问题的评论。当然,这取决于目的,但对于大多数人来说,你的比较实际意义不大。我希望我解释了原因。


现在,我没告诉你 GetPixel 令人望而却步?你必须使用 System.Drawing.Image.LockBits

http://msdn.microsoft.com/en-us/library/system.drawing.bitmap.lockbits%28v=vs .110%29.aspx [ ^ ]。



这两种方法中的第一种方法的帮助页面显示了一些足够的代码示例了解操作。



-SA
Please see the comment to the question. It depends on the purpose, of course, but for most, your comparison have too little practical sense. I hope I explained why.

Now, didn't I tell you before that GetPixel is prohibitively slow? You have to use System.Drawing.Image.LockBits:
http://msdn.microsoft.com/en-us/library/system.drawing.bitmap.lockbits%28v=vs.110%29.aspx[^].

The help page on first of the two methods shows some code sample sufficient for understanding of the operation.

—SA


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

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