ImageDev

BoxFilter2d

Smooths an image using a box kernel.

Access to parameter description

For an introduction to image filters: section Images Filtering.

This algorithm smooths an image using the same box kernel as a lowpass filter. The filter's X and Y sizes are user-defined.

The algorithm calculates the local mean in a given size window. For a window of size $2p+1$ in X and $2q+1$ in Y: $$ O(n,m)=\frac{1}{K}\sum_{i=-p}^{p}\sum_{j=-q}^{q} I(n-i,m-j) $$ The $K$ coefficient is a normalization factor: Note: If the result is normalized, the output image has same type as the input. Else, it is upgraded according to the Image type promotion rule.

See also
See related example

Function Syntax

This function returns outputImage.
// Function prototype
std::shared_ptr< iolink::ImageView > boxFilter2d( std::shared_ptr< iolink::ImageView > inputImage, int32_t kernelSizeX, int32_t kernelSizeY, BoxFilter2d::AutoScale autoScale, std::shared_ptr< iolink::ImageView > outputImage = NULL );
This function returns outputImage.
// Function prototype.
box_filter_2d( input_image,
               kernel_size_x = 3,
               kernel_size_y = 3,
               auto_scale = BoxFilter2d.AutoScale.YES,
               output_image = None )
This function returns outputImage.
// Function prototype.
public static IOLink.ImageView
BoxFilter2d( IOLink.ImageView inputImage,
             Int32 kernelSizeX = 3,
             Int32 kernelSizeY = 3,
             BoxFilter2d.AutoScale autoScale = ImageDev.BoxFilter2d.AutoScale.YES,
             IOLink.ImageView outputImage = null );

Class Syntax

Parameters

Parameter Name Description Type Supported Values Default Value
input
kernelSizeX
The horizontal kernel size. Int32 >=1 3
input
kernelSizeY
The vertical kernel size. Int32 >=1 3
input
inputImage
The input image. Image Binary, Grayscale or Multispectral nullptr
input
autoScale
The automatic intensity scaling mode.
NO The result is not normalized; it corresponds to the sum of the window elements.
YES The result is automatically normalized by the number of elements of the kernel; it corresponds to the mean of the window elements.
Enumeration YES
output
outputImage
The output image. Its dimensions are forced to the same values as the input. Its type is the same as the input if the normalization is set to yes, else the type is upgraded. Image nullptr
Parameter Name Description Type Supported Values Default Value
input
kernel_size_x
The horizontal kernel size. int32 >=1 3
input
kernel_size_y
The vertical kernel size. int32 >=1 3
input
input_image
The input image. image Binary, Grayscale or Multispectral None
input
auto_scale
The automatic intensity scaling mode.
NO The result is not normalized; it corresponds to the sum of the window elements.
YES The result is automatically normalized by the number of elements of the kernel; it corresponds to the mean of the window elements.
enumeration YES
output
output_image
The output image. Its dimensions are forced to the same values as the input. Its type is the same as the input if the normalization is set to yes, else the type is upgraded. image None
Parameter Name Description Type Supported Values Default Value
input
kernelSizeX
The horizontal kernel size. Int32 >=1 3
input
kernelSizeY
The vertical kernel size. Int32 >=1 3
input
inputImage
The input image. Image Binary, Grayscale or Multispectral null
input
autoScale
The automatic intensity scaling mode.
NO The result is not normalized; it corresponds to the sum of the window elements.
YES The result is automatically normalized by the number of elements of the kernel; it corresponds to the mean of the window elements.
Enumeration YES
output
outputImage
The output image. Its dimensions are forced to the same values as the input. Its type is the same as the input if the normalization is set to yes, else the type is upgraded. Image null

Object Examples

std::shared_ptr< iolink::ImageView > polystyrene = ioformat::readImage( std::string( IMAGEDEVDATA_IMAGES_FOLDER ) + "polystyrene.tif" );

BoxFilter2d boxFilter2dAlgo;
boxFilter2dAlgo.setInputImage( polystyrene );
boxFilter2dAlgo.setKernelSizeX( 3 );
boxFilter2dAlgo.setKernelSizeY( 3 );
boxFilter2dAlgo.setAutoScale( BoxFilter2d::AutoScale::YES );
boxFilter2dAlgo.execute();

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

box_filter_2d_algo = imagedev.BoxFilter2d()
box_filter_2d_algo.input_image = polystyrene
box_filter_2d_algo.kernel_size_x = 3
box_filter_2d_algo.kernel_size_y = 3
box_filter_2d_algo.auto_scale = imagedev.BoxFilter2d.YES
box_filter_2d_algo.execute()

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

BoxFilter2d boxFilter2dAlgo = new BoxFilter2d
{
    inputImage = polystyrene,
    kernelSizeX = 3,
    kernelSizeY = 3,
    autoScale = BoxFilter2d.AutoScale.YES
};
boxFilter2dAlgo.Execute();

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

Function Examples

std::shared_ptr< iolink::ImageView > polystyrene = ioformat::readImage( std::string( IMAGEDEVDATA_IMAGES_FOLDER ) + "polystyrene.tif" );

auto result = boxFilter2d( polystyrene, 3, 3, BoxFilter2d::AutoScale::YES );

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

result = imagedev.box_filter_2d( polystyrene, 3, 3, imagedev.BoxFilter2d.YES )

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

IOLink.ImageView result = Processing.BoxFilter2d( polystyrene, 3, 3, BoxFilter2d.AutoScale.YES );

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