ImageDev

BilateralFilter3d

Applies a three-dimensional edge-preserving smoothing filter.

Access to parameter description

For an introduction to image filters: see Images Filtering.

This algorithm is an edge-preserving smoothing filter. The intensity value at each voxel in an image is replaced by a weighted average of intensity values from nearby voxels. Crucially, the weights depend on the distance in color space from the considered voxel.
It preserves sharp edges by systematically excluding voxels across discontinuities from consideration: $$ O(i,j,k)=\frac{1}{K(i,j,k)}\sum_{l=-\frac{n_x}{2}}^{\frac{n_x}{2}}\sum_{m=-\frac{n_y}{2}}^{\frac{n_y}{2}} \sum_{n=-\frac{n_z}{2}}^{\frac{n_z}{2}} e^{_\frac{(I(i,j,k)-I(l,m,n))^2}{h^2}} I(l,m,n) $$
Where $h$ is a weighting similarity factor and $K$ is a local normalisation factor given by: $$ K(i,j,k)=\sum_{l=-\frac{n_x}{2}}^{\frac{n_x}{2}}\sum_{m=-\frac{n_y}{2}}^{\frac{n_y}{2}} \sum_{n=-\frac{n_z}{2}}^{\frac{n_z}{2}} e^{_\frac{(I(i,j,k)-I(l,m,n))^2}{h^2}} $$
The greater $h$ is, the stronger the blur.

A filter mode parameter that allows this algorithm to switch to the SUSAN filter (Smallest Univalue Segment Assimilating Nucleus).
The SUSAN filter reproduces bilateral filter behavior simply by excluding the central voxel from computation. This filter gives better results in the case of impulse noise.

Reference:
C.Tomasi, R.Manduchi. "Bilateral Filtering for Gray and Color Images". Sixth International Conference on Computer Vision (IEEE Cat. No.98CH36271), Bombay, India, pp. 839-846, 1998.

See also
See related example

Function Syntax

This function returns outputImage.
// Function prototype
std::shared_ptr< iolink::ImageView > bilateralFilter3d( std::shared_ptr< iolink::ImageView > inputImage, int32_t kernelSizeX, int32_t kernelSizeY, int32_t kernelSizeZ, double similarity, BilateralFilter3d::FilterMode filterMode, std::shared_ptr< iolink::ImageView > outputImage = NULL );
This function returns outputImage.
// Function prototype.
bilateral_filter_3d( input_image,
                     kernel_size_x = 3,
                     kernel_size_y = 3,
                     kernel_size_z = 3,
                     similarity = 20,
                     filter_mode = BilateralFilter3d.FilterMode.BILATERAL,
                     output_image = None )
This function returns outputImage.
// Function prototype.
public static IOLink.ImageView
BilateralFilter3d( IOLink.ImageView inputImage,
                   Int32 kernelSizeX = 3,
                   Int32 kernelSizeY = 3,
                   Int32 kernelSizeZ = 3,
                   double similarity = 20,
                   BilateralFilter3d.FilterMode filterMode = ImageDev.BilateralFilter3d.FilterMode.BILATERAL,
                   IOLink.ImageView outputImage = null );

Class Syntax

Parameters

Class Name BilateralFilter3d

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 voxels (odd value). Int32 [3, 100] 3
input
kernelSizeY
The vertical kernel size in voxels (odd value). Int32 [3, 100] 3
input
kernelSizeZ
The depth kernel size in voxels (odd value). Int32 [3, 100] 3
input
similarity
The weighting similarity factor (must be a positive value). Float64 >0 20
input
filterMode
The way to consider the central pixel.
BILATERAL This mode corresponds to the standard bilateral filter (uses the central point).
SUSAN This mode corresponds to the SUSAN filter (does not use the central point).
Enumeration BILATERAL
output
outputImage
The output image. Its dimensions, type, and calibration are forced to the same values as the input. Image nullptr

Object Examples

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

BilateralFilter3d bilateralFilter3dAlgo;
bilateralFilter3dAlgo.setInputImage( foam );
bilateralFilter3dAlgo.setKernelSizeX( 3 );
bilateralFilter3dAlgo.setKernelSizeY( 3 );
bilateralFilter3dAlgo.setKernelSizeZ( 3 );
bilateralFilter3dAlgo.setSimilarity( 20.0 );
bilateralFilter3dAlgo.setFilterMode( BilateralFilter3d::FilterMode::BILATERAL );
bilateralFilter3dAlgo.execute();

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

bilateral_filter_3d_algo = imagedev.BilateralFilter3d()
bilateral_filter_3d_algo.input_image = foam
bilateral_filter_3d_algo.kernel_size_x = 3
bilateral_filter_3d_algo.kernel_size_y = 3
bilateral_filter_3d_algo.kernel_size_z = 3
bilateral_filter_3d_algo.similarity = 20.0
bilateral_filter_3d_algo.filter_mode = imagedev.BilateralFilter3d.BILATERAL
bilateral_filter_3d_algo.execute()

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

BilateralFilter3d bilateralFilter3dAlgo = new BilateralFilter3d
{
    inputImage = foam,
    kernelSizeX = 3,
    kernelSizeY = 3,
    kernelSizeZ = 3,
    similarity = 20.0,
    filterMode = BilateralFilter3d.FilterMode.BILATERAL
};
bilateralFilter3dAlgo.Execute();

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

Function Examples

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

auto result = bilateralFilter3d( foam, 3, 3, 3, 20.0, BilateralFilter3d::FilterMode::BILATERAL );

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

result = imagedev.bilateral_filter_3d( foam, 3, 3, 3, 20.0, imagedev.BilateralFilter3d.BILATERAL )

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

IOLink.ImageView result = Processing.BilateralFilter3d( foam, 3, 3, 3, 20.0, BilateralFilter3d.FilterMode.BILATERAL );

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