Noise Reduction Example
This example program illustrates linear and non-linear filters supported by the
library functions. After adding some noise to two input images, the program
filters the images obtained. (The noise intensity is determined by the
number of image pixels that change their values because of the noise.)
One of the images is filtered by two filters:
the median filter and a low-pass filter with a threshold.
For the other image, you can choose the filters yourself.
To run the example from the command line, type:
>filter -t1 -f<filter> -w<band width>
The source:
void testFilter( IplImage* srcimg, IplImage* dstimg, const char* filter ) { IplImage* noisy = iplCloneImage( srcimg ); IplImage* noisier = iplCloneImage( srcimg ); // produce noisy with 5% of the image corrupted flipPixel8uC1( noisy, 0.05f); // produce noisier with 20% of the image corrupted flipPixel8uC1( noisier, 0.2f); // display the results ipView( noisy, "Noisy", !is_modal ); ipView( noisier, "Noisier", !is_modal ); // Try to remove the noise, w/Median iplMedianFilter( noisy, dstimg, 3,3, 1,1 ); ipView( dstimg,"MedianFilter(Noisy)", !is_modal ); // Try to remove the noise, w/Gaussian&threshold iplFixedFilter( noisy, dstimg, IPL_GAUSSIAN_5x5 ); ipView( dstimg, "Gaussian(Noisy)", !is_modal ); iplThreshold( dstimg, dstimg, 128 ); ipView( dstimg,"Threshold(Gaussian(Noisy))", !is_modal ); __int64 start, stop; char title[128], funcname[32]; int size = noisier->width* noisier->height; // filter the noisier image switch( toupper(filter[0]) ) { case 'S' : start = getPentiumCounter(); iplFixedFilter( noisier, noisy, IPL_SOBEL_3x3_H ); iplFixedFilter( noisy, dstimg, IPL_SOBEL_3x3_V ); stop = getPentiumCounter(); strcpy( funcname, "Sobel(Noisier)" ); break; ... } sprintf( title, "%s : %.1f cpe", funcname, (float)(stop-start) / size ); ipView( dstimg, title, is_modal ); iplDeallocate( noisy, IPL_IMAGE_ALL ); iplDeallocate( noisier, IPL_IMAGE_ALL ); }
* Legal Information © 1998-2000, Intel Corporation