ImageDev

MajorityFilter2d

Replaces pixels of a two-dimensional image by the most represented value inside their neighborhood.

Access to parameter description

For an introduction to image filters: see Images Filtering.

This algorithm replaces pixels by the value that is most frequent within the filter kernel. If several values occur the same number of times, the module favors the original voxel value.

This algorithm can be especially useful for post-processing a label image, and thus correcting misclassifications of a segmentation process.

See also

Function Syntax

This function returns outputImage.
// Function prototype
std::shared_ptr< iolink::ImageView > majorityFilter2d( std::shared_ptr< iolink::ImageView > inputImage, int32_t kernelSizeX, int32_t kernelSizeY, std::shared_ptr< iolink::ImageView > outputImage = nullptr );
This function returns outputImage.
// Function prototype.
majority_filter_2d(input_image: idt.ImageType,
                   kernel_size_x: int = 3,
                   kernel_size_y: int = 3,
                   output_image: idt.ImageType = None) -> idt.ImageType
This function returns outputImage.
// Function prototype.
public static IOLink.ImageView
MajorityFilter2d( IOLink.ImageView inputImage,
                  Int32 kernelSizeX = 3,
                  Int32 kernelSizeY = 3,
                  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
kernelSizeX
The horizontal kernel size in pixels (odd value). Int32 [1, 100] 3
input
kernelSizeY
The vertical kernel size in pixels (odd value). Int32 [1, 100] 3
output
outputImage
The output image. Its dimensions, type, and calibration 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_size_x
The horizontal kernel size in pixels (odd value). int32 [1, 100] 3
input
kernel_size_y
The vertical kernel size in pixels (odd value). int32 [1, 100] 3
output
output_image
The output image. Its dimensions, type, and calibration 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
kernelSizeX
The horizontal kernel size in pixels (odd value). Int32 [1, 100] 3
input
kernelSizeY
The vertical kernel size in pixels (odd value). Int32 [1, 100] 3
output
outputImage
The output image. Its dimensions, type, and calibration are forced to the same values as the input. Image null

Object Examples

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

MajorityFilter2d majorityFilter2dAlgo;
majorityFilter2dAlgo.setInputImage( polystyrene );
majorityFilter2dAlgo.setKernelSizeX( 3 );
majorityFilter2dAlgo.setKernelSizeY( 3 );
majorityFilter2dAlgo.execute();

std::cout << "outputImage:" << majorityFilter2dAlgo.outputImage()->toString();
polystyrene = ioformat.read_image(imagedev_data.get_image_path("polystyrene.tif"))

majority_filter_2d_algo = imagedev.MajorityFilter2d()
majority_filter_2d_algo.input_image = polystyrene
majority_filter_2d_algo.kernel_size_x = 3
majority_filter_2d_algo.kernel_size_y = 3
majority_filter_2d_algo.execute()

print("output_image:", str(majority_filter_2d_algo.output_image))
ImageView polystyrene = ViewIO.ReadImage( @"Data/images/polystyrene.tif" );

MajorityFilter2d majorityFilter2dAlgo = new MajorityFilter2d
{
    inputImage = polystyrene,
    kernelSizeX = 3,
    kernelSizeY = 3
};
majorityFilter2dAlgo.Execute();

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

Function Examples

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

auto result = majorityFilter2d( polystyrene, 3, 3 );

std::cout << "outputImage:" << result->toString();
polystyrene = ioformat.read_image(imagedev_data.get_image_path("polystyrene.tif"))

result = imagedev.majority_filter_2d(polystyrene, 3, 3)

print("output_image:", str(result))
ImageView polystyrene = ViewIO.ReadImage( @"Data/images/polystyrene.tif" );

IOLink.ImageView result = Processing.MajorityFilter2d( polystyrene, 3, 3 );

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