Image comparison 
Author Message
 Image comparison

Hey all,

I want to compare images and group similar images and display the images.
Give me an idea how to go about...

sample code will be more helpful

thanks in advance,

Prathap



Sat, 17 Dec 2005 14:20:07 GMT  
 Image comparison

Quote:
> I want to compare images and group similar images and display the images.
> Give me an idea how to go about...

> sample code will be more helpful

Add three picture box's to your form, enable the AutoRedraw property of each
set the scale mode to vbPixels, put your pictures in 1 and 2 then run this
and the 'difference' image is generated into 3:

'***
Private Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, _
    ByVal X As Long, ByVal Y As Long, ByVal nWidth As Long, _
    ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, _
    ByVal ySrc As Long, ByVal dwRop As Long) As Long

...

Picture3.BackColor = vbBlack
Call BitBlt(Picture3.hDC(), 0, 0, Picture1.ScaleWidth, _
    Picture1.ScaleHeight, Picture1.hDC, 0, 0, vbSrcInvert)
Call BitBlt(Picture3.hDC(), 0, 0, Picture2.ScaleWidth, _
    Picture2.ScaleHeight, Picture2.hDC, 0, 0, vbSrcInvert)
'***

An all-black resulting image means you've got the same picture, anything
else means _something_ is different.  If you need to know what is different,
then this will create a mask for you:

'***
Private Declare Function GetPixel Lib "gdi32" (ByVal hDC As Long, _
    ByVal X As Long, ByVal Y As Long) As Long
Private Declare Function SetPixelV Lib "gdi32" (ByVal hDC As Long, _
    ByVal X As Long, ByVal Y As Long, ByVal crColor As Long) As Long

...

Dim LoopX As Long, LoopY As Long

For LoopX = 0 To Picture3.ScaleWidth - 1
    For LoopY = 0 To Picture3.ScaleHeight - 1
        Call SetPixelV(Picture3.hDC, LoopX, LoopY, _
            IIf(GetPixel(Picture3.hDC, LoopX, LoopY) = _
            vbBlack, vbBlack, vbWhite))
    Next LoopY
Next LoopX
'***

You can also use it to find what percentage of the image is different by
unwrapping the IIf(), or just give you a boolean IsSameImage result
depending on what you actually need, your post was rather vague in this
respect so I'm just guessing what you needed..
Hope this helps,

    Mike

 - Microsoft Visual Basic MVP -

WWW: Http://www.mvps.org/EDais/



Sat, 17 Dec 2005 16:25:51 GMT  
 Image comparison

Quote:

> I want to compare images and group similar images and display the images.
> Give me an idea how to go about...

> sample code will be more helpful

The following code can be used, to compare the Picture-Content of 2
VB-Picturebox-Controls.

'***Into a form (contains Picture1 and Picture2)
'***Load Pictures into Picture1 and Picture2.

Private Declare Function GetDIBits& Lib "gdi32" (ByVal hdc&, ByVal hBM&, _
  ByVal nStart&, ByVal nNum&, lpBits As Any, lpBI As Any, ByVal Usg&)

Private Sub Form_Click()
  MsgBox PicCompare(Picture1, Picture2)
End Sub

Function PicCompare(P1 As PictureBox, P2 As PictureBox) As Boolean
Dim B1&(), Arr1&(), B2&(), Arr2&(), W1&, W2&, H1&, H2&, x&, y&
  GetArrFromHdl Arr1, P1.hdc, P1.Picture, B1, 32
  W1 = B1(1): H1 = B1(2)
  GetArrFromHdl Arr2, P2.hdc, P2.Picture, B2, 32
  W2 = B2(1): H2 = B2(2)
  If W1 <> W2 Or H1 <> H2 Then Exit Function
  For y = 0 To H1 - 1
    For x = 0 To W1 - 1
      If Arr1(x, y) <> Arr2(x, y) Then Exit Function
    Next x
  Next y
  PicCompare = True
End Function

Private Sub GetArrFromHdl(P&(), SrcDC&, ByVal Hdl&, BI&(), ByVal BpP&)
Dim W&, H&
  ReDim P(0, 0): ReDim BI(1033): BI(0) = 40
  GetDIBits SrcDC, Hdl, 0, 0, ByVal 0&, BI(0), 0
  W = BI(1): H = BI(2): BI(2) = H: BI(3) = BpP * 65536 + 1: BI(4) = 0
  If W = 0 Or H = 0 Then Exit Sub
  ReDim P(W * BpP \ 32 - IIf(W * BpP Mod 32, 0, 1), H - 1)
  GetDIBits SrcDC, Hdl, 0, H, P(0, 0), BI(0), 0
End Sub

Olaf



Sat, 17 Dec 2005 19:35:11 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Image and picture control comparison

2. Printing Images with Imaging for Windows (Wang Imaging)

3. image 1 + image 2 = image 3 how ???

4. String comparison does not work

5. Null comparison with string

6. Text comparison

7. Comparison Operator - Erratic Behaviour

8. Table comparison

9. Visual Foxpro vs Jet 3.5 -- Comparison (Help!)

10. VFP vs Jet 3.5 Comparison (Help!)

11. Case-Sensitive Comparisons

12. address comparison

 

 
Powered by phpBB® Forum Software