CS676 Jan-Apr 2011

Homework 6

Background Modeling and Foreground Extraction

Implement the Single Gaussian based Background Modeling and Foreground Extraction on the PETS2000 data set.

/******************* Sample Data Structure and Functions **********************/

// Background Model Data Structure
struct CBakSG
{
       // Background Model Width
       int m_Width;

       // Background Model Height
       int m_Height;

       // Number of Channels
       // NOTE : ChannelNum = 3 for RGB Images
       int m_ChannelNum;

       // Background Model Mean Value Array
       float* m_MeanValArray;

       // Background Model Variance Value Array
       float* m_VarValArray;

       // The Mean/Variance Value Array Size
       // NOTE : ArraySize = Width * Height * ChannelNum
       int m_MeanVarValArraySize;
};

// Initialization to NULL Pointers and Negative Size Values
void initialize_CBakSG( CBakSG* bak );

// Allocation
unsigned char allocate_CBakSG( CBakSG* bak , int width , int height , int channelNum );

// Deallocation
unsigned char deallocate_CBakSG( CBakSG* bak );

// Foreground Extraction
// frameData : Input RGB Image
// clasImg : Background (0/BLACK) and Foreground (255/WHITE) Segmented Image
// membershipThreshold : Chebychev Inequality Constant
unsigned char classify_CBakSG( CBakSG* bak , IplImage* frameData , IplImage* clasImg , float membershipThreshold );

// Background Model Update
// clasImg : Here we use the Background-Foreground Segmented Image as a Mask for Updating
// updateRate : The Updating Rate (alpha) for Mean/Variance
// selectiveUpdate : Set to TRUE if Update is Performed Strictly at the Background Pixels (BLACK) in clasImg
// clipVariance : Set to TRUE if the Updated Variance Value is not allowed to fall under a certain value (e.g. initial variance value)
unsigned char update_CBakSG( CBakSG* bak , IplImage* frameData , IplImage* clasImg , float updateRate , bool selectiveUpdate , bool clipVariance );

// Function for Viewing the Background Model
// bakImg : The Rounded Off Mean Background Image as a RGB IplImage
unsigned char getBakImg_CBakSG( CBakSG* bak , IplImage* bakImg );


/*********************************************************************************/

Perform the Background Foreground Segmentation in the following Sequence Also, Pls find attached the codes for connected component analysis. This CPP file is 
to be placed in the CVDRIKImageProcessing directory and the functions to be pushed into the CVDRIKImageProcessing.h file. A sample code showing the usage of 
Connceted Component Analysis is also Attached which would show how the functions are to be called, what temporary variables are to be allocated etc
clasify_BakSubSG( ... ) ---> gives you the noisy classification image stored in auxImg (temporary image)

vote( auxImg , clasImg , , nbhSize , voteThreshold ) ---> Removes
classification noise by neighborhood voting and stores the result in a temporary image called auxImg

binaryCCA( auxImg, ... , minBlobSize ) ----> Removes the small blobs whose size is lesser than the minBlobSize. This code will be supplied along with the 
assignment set

update_BakSubSG( ..., clasImg ,... ) ----> Updates the Background Model by using clasImg as a Mask

In each stage display the Current Input Image, The Current Background-Foreground Segmented Image and the Mean Background Image. Play around with the update 
rate (keeping selectiveUpdate = FLASE) and see the effect of the update rate on the mean background Image

Parameter Ranges

1. Initial Variance : 4 - 16
2. Membership Threshold : 2.5 - 5
3. updateRate : 0.005 - 0.0 
Also, below are the codes for connected component analysis. This CPP file is to be placed in the CVDRIKImageProcessing directory and the functions to be pushed into the CVDRIKImageProcessing.h file. The function works if there are less then 255 blobs, so remove noise beforehand. A sample code showing the usage of Connceted Component Analysis is also Attached which would show how the functions are to be called, what temporary variables are to be allocated etc
CVDRIKIPCCA.cpp
getLabelImageCCA.cpp

Please upload the code as a .zip file on your homepage