Thursday, April 2, 2009

DIP using OpenCV #2 : Clearing an image


// clear the image

cvSet( IplImage* img, cvScalar(0,0));

// this will set each and every pixel to zero

Another simple method I recently became aware of:

cvZero( IplImage* img );

Wednesday, April 1, 2009

Image processing using OpenCV #1: Invert an image

Code to open an image and invert it using OpenCV:


img = cvLoadImage(argv[1]);

// get the image data
height = img->height;
width = img->width;
step = img->widthStep;
channels = img->nChannels;
data = (uchar *)img->imageData;

for( i=0;i<height;i++ )
{
for( j=0;j<width;j++ )
{
for( k=0;k<channels;k++ )
data[i*step+j*channels+k] = 255 - data[i*step+j*channels+k];
}
}

Followers