Image comparison

Image comparison

Post by R.Saravana Pratha » Wed, 02 Jul 2003 15:20:07



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

 
 
 

Image comparison

Post by Mike D Sutto » Wed, 02 Jul 2003 17:25:51


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/

 
 
 

Image comparison

Post by Schmid » Wed, 02 Jul 2003 20:35:11



> 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

 
 
 

1. image comparison package?

hi all,
what i imagine is a software library with a function you can call on 2
images which returns a value describing how equal they are (ie. 100% if
they are equal, and something like a couple random % if they have
nothing in common, and a relatively high % number if they show the same
image, but are different in size or there are some random errors).
does anybody know of a free, preferrably portable, preferrably C or C++
library which can accomplish this?
thx, helge.

Sent via Deja.com http://www.deja.com/
Before you buy.

2. Palette Code Needed

3. Electric Image comparison?

4. BitMap from HDC

5. Image comparison

6. delphiX help file.

7. Image comparison algorithm ?

8. fli animator

9. Image comparison

10. looking for routines (algorithms) to do image comparison

11. Image Comparison

12. Image Comparison or Deltas

13. image comparison algorithms/software