Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
Anyone here know how to compare 2 images. . and then show how many percent from before and after image captured. thanks in advance.
Posted 26-Nov-11 5:38am
chieto556
Edited 26-Nov-11 6:07am
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

This[^] might help you.
  Permalink  
Comments
chieto at 26-Nov-11 21:42pm
   
thanks abhinav,
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

Thanks for your reply. . but what algorithm im going to use?
 
Thanks
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

That's kind of vague, but in essence you need to instantiate two System.Drawing.Bitmap objects and compare them pixel by pixel.
You might find that something in the AForge.NET library could help your specific case.
 
_________________________________
Yvan Rodrigues
Red Cell Innovation Inc.
L'innovation de Globules Rouges Inc.
  Permalink  
v2
Comments
chieto at 26-Nov-11 21:43pm
   
thanks Yvan.in what algorithm?
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

Check Out the following Code :
Private Sub btnCheck_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 bmp1 As Bitmap = Image.FromFile(txtFile1.Text)
    Dim bmp2 As Bitmap = Image.FromFile(txtFile2.Text)
 
    ' Make a difference image.
    Dim wid As Integer = Math.Min(bmp1.Width, bmp2.Width)
    Dim hgt As Integer = Math.Min(bmp1.Height, bmp2.Height)
    Dim bmp3 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 = bmp1.GetPixel(x, y)
            color2 = bmp2.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
                bmp3.SetPixel(x, y, eq_color)
            Else
                bmp3.SetPixel(x, y, ne_color)
                are_identical = False
            End If
        Next y
    Next x
 
    ' Display the result.
    picResult.Image = bmp3
 
    Me.Cursor = Cursors.Default
    If (bmp1.Width <> bmp2.Width) OrElse (bmp1.Height <> _
        bmp2.Height) Then are_identical = False
    If are_identical Then
        MessageBox.Show("The images are identical")
    Else
        MessageBox.Show("The images are different")
    End If
 
    bmp1.Dispose()
    bmp2.Dispose()
End Sub
I hope it will help you.
  Permalink  
Comments
chieto at 26-Nov-11 21:44pm
   
thanks

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

  Print Answers RSS
0 OriginalGriff 605
1 Maciej Los 319
2 BillWoodruff 184
3 Richard MacCutchan 180
4 Suraj Sahoo | Coding Passion 180
0 OriginalGriff 8,654
1 Sergey Alexandrovich Kryukov 7,407
2 DamithSL 5,639
3 Maciej Los 5,229
4 Manas Bhardwaj 4,986


Advertise | Privacy | Mobile
Web02 | 2.8.1411023.1 | Last Updated 26 Nov 2011
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100