ImageDev

MedianFilter3d

Applies a median operator, which is a non-linear smoothing filter, on a three-dimensional image.

Access to parameter description

For an introduction to image filters: section Images Filtering.

This algorithm uses morphological operators to set the voxel 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 voxels of the considered neighborhood are sorted from the smallest value to the largest one. The central voxel 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:
$$\begin{bmatrix} 1 & 2 & 3 \\ 4 & 5 & 6 \\ 7 & 8 & 9 \end{bmatrix} \begin{bmatrix} 12 & 17 & 15 \\ 20 & 14 & 16 \\ 18 & 19 & 14 \end{bmatrix} \begin{bmatrix} 20 & 21 & 22 \\ 23 & 24 & 25 \\ 26 & 27 & 28 \end{bmatrix} $$ The sorted gray level values are: [1 2 3 4 5 6 7 8 9 12 14 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28]. The median value is 16, and it is assigned to the output voxel.

See also
See related example

Function Syntax

This function returns outputImage.
// Function prototype
std::shared_ptr< iolink::ImageView > medianFilter3d( std::shared_ptr< iolink::ImageView > inputImage, uint32_t kernelRadius, MedianFilter3d::KernelMode kernelMode, MedianFilter3d::SearchMode searchMode, std::shared_ptr< iolink::ImageView > outputImage = nullptr );
This function returns outputImage.
// Function prototype.
median_filter_3d(input_image: idt.ImageType,
                 kernel_radius: int = 3,
                 kernel_mode: MedianFilter3d.KernelMode = MedianFilter3d.KernelMode.CUBE,
                 search_mode: MedianFilter3d.SearchMode = MedianFilter3d.SearchMode.AUTOMATIC,
                 output_image: idt.ImageType = None) -> idt.ImageType
This function returns outputImage.
// Function prototype.
public static IOLink.ImageView
MedianFilter3d( IOLink.ImageView inputImage,
                UInt32 kernelRadius = 3,
                MedianFilter3d.KernelMode kernelMode = ImageDev.MedianFilter3d.KernelMode.CUBE,
                MedianFilter3d.SearchMode searchMode = ImageDev.MedianFilter3d.SearchMode.AUTOMATIC,
                IOLink.ImageView outputImage = null );

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 cube structuring element always has an odd side length (3x3x3, 5x5x5, etc.) which is defined by twice the kernel radius + 1. UInt32 >=1 3
input
searchMode
Handles all types of methods for finding the median.
AUTOMATIC The algorithm automatically chooses the method to find the median value.
HISTOGRAM The algorithm uses a histogram to find the median value.
SELECTION The algorithm uses a shoting by selection to find the median value.
Enumeration AUTOMATIC
input
kernelMode
The structuring element shape and application mode.
CUBE This mode considers a cube structuring element of side length 2 x kernelRadius + 1 voxels.
BALL This mode considers a sphere structuring element of diameter 2 x kernelRadius + 1 voxels.
Enumeration CUBE
output
outputImage
The output image. Its dimensions and type are forced to the same values as the input. Image nullptr
Parameter Name Description Type Supported Values Default Value
input
input_image
The input image. image Binary, Label, Grayscale or Multispectral None
input
kernel_radius
The half size of the structuring element. A cube structuring element always has an odd side length (3x3x3, 5x5x5, etc.) which is defined by twice the kernel radius + 1. uint32 >=1 3
input
search_mode
Handles all types of methods for finding the median.
AUTOMATIC The algorithm automatically chooses the method to find the median value.
HISTOGRAM The algorithm uses a histogram to find the median value.
SELECTION The algorithm uses a shoting by selection to find the median value.
enumeration AUTOMATIC
input
kernel_mode
The structuring element shape and application mode.
CUBE This mode considers a cube structuring element of side length 2 x kernelRadius + 1 voxels.
BALL This mode considers a sphere structuring element of diameter 2 x kernelRadius + 1 voxels.
enumeration CUBE
output
output_image
The output image. Its dimensions and type are forced to the same values as the input. image None
Parameter Name Description Type Supported Values Default Value
input
inputImage
The input image. Image Binary, Label, Grayscale or Multispectral null
input
kernelRadius
The half size of the structuring element. A cube structuring element always has an odd side length (3x3x3, 5x5x5, etc.) which is defined by twice the kernel radius + 1. UInt32 >=1 3
input
searchMode
Handles all types of methods for finding the median.
AUTOMATIC The algorithm automatically chooses the method to find the median value.
HISTOGRAM The algorithm uses a histogram to find the median value.
SELECTION The algorithm uses a shoting by selection to find the median value.
Enumeration AUTOMATIC
input
kernelMode
The structuring element shape and application mode.
CUBE This mode considers a cube structuring element of side length 2 x kernelRadius + 1 voxels.
BALL This mode considers a sphere structuring element of diameter 2 x kernelRadius + 1 voxels.
Enumeration CUBE
output
outputImage
The output image. Its dimensions and type are forced to the same values as the input. Image null

Object Examples

auto foam = readVipImage( std::string( IMAGEDEVDATA_IMAGES_FOLDER ) + "foam.vip" );

MedianFilter3d medianFilter3dAlgo;
medianFilter3dAlgo.setInputImage( foam );
medianFilter3dAlgo.setKernelRadius( 3 );
medianFilter3dAlgo.setKernelMode( MedianFilter3d::KernelMode::CUBE );
medianFilter3dAlgo.setSearchMode( MedianFilter3d::SearchMode::AUTOMATIC );
medianFilter3dAlgo.execute();

std::cout << "outputImage:" << medianFilter3dAlgo.outputImage()->toString();
foam = imagedev.read_vip_image(imagedev_data.get_image_path("foam.vip"))

median_filter_3d_algo = imagedev.MedianFilter3d()
median_filter_3d_algo.input_image = foam
median_filter_3d_algo.kernel_radius = 3
median_filter_3d_algo.kernel_mode = imagedev.MedianFilter3d.CUBE
median_filter_3d_algo.search_mode = imagedev.MedianFilter3d.AUTOMATIC
median_filter_3d_algo.execute()

print("output_image:", str(median_filter_3d_algo.output_image))
ImageView foam = Data.ReadVipImage( @"Data/images/foam.vip" );

MedianFilter3d medianFilter3dAlgo = new MedianFilter3d
{
    inputImage = foam,
    kernelRadius = 3,
    kernelMode = MedianFilter3d.KernelMode.CUBE,
    searchMode = MedianFilter3d.SearchMode.AUTOMATIC
};
medianFilter3dAlgo.Execute();

Console.WriteLine( "outputImage:" + medianFilter3dAlgo.outputImage.ToString() );

Function Examples

auto foam = readVipImage( std::string( IMAGEDEVDATA_IMAGES_FOLDER ) + "foam.vip" );

auto result = medianFilter3d( foam, 3, MedianFilter3d::KernelMode::CUBE, MedianFilter3d::SearchMode::AUTOMATIC );

std::cout << "outputImage:" << result->toString();
foam = imagedev.read_vip_image(imagedev_data.get_image_path("foam.vip"))

result = imagedev.median_filter_3d(foam, 3, imagedev.MedianFilter3d.CUBE, imagedev.MedianFilter3d.AUTOMATIC)

print("output_image:", str(result))
ImageView foam = Data.ReadVipImage( @"Data/images/foam.vip" );

IOLink.ImageView result = Processing.MedianFilter3d( foam, 3, MedianFilter3d.KernelMode.CUBE, MedianFilter3d.SearchMode.AUTOMATIC );

Console.WriteLine( "outputImage:" + result.ToString() );