返回首页

chieto

回答

评论会员:游客 时间:2012/02/07
阅读:imgsrc=]|SAKryukov
严格地说,制定的问题,因为它是没有意义的。一个比较是一类,这需要每类对象的定义。它被定义为数字,字符串,但没有图像。唯一明显的定义自然的一部分是等价的,但比较也意味着LT,GT = ......

在实践中,图像的像素到像素的等价是很少使用的应用程序。广泛讨论的想法是承认"类似"图像,这是非常困难的,甚至制订在几乎明智的方式。

mdash;水杨酸
评论会员:游客 时间:2012/02/07
试试这个:codeprelang="vb"spanclass="code-keyword"Private/spanspanclass="code-keyword"Sub/spanbtnCheck_Click(spanclass="code-keyword"ByVal/spansenderspanclass="code-keyword"As/spanSystem.spanclass="code-keyword"Object/span,_spanclass="code-keyword"ByVal/spanespanclass="code-keyword"As/spanSystem.EventArgs)spanclass="code-keyword"Handles/spanbtnGo.Clickspanclass="code-keyword"Me/span.Cursor=Cursors.WaitCursorApplication.DoEvents()spanclass="code-comment"'/spanspanclass="code-comment"Getthethreshold./spanspanclass="code-keyword"Dim/spanthresholdspanclass="code-keyword"As/spanspanclass="code-keyword"Integer/span=_spanclass="code-keyword"Integer/span.Parse(txtThreshold.Text)spanclass="code-comment"'/spanspanclass="code-comment"Loadtheimages./spanspanclass="code-keyword"Dim/spanbmp1spanclass="code-keyword"As/spanBitmap=Image.FromFile(txtFile1.Text)spanclass="code-keyword"Dim/spanbmp2spanclass="code-keyword"As/spanBitmap=Image.FromFile(txtFile2.Text)spanclass="code-comment"'/spanspanclass="code-comment"Makeadifferenceimage./spanspanclass="code-keyword"Dim/spanwidspanclass="code-keyword"As/spanspanclass="code-keyword"Integer/span=Math.Min(bmp1.Width,bmp2.Width)spanclass="code-keyword"Dim/spanhgtspanclass="code-keyword"As/spanspanclass="code-keyword"Integer/span=Math.Min(bmp1.Height,bmp2.Height)spanclass="code-keyword"Dim/spanbmp3spanclass="code-keyword"As/spanspanclass="code-keyword"New/spanBitmap(wid,hgt)spanclass="code-comment"'/spanspanclass="code-comment"Createthedifferenceimage./spanspanclass="code-keyword"Dim/spanare_identicalspanclass="code-keyword"As/spanspanclass="code-keyword"Boolean/span=spanclass="code-keyword"True/spanspanclass="code-keyword"Dim/spanr1,g1,b1,r2,g2,b2,r3,g3,b3spanclass="code-keyword"As/spanspanclass="code-keyword"Integer/spanspanclass="code-keyword"Dim/spancolor1,color2spanclass="code-keyword"As/spanColorspanclass="code-keyword"Dim/spaneq_colorspanclass="code-keyword"As/spanColor=Color.Whitespanclass="code-keyword"Dim/spanne_colorspanclass="code-keyword"As/spanColor=Color.Redspanclass="code-keyword"Dim/spandr,dg,db,diffspanclass="code-keyword"As/spanspanclass="code-keyword"Integer/spanspanclass="code-keyword"For/spanxspanclass="code-keyword"As/spanspanclass="code-keyword"Integer/span=spanclass="code-digit"0/spanspanclass="code-keyword"To/spanwid-spanclass="code-digit"1/spanspanclass="code-keyword"For/spanyspanclass="code-keyword"As/spanspanclass="code-keyword"Integer/span=spanclass="code-digit"0/spanspanclass="code-keyword"To/spanhgt-spanclass="code-digit"1/spancolor1=bmp1.GetPixel(x,y)color2=bmp2.GetPixel(x,y)dr=spanclass="code-keyword"CInt/span(color1.R)-color2.Rdg=spanclass="code-keyword"CInt/span(color1.G)-color2.Gdb=spanclass="code-keyword"CInt/span(color1.B)-color2.Bdiff=dr*dr+dg*dg+db*dbspanclass="code-keyword"If/spandiff<=thresholdspanclass="code-keyword"Then/spanbmp3.SetPixel(x,y,eq_color)spanclass="code-keyword"Else/spanbmp3.SetPixel(x,y,ne_color)are_identical=spanclass="code-keyword"False/spanspanclass="code-keyword"End/spanspanclass="code-keyword"If/spanspanclass="code-keyword"Next/spanyspanclass="code-keyword"Next/spanxspanclass="code-comment"'/spanspanclass="code-comment"Displaytheresult./spanpicResult.Image=bmp3spanclass="code-keyword"Me/span.Cursor=Cursors.spanclass="code-keyword"Default/spanspanclass="code-keyword"If/span(bmp1.Width<>bmp2.Width)spanclass="code-keyword"OrElse/span(bmp1.Height<>_bmp2.Height)spanclass="code-keyword"Then/spanare_identical=spanclass="code-keyword"False/spanspanclass="code-keyword"If/spanare_identicalspanclass="code-keyword"Then/spanMessageBox.Show(spanclass="code-string""/spanspanclass="code-string"Theimagesareidentical"/span)spanclass="code-keyword"Else/spanMessageBox.Show(spanclass="code-string""/spanspanclass="code-string"Theimagesaredifferent"/span)spanclass="code-keyword"End/spanspanclass="code-keyword"If/spanbmp1.Dispose()bmp2.Dispose()spanclass="code-keyword"End/spanspanclass="code-keyword"Sub/span/pre/code