Commit 7e589c5b authored by jaco's avatar jaco

lowResolutionDetection function completed

parent 83081fd4
...@@ -139,6 +139,7 @@ class CV_EXPORTS_W MotionSaliencyBinWangApr2014 : public MotionSaliency ...@@ -139,6 +139,7 @@ class CV_EXPORTS_W MotionSaliencyBinWangApr2014 : public MotionSaliency
// background pixel. In a noise-pixel mask, the identified noise-pixels are set to 1 while other pixels are 0; // background pixel. In a noise-pixel mask, the identified noise-pixels are set to 1 while other pixels are 0;
//fixed parameter //fixed parameter
int N_DS; // Number of template to be downsampled and used in lowResolutionDetection function
Ptr<Size> imgSize; // Size of input image Ptr<Size> imgSize; // Size of input image
int K; // Number of background model template int K; // Number of background model template
int N; // NxN is the size of the block for downsampling in the lowlowResolutionDetection int N; // NxN is the size of the block for downsampling in the lowlowResolutionDetection
......
...@@ -55,7 +55,7 @@ void MotionSaliencyBinWangApr2014::setWsize( const cv::Ptr<Size>& newSize ) ...@@ -55,7 +55,7 @@ void MotionSaliencyBinWangApr2014::setWsize( const cv::Ptr<Size>& newSize )
MotionSaliencyBinWangApr2014::MotionSaliencyBinWangApr2014() MotionSaliencyBinWangApr2014::MotionSaliencyBinWangApr2014()
{ {
N_DS = 2; // Number of template to be downsampled and used in lowResolutionDetection function
K = 3; // Number of background model template K = 3; // Number of background model template
N = 4; // NxN is the size of the block for downsampling in the lowlowResolutionDetection N = 4; // NxN is the size of the block for downsampling in the lowlowResolutionDetection
alpha = 0.01; // Learning rate alpha = 0.01; // Learning rate
...@@ -121,7 +121,7 @@ bool MotionSaliencyBinWangApr2014::fullResolutionDetection( const Mat& image, Ma ...@@ -121,7 +121,7 @@ bool MotionSaliencyBinWangApr2014::fullResolutionDetection( const Mat& image, Ma
currentEpslonValue = epslonPixelsValue.at<float>( i, j ); currentEpslonValue = epslonPixelsValue.at<float>( i, j );
// scan background model vector // scan background model vector
for ( size_t z = 0; z <backgroundModel.size(); z++ ) for ( size_t z = 0; z < backgroundModel.size(); z++ )
{ {
// TODO replace "at" with more efficient matrix access // TODO replace "at" with more efficient matrix access
currentB = &backgroundModel[z].at<Vec2f>( i, j )[0]; currentB = &backgroundModel[z].at<Vec2f>( i, j )[0];
...@@ -136,7 +136,7 @@ bool MotionSaliencyBinWangApr2014::fullResolutionDetection( const Mat& image, Ma ...@@ -136,7 +136,7 @@ bool MotionSaliencyBinWangApr2014::fullResolutionDetection( const Mat& image, Ma
// TODO replace "at" with more efficient matrix access // TODO replace "at" with more efficient matrix access
highResBFMask.at<uchar>( i, j ) = 0; highResBFMask.at<uchar>( i, j ) = 0;
if((*currentC< L0 && z==0) || (*currentC< L1 && z==1) || (z>1)) if( ( *currentC < L0 && z == 0 ) || ( *currentC < L1 && z == 1 ) || ( z > 1 ) )
*currentC += 1; // increment the efficacy of this template *currentC += 1; // increment the efficacy of this template
*currentB = ( ( 1 - alpha ) * * ( currentB ) ) + ( alpha * currentPixelValue ); // Update the template value *currentB = ( ( 1 - alpha ) * * ( currentB ) ) + ( alpha * currentPixelValue ); // Update the template value
...@@ -162,10 +162,8 @@ bool MotionSaliencyBinWangApr2014::lowResolutionDetection( const Mat& image, Mat ...@@ -162,10 +162,8 @@ bool MotionSaliencyBinWangApr2014::lowResolutionDetection( const Mat& image, Mat
{ {
float currentPixelValue; float currentPixelValue;
float currentEpslonValue; float currentEpslonValue;
float currentB;
//Size resizedDimension = image.size() / ( N * N ); float currentC;
Mat resizedImageResults( image.size().height / ( N * N ), image.size().width / ( N * N ), CV_8UC1 );
Mat resizedBackGroundModelResults( image.size().height / ( N * N ), image.size().width / ( N * N ), CV_32FC2 );
// Create a mask to select ROI in the original Image and Backgound model and at the same time compute the mean // Create a mask to select ROI in the original Image and Backgound model and at the same time compute the mean
Mat ROIMask( image.rows, image.cols, CV_8UC1 ); Mat ROIMask( image.rows, image.cols, CV_8UC1 );
...@@ -181,34 +179,38 @@ bool MotionSaliencyBinWangApr2014::lowResolutionDetection( const Mat& image, Mat ...@@ -181,34 +179,38 @@ bool MotionSaliencyBinWangApr2014::lowResolutionDetection( const Mat& image, Mat
lowResBFMask.setTo( 1 ); lowResBFMask.setTo( 1 );
// Scan all the ROI of original matrices that correspond to the pixels of new resized matrices // Scan all the ROI of original matrices that correspond to the pixels of new resized matrices
for ( int i = 0; i < resizedImageResults.rows; i++ ) for ( int i = 0; i < image.rows/( N * N ); i++ )
{ {
for ( int j = 0; j < resizedImageResults.cols; j++ ) for ( int j = 0; j < image.cols/( N * N ); j++ )
{ {
// Reser ROI mask // Reset and update ROI mask
ROIMask.setTo( 0 ); ROIMask.setTo( 0 );
// Compute the mean of image's block based on ROI
rectangle( ROIMask, roi, Scalar( 255 ), FILLED ); rectangle( ROIMask, roi, Scalar( 255 ), FILLED );
imageROImean = mean( image, ROIMask );
// Compute the mean of epslonMatrix's block based on ROI
// Insert the just calculated mean value in the correct pixel of the resized image
resizedImageResults.at<uchar>( i, j ) = imageROImean.val[0];
// Compute the mean of image's block and epslonMatrix's block based on ROI
// TODO replace "at" with more efficient matrix access // TODO replace "at" with more efficient matrix access
currentPixelValue = imageROImean.val[0]; currentPixelValue = mean( image, ROIMask ).val[0];
currentEpslonValue = mean(epslonPixelsValue, ROIMask).val[0]; currentEpslonValue = mean( epslonPixelsValue, ROIMask ).val[0];
// scan background model vector // scan background model vector
for ( size_t z = 0; z < 2 /* first two template*/; z++ ) for ( size_t z = 0; z < N_DS; z++ )
{ {
// Select the current template 2 channel matrix, select ROI and compute the mean for each channel separately // Select the current template 2 channel matrix, select ROI and compute the mean for each channel separately
currentModel = backgroundModel[z]; currentB = mean( backgroundModel[z], ROIMask ).val[0];
backGModelROImean = mean( currentModel, ROIMask ); currentC = mean( backgroundModel[z], ROIMask ).val[1];
// Insert the just calculated mean values in the correct pixels of the resized background template
resizedBackGroundModelResults.at<Vec2f>( i, j )[0] = backGModelROImean.val[0]; if( currentC > 0 ) //The current template is active
resizedBackGroundModelResults.at<Vec2f>( i, j )[1] = backGModelROImean.val[1]; {
// If there is a match with a current background template
if( abs( currentPixelValue - ( currentB ) ) < currentEpslonValue )
{
// The correspondence pixel in the BF mask is set as background ( 0 value)
// TODO replace "at" with more efficient matrix access
lowResBFMask.at<uchar>( i, j ) = 0;
break;
}
}
} }
// Shift the ROI from left to right follow the block dimension // Shift the ROI from left to right follow the block dimension
roi = roi + Point( 0, N ); roi = roi + Point( 0, N );
...@@ -217,11 +219,13 @@ bool MotionSaliencyBinWangApr2014::lowResolutionDetection( const Mat& image, Mat ...@@ -217,11 +219,13 @@ bool MotionSaliencyBinWangApr2014::lowResolutionDetection( const Mat& image, Mat
roi = roi + Point( N, - ( image.cols - N ) ); roi = roi + Point( N, - ( image.cols - N ) );
} }
//resize( image, resizedImage, resizedDimension, 0, 0, INTER_LINEAR ); // UPSAMPLE the lowResBFMask to the original image dimension, so that it's then possible to compare the results
//resize( image, resizedBackGroundModel, resizedDimension, 0, 0, INTER_LINEAR ); // of lowlResolutionDetection with the fullResolutionDetection
resize( lowResBFMask, lowResBFMask, image.size(), 0, 0, INTER_LINEAR );
return true; return true;
} }
/*bool MotionSaliencyBinWangApr2014::templateUpdate( Mat highResBFMask ) /*bool MotionSaliencyBinWangApr2014::templateUpdate( Mat highResBFMask )
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment