Processing math: 100%
ImageDev

CudaMedianFilter2d

Applies a median operator, which is a non-linear smoothing filter, on a two-dimensional image. The calculations are performed on the GPU.

Access to parameter description

This command is experimental, his signature may be modified between now and his final version.

For an introduction to image filters: section Images Filtering.

This algorithm uses morphological operators to set the pixel value to the median for the defined neighborhood. This filter is particularly effective for removing speckle noise and salt and pepper noise (impulsive noise) without affecting edges.
The median filter usually works well with images containing non-Gaussian noise and/or very small artifacts. It does not cause blurring to the same extent as the Box Filter, but takes longer to execute.

The gray levels of all pixels of the considered neighborhood are sorted from the smallest value to the largest one. The central pixel in the sort is then the median value (the value for which there are as many lower gray levels as higher ones). The process can be iterated.

Considering the array: [121715201416181914] The sorted gray level values are: [12 14 14 15 16 17 18 19 20]. The median value is 16, and it is assigned to the output pixel.

See also

Function Syntax

This function returns outputImage.
// Function prototype
std::shared_ptr< iolink::ImageView > cudaMedianFilter2d( std::shared_ptr< iolink::ImageView > inputImage, uint32_t kernelRadius, CudaMedianFilter2d::TilingMode tilingMode, iolink::Vector2u32 tileSize, CudaContext::Ptr cudaContext, std::shared_ptr< iolink::ImageView > outputImage = nullptr );

Class Syntax

Parameters

Parameter Name Description Type Supported Values Default Value
input
inputImage
The input image. Image Binary, Label, Grayscale or Multispectral nullptr
input
kernelRadius
The half size of the structuring element. A square structuring element always has an odd side length (3x3, 5x5, etc.) which is defined by twice the kernel radius + 1. UInt32 [1, 6] 3
input
tilingMode
The way to manage the GPU memory.
NONE The entire input image is transferred to the GPU memory. If the total input, intermediate and output data size exceed the GPU memory, the computation will fail.
USER_DEFINED The input image is processed by tiles of a predefined size.
Enumeration NONE
input
tileSize
The tile width and height in pixels. This parameter is used only in USER_DEFINED tiling mode. Vector2u32 >=1 {1024, 1024}
input
cudaContext
CUDA context information. CudaContext nullptr
output
outputImage
The output image. Its dimensions and type are forced to the same values as the input. Image nullptr

Object Examples

auto polystyrene = ioformat::readImage( std::string( IMAGEDEVDATA_IMAGES_FOLDER ) + "polystyrene.tif" );

CudaMedianFilter2d cudaMedianFilter2dAlgo;
cudaMedianFilter2dAlgo.setInputImage( polystyrene );
cudaMedianFilter2dAlgo.setKernelRadius( 3 );
cudaMedianFilter2dAlgo.setTilingMode( CudaMedianFilter2d::TilingMode::NONE );
cudaMedianFilter2dAlgo.setTileSize( {264, 264} );
cudaMedianFilter2dAlgo.setCudaContext( nullptr );
cudaMedianFilter2dAlgo.setOutputImage( iolink::ImageViewFactory::allocate( iolink::VectorXu64( { 1, 1 } ), iolink::DataTypeId::UINT8 ) );
cudaMedianFilter2dAlgo.execute();

std::cout << "outputImage:" << cudaMedianFilter2dAlgo.outputImage()->toString();

Function Examples

auto polystyrene = ioformat::readImage( std::string( IMAGEDEVDATA_IMAGES_FOLDER ) + "polystyrene.tif" );

auto result = cudaMedianFilter2d( polystyrene, 3, CudaMedianFilter2d::TilingMode::NONE, {264, 264}, nullptr , iolink::ImageViewFactory::allocate( iolink::VectorXu64( { 1, 1 } ), iolink::DataTypeId::UINT8 ));

std::cout << "outputImage:" << result->toString();