hi every one
my question is same as my topic I want to compare two images and deside which one are same .
I got no clue where to start
thx for future help
Printable View
hi every one
my question is same as my topic I want to compare two images and deside which one are same .
I got no clue where to start
thx for future help
http://www.vb-helper.com/howto_net_i...threshold.htmlCode:Private Sub btnGo_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles btnGo.Click
Me.Cursor = Cursors.WaitCursor
Application.DoEvents()
' Get the threshold.
Dim threshold As Integer = _
Integer.Parse(txtThreshold.Text)
' Load the images.
Dim bm1 As Bitmap = Image.FromFile(txtFile1.Text)
Dim bm2 As Bitmap = Image.FromFile(txtFile2.Text)
' Make a difference image.
Dim wid As Integer = Math.Min(bm1.Width, bm2.Width)
Dim hgt As Integer = Math.Min(bm1.Height, bm2.Height)
Dim bm3 As New Bitmap(wid, hgt)
' Create the difference image.
Dim are_identical As Boolean = True
Dim r1, g1, b1, r2, g2, b2, r3, g3, b3 As Integer
Dim color1, color2 As Color
Dim eq_color As Color = Color.White
Dim ne_color As Color = Color.Red
Dim dr, dg, db, diff As Integer
For x As Integer = 0 To wid - 1
For y As Integer = 0 To hgt - 1
color1 = bm1.GetPixel(x, y)
color2 = bm2.GetPixel(x, y)
dr = CInt(color1.R) - color2.R
dg = CInt(color1.G) - color2.G
db = CInt(color1.B) - color2.B
diff = dr * dr + dg * dg + db * db
If diff <= threshold Then
bm3.SetPixel(x, y, eq_color)
Else
bm3.SetPixel(x, y, ne_color)
are_identical = False
End If
Next y
Next x
' Display the result.
picResult.Image = bm3
Me.Cursor = Cursors.Default
If (bm1.Width <> bm2.Width) OrElse (bm1.Height <> _
bm2.Height) Then are_identical = False
If are_identical Then
MessageBox.Show("The images are identical")
Else
MessageBox.Show("The images are different")
End If
bm1.Dispose()
bm2.Dispose()
End Sub
I found this code and I need some explination
thx for the help
It compares the difference of the color of the pixels. If it falls under some threshold, the pixels are considered similar, if it doesn't the pixels are considered not similar. It also outputs an image of the same size that gives you a visual indicator of where the difference lies.
If you are trying to determine if they are identical, you don't need to do this much work. You could check the sizes of the files and also compute an MD5 hash of the file.
I got every thing u said execpt the this part
can u pls expalin this part again
thx for ut helpQuote:
also compute an MD5 hash of the file.
is this like this ??
source :Code:Imports System.Text
Imports System.Security.Cryptography
Private Function GenerateHash(ByVal SourceText As String) As String
'Create an encoding object to ensure the encoding standard for the source text
Dim Ue As New UnicodeEncoding()
'Retrieve a byte array based on the source text
Dim ByteSourceText() As Byte = Ue.GetBytes(SourceTStext)
'Instantiate an MD5 Provider object
Dim Md5 As New MD5CryptoServiceProvider()
'Compute the hash value from the source
Dim ByteHash() As Byte = Md5.ComputeHash(ByteSourceText)
'And convert it to String format for return
Return Convert.ToBase64String(ByteHash)
End Function
http://www.a1vbcode.com/vbtip-149.asp
how do i do that with image
You can get the bytes of the image and pass it to the MD5.ComputeHash function.
VB Code:
MessageBox.Show(Convert.ToBase64String(Md5.ComputeHash(New System.IO.StreamReader("C:\Temp\2006_01_07\IMG_2809.JPG").BaseStream)))
Now if the MD5 hashes are identical, it does not guarantee that the files are exactly the same, however, it is a pretty good indicator, especially if the files are the same size.
Is it posible for md5 hash to show same string even thow it not same
Technically, yes. However, very similar files (i.e. off by only a few bytes) will have drastically different MD5 hashes.
The only way to be 100% sure that it is the exact same file, would be comparing every single byte in the files.
Okay Thx I Will Try That Code And Ask If Any Help Is Needed