Skip to content

Instantly share code, notes, and snippets.

@hone
Created September 27, 2008 02:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hone/13243 to your computer and use it in GitHub Desktop.
Save hone/13243 to your computer and use it in GitHub Desktop.
#include <string>
#include "image_loader.h"
#include <cv.h>
#include <highgui.h>
/**
* constructs a box filter. a matrix with all 1s and is normalized.
* @param size of box filter as an int.
*/
void makeBoxFilter( CvMat * mat, int w )
{
double one_over_w_squared = 1.0 / ( w * w );
double data[w][w];
// initialize data array
for( int i = 0; i < w; i++ )
{
for( int j = 0; j < w; j++ )
{
//data[i][j] = one_over_w_squared;
data[i][j] = 1.0;
}
}
cvInitMatHeader( mat, w, w, CV_64FC1, data );
}
int main( int argc, char * argv[] )
{
// load image
std::string filename = "cameraman.tif";
ImageLoader original_image( filename );
IplImage * grayscale_image = cvCreateImage( cvSize( original_image.image->width, original_image.image->height ), IPL_DEPTH_8U, 1 );
IplImage * box_filtered_image = cvCreateImage( cvSize( original_image.image->width, original_image.image->height ), IPL_DEPTH_8U, 1 );
CvMat * box_filter = new CvMat();
makeBoxFilter( box_filter, 3 );
// Convert image to grayscale
cvCvtColor( original_image.image, grayscale_image, CV_BGR2GRAY );
cvFilter2D( grayscale_image, box_filtered_image, box_filter );
// create window
cvNamedWindow( "mainWin", CV_WINDOW_AUTOSIZE );
cvShowImage( "mainWin", box_filtered_image );
cvWaitKey( 0 );
cvReleaseImage( &grayscale_image );
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment