RP → Filtering

The concept of filtering involves neighborhood operations work with the values of the image pixels in the neighborhood and the corresponding values of a subimage that has the same dimensions as the neighborhood.

Dependencies: Raster

Edge Filters

Local discontinuities in image luminance from one level to another are called luminance edges, limited to image amplitude discontinuities between reasonably smooth regions. There are two major classes of differential edge detection: first- and second-order derivative. For the first-order class, some form of spatial first-order differentiation is performed, and the resulting edge gradient is compared to a threshold value. An edge is judged present if the gradient exceeds the threshold. For the second-order derivative class of differential edge detection, an edge is judged present if there is a significant spatial change in the polarity of the second derivative.

Sobel

The Sobel operator edge detector where the mask values of the north, south, east, and west pixels are doubled. The motivation for this weighting is to give equal importance to each pixel in terms of its contribution to the spatial gradient.

Original Image Filtered Image

Example of use
// Openning the the input image
 
te::rst::Raster inputRaster;
....
....
 
// Creating the algorithm parameters
 
te::rp::Filter::InputParameters filterInputParameters;
 
filterInputParameters.m_type = te::rp::Filter::InputParameters::SobelFilterT;
filterInputParameters.m_windowH = 3;
filterInputParameters.m_windowW = 3;
filterInputParameters.m_inRasterPtr = &inputRaster;
filterInputParameters.m_inRasterBands.push_back(0);
 
te::rp::Filter::OutputParameters filterOutputParameters;
filterOutputParameters.m_createdOutRasterInfo = "FilteredImage.tif";
filterOutputParameters.m_createdOutRasterDSType = "GDAL";
filterOutputParameters.m_normalizeOutput = false;
 
// execute the algorithm
te::rp::Filter filterInstance;
filterInstance.initialize(filterInputParameters);
filterInstance.execute(filterOutputParameters);

Roberts

Diagonal edge gradients can be obtained by forming running differences of diagonal pairs of pixels. This is the basis of the Roberts cross-difference operator:

Original Image Filtered Image

Example of use
// Openning the the input image
 
te::rst::Raster inputRaster;
....
....
 
// Creating the algorithm parameters
 
te::rp::Filter::InputParameters filterInputParameters;
 
filterInputParameters.m_type = te::rp::Filter::InputParameters::RobertsFilterT;
filterInputParameters.m_windowH = 3;
filterInputParameters.m_windowW = 3;
filterInputParameters.m_inRasterPtr = &inputRaster;
filterInputParameters.m_inRasterBands.push_back(0);
 
te::rp::Filter::OutputParameters filterOutputParameters;
filterOutputParameters.m_createdOutRasterInfo = "FilteredImage.tif";
filterOutputParameters.m_createdOutRasterDSType = "GDAL";
filterOutputParameters.m_normalizeOutput = false;
 
// execute the algorithm
te::rp::Filter filterInstance;
filterInstance.initialize(filterInputParameters);
filterInstance.execute(filterOutputParameters);

Smoothing Spatial Filters

Smoothing filters are used for blurring and for noise reduction. Blurring is used in preprocessing steps, such as removal of small details from an image prior to (large) object extraction, and bridging of small gaps in lines or curves. Noise reduction can be accomplished by blurring with a linear filter and also by nonlinear filtering.

Mean

The output of a mean, linear spatial filter is simply the average of the pixels contained in the neighborhood of the filter mask. These filters sometimes are called averaging filters or lowpass filters. A major use of averaging filters is in the reduction of “irrelevant” detail in an image. By “irrelevant” we mean pixel regions that are small with respect to the size of the filter mask.

cbers_rgb342_crop1_zoom.jpg

Example of use
// Openning the the input image
 
te::rst::Raster inputRaster;
....
....
 
// Creating the algorithm parameters
 
te::rp::Filter::InputParameters filterInputParameters;
 
filterInputParameters.m_type = te::rp::Filter::InputParameters::MeanFilterT;
filterInputParameters.m_windowH = 3;
filterInputParameters.m_windowW = 3;
filterInputParameters.m_inRasterPtr = &inputRaster;
filterInputParameters.m_inRasterBands.push_back(0);
 
te::rp::Filter::OutputParameters filterOutputParameters;
filterOutputParameters.m_createdOutRasterInfo = "FilteredImage.tif";
filterOutputParameters.m_createdOutRasterDSType = "GDAL";
filterOutputParameters.m_normalizeOutput = false;
 
// execute the algorithm
te::rp::Filter filterInstance;
filterInstance.initialize(filterInputParameters);
filterInstance.execute(filterOutputParameters);

Mode

The Mode filter is used to remove noise from an image by replacing pixels with the most frequently occurring pixel value selected from a certain window size.

