Victor Image Processing Library How-to Tips

Detect Scene Change


Reference Frame

Test Frame1
corelation coef = .91

Test Frame2
correlation coef = .97

Test Frame3
correlation coef = .97

Test Frame4
correlation coef = .94

Test Frame5
correlation coef = .96

Test Frame6
correlation coef = .96

Test Frame7
correlation coef = .96

Test Frame8
correlation coef = .78

Test Frame9
correlation coef = .97

In this example we captured a series of JPEG images from a camera aimed at a traffic scene. Using the first frame as the reference, we analyzed each image by comparing it to the reference and calculated the correlation coefficient. The individual frames and their coefficients are shown at left.

The Visual Basic sample application, Comparator, uses the Victor Library and the helper modules vicstats and vicfx to load, compare, and analyze images. Download Comparator and its VB source code.

We can see that for the frames with no vehicles shown the correlations to the reference image are very high: .96 and .97. But when a car begins to enter the scene, as in Test Frame4 the value dips to .94. Test Frame1 shows a dark vehicle in the far lane and the value drops to .91. And in Frame8 the value dramatically declined to .78 when a car begins to enter the scene in the near lane.

This can be an efficient method for automatically screening video frames for scene changes. The suspect frames can then be analyzed visually or with image processing techniques. The applications can include detecting motion with security cameras, finding a matching image, and quality control.

The procedure is:

  • determine the dimensions of the reference image and allocate a source image buffer
  • determine the dimensions of the test image and allocate an operator image buffer
  • load each image
  • calculate the correlation coefficient
  • report the correlation coefficient in the message box

VB Source Code


Detect Scene Change - the Visual Basic Source Code

Requires Victor Image Processing Library for 32-bit Windows v 5.4 or higher and the helper dll vicstats.dll.
' Function Declarations and Data Type Definitions are in vic32def.bas 
' see the Victor Library sample VB applications Loadpic or Comparator 

' The Function .................................................... 
Private Sub mnudetectscenechange_Click()
Dim rcode As Long
Dim sourceimage As imgdes        ' Image descriptor for the reference image 
Dim operatorimage As imgdes      ' Image descriptor for the test image 
Dim tempimage As imgdes          ' Just in case we have to convert test image to same pixel depth as the reference image 
Dim filedata As JpegData
Dim srcbpp As Long
Dim coef As Double               ' Correlation Coefficient 
Dim resultstr As String

    ' Get the image dimensions from the first file 
    rcode = jpeginfo("p1a.jpg", filedata)
    If (rcode = NO_ERROR) Then
        ' Allocate an image buffer to hold the image 
        rcode = allocimage(sourceimage, filedata.width, filedata.length, filedata.vbitcount)
        If (rcode = NO_ERROR) Then
            ' Load the image from the file 
            rcode = loadjpg("p1a.jpg", sourceimage)
            If (rcode = NO_ERROR) Then  ' Successfully loaded the reference image 
                srcbpp = filedata.vbitcount
                ' Get the image dimensions from the second file 
                rcode = jpeginfo("p3a.jpg", filedata)
                If (rcode = NO_ERROR) Then
                    ' Allocate an image buffer to hold the image 
                    rcode = allocimage(operatorimage, filedata.width, filedata.length, filedata.vbitcount)
                    If (rcode = NO_ERROR) Then
                        ' Load the image from the file 
                        rcode = loadjpg("p3a.jpg", operatorimage)
                        If (rcode = NO_ERROR) Then
                            ' Test for pixel depth 
                            If (filedata.vbitcount <> srcbpp) Then  ' If it's not compatible pixel depth 
                                ' Allocate the temporary image buffer 
                                rcode = allocimage(tempimage, filedata.width, filedata.length, srcbpp)
                                If (rcode = NO_ERROR) Then
                                    If (srcbpp = 24) Then
                                        ' Convert 8-bit grayscale to rgb color 
                                        rcode = convertpaltorgb(operatorimage, tempimage)
                                    Else
                                        ' Convert 24-bit color to 8-bit grayscale 
                                        rcode = colortogray(operatorimage, tempimage)
                                    End If
                                    
                                    If (rcode = NO_ERROR) Then
                                        ' Replace the original operator image with the converted image 
                                        freeimage operatorimage
                                        copyimgdes tempimage, operatorimage
                                    End If
                                End If
                            End If
                            
                        ' Now do the analysis 
                        rcode = correlationcoef(sourceimage, operatorimage, coef)
                        freeimage operatorimage

                    End If
                End If
            End If
            freeimage sourceimage
        End If
    End If
End If

resultstr = "Result of analysis:" + Chr(13)
resultstr = resultstr + "rcode = " + Str(rcode) + Chr(13)

If (rcode = NO_ERROR) Then
    resultstr = resultstr + "Correlation Coefficient = " + Str(coef) + Chr(13)
End If
MsgBox resultstr

End Sub




Victor Image Processing Library

Victor Image Processing Library homepage | Victor Product Summary | more source code




Copyright © 2003 Catenary Systems Inc. All rights reserved. Victor Image Processing Library is a trademark of Catenary Systems.