Example of use
// Openning the the input image
 
te::rst::Raster inputRaster;
....
....
 
// Creating the algorithm parameters
 
te::rp::Filter::InputParameters filterInputParameters;
 
filterInputParameters.m_type = te::rp::Filter::InputParameters::ModeFilterT;
filterInputParameters.m_windowH = 3;
filterInputParameters.m_windowW = 3;
filterInputParameters.m_inRasterPtr = &inputRaster;
filterInputParameters.m_inRasterBands.push_back(0);
 
te::rp::Filter::OutputParameters filterOutputParameters;
filterOutputParameters.m_createdOutRasterInfo = "FilteredImage.tif";
filterOutputParameters.m_createdOutRasterDSType = "GDAL";
filterOutputParameters.m_normalizeOutput = false;
 
// execute the algorithm
te::rp::Filter filterInstance;
filterInstance.initialize(filterInputParameters);
filterInstance.execute(filterOutputParameters);

Median

A median filter, which, as its name implies, replaces the value of a pixel by the median of the gray levels in the neighborhood of that pixel (the original value of the pixel is included in the computation of the median). Median filters are quite popular because, for certain types of random noise, they provide excellent noise-reduction capabilities, with considerably less blurring than linear smoothing filters of similar size.

Example of use
// Openning the the input image
 
te::rst::Raster inputRaster;
....
....
 
// Creating the algorithm parameters
 
te::rp::Filter::InputParameters filterInputParameters;
 
filterInputParameters.m_type = te::rp::Filter::InputParameters::MedianFilterT;
filterInputParameters.m_windowH = 3;
filterInputParameters.m_windowW = 3;
filterInputParameters.m_inRasterPtr = &inputRaster;
filterInputParameters.m_inRasterBands.push_back(0);
 
te::rp::Filter::OutputParameters filterOutputParameters;
filterOutputParameters.m_createdOutRasterInfo = "FilteredImage.tif";
filterOutputParameters.m_createdOutRasterDSType = "GDAL";
filterOutputParameters.m_normalizeOutput = false;
 
// execute the algorithm
te::rp::Filter filterInstance;
filterInstance.initialize(filterInputParameters);
filterInstance.execute(filterOutputParameters);

Morphological Filters

Morphological image processing is a type of processing in which the spatial form or structure of objects within an image are modified. Dilation and erosion are three fundamental morphological operations.

Dilation

With dilation, an object grows uniformly in spatial extent, whereas with erosion an object shrinks uniformly.

Example of use
// Openning the the input image
 
te::rst::Raster inputRaster;
....
....
 
// Creating the algorithm parameters
 
te::rp::Filter::InputParameters filterInputParameters;
 
filterInputParameters.m_type = te::rp::Filter::InputParameters::DilationFilterT;
filterInputParameters.m_windowH = 3;
filterInputParameters.m_windowW = 3;
filterInputParameters.m_inRasterPtr = &inputRaster;
filterInputParameters.m_inRasterBands.push_back(0);
 
te::rp::Filter::OutputParameters filterOutputParameters;
filterOutputParameters.m_createdOutRasterInfo = "FilteredImage.tif";
filterOutputParameters.m_createdOutRasterDSType = "GDAL";
filterOutputParameters.m_normalizeOutput = false;
 
// execute the algorithm
te::rp::Filter filterInstance;
filterInstance.initialize(filterInputParameters);
filterInstance.execute(filterOutputParameters);

Erosion

With erosion an object shrinks uniformly.

Example of use
// Openning the the input image
 
te::rst::Raster inputRaster;
....
....
 
// Creating the algorithm parameters
 
te::rp::Filter::InputParameters filterInputParameters;
 
filterInputParameters.m_type = te::rp::Filter::InputParameters::ErosionFilterT;
filterInputParameters.m_windowH = 3;
filterInputParameters.m_windowW = 3;
filterInputParameters.m_inRasterPtr = &inputRaster;
filterInputParameters.m_inRasterBands.push_back(0);
 
te::rp::Filter::OutputParameters filterOutputParameters;
filterOutputParameters.m_createdOutRasterInfo = "FilteredImage.tif";
filterOutputParameters.m_createdOutRasterDSType = "GDAL";
filterOutputParameters.m_normalizeOutput = false;
 
// execute the algorithm
te::rp::Filter filterInstance;
filterInstance.initialize(filterInputParameters);
filterInstance.execute(filterOutputParameters);

Rerefences

Rafael C. Gonzales, Richard E. Woods, Digital Image Processing, second edition,. Prentice Hall, 2002. William K. Pratt, Digital Image Processing: PIKS Inside, Third Edition.


QR Code
QR Code wiki:designimplementation:rp:filtering (generated for current page)