ImageDev

CudaDilation2d

Performs a two-dimensional dilation using a structuring element matching with a square or a cross. 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: The dilation is performed by an iterative method in which each step dilates the result of the previous step. The kernelRadius parameter tunes the number of iterations, which sets the kernel size.
This algorithm uses a basic structuring element with either 8 neighbors, or 4 neighbors, according to the neighborhood parameter.

<b> Figure 1.</b> Structuring elements
Figure 1. Structuring elements
See also

Function Syntax

This function returns outputImage.
// Function prototype
std::shared_ptr< iolink::ImageView > cudaDilation2d( std::shared_ptr< iolink::ImageView > inputImage, uint32_t kernelRadius, CudaDilation2d::Neighborhood neighborhood, CudaDilation2d::TilingMode tilingMode, iolink::Vector2u32 tileSize, CudaContext::Ptr cudaContext, std::shared_ptr< iolink::ImageView > outputImage = nullptr );
This function returns outputImage.
// Function prototype.
cuda_dilation_2d(input_image: idt.ImageType,
                 kernel_radius: int = 3,
                 neighborhood: CudaDilation2d.Neighborhood = CudaDilation2d.Neighborhood.CONNECTIVITY_8,
                 tiling_mode: CudaDilation2d.TilingMode = CudaDilation2d.TilingMode.NONE,
                 tile_size: Iterable[int] = [1024, 1024],
                 cuda_context: Union[CudaContext, None] = None,
                 output_image: idt.ImageType = None) -> idt.ImageType
This function returns outputImage.
// Function prototype.
public static IOLink.ImageView
CudaDilation2d( IOLink.ImageView inputImage,
                UInt32 kernelRadius = 3,
                CudaDilation2d.Neighborhood neighborhood = ImageDev.CudaDilation2d.Neighborhood.CONNECTIVITY_8,
                CudaDilation2d.TilingMode tilingMode = ImageDev.CudaDilation2d.TilingMode.NONE,
                uint[] tileSize = null,
                Data.CudaContext cudaContext = null,
                IOLink.ImageView outputImage = null );

Class Syntax

Parameters

Parameter Name Description Type Supported Values Default Value
input
inputImage
The input image. The image type can be integer or float. Image Binary, Label, Grayscale or Multispectral nullptr
input
kernelRadius
The number of iterations (the half size of the structuring element, in pixels). A square structuring element always has an odd side length (3x3, 5x5, etc.) which is defined by twice the kernel radius + 1. UInt32 >=1 3
input
neighborhood
The 2D neighborhood configuration.
CONNECTIVITY_4 The structuring element is a cross.
CONNECTIVITY_8 The structuring element is a square.
Enumeration CONNECTIVITY_8
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 >=3 {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. Image nullptr
Parameter Name Description Type Supported Values Default Value
input
input_image
The input image. The image type can be integer or float. image Binary, Label, Grayscale or Multispectral None
input
kernel_radius
The number of iterations (the half size of the structuring element, in pixels). A square structuring element always has an odd side length (3x3, 5x5, etc.) which is defined by twice the kernel radius + 1. uint32 >=1 3
input
neighborhood
The 2D neighborhood configuration.
CONNECTIVITY_4 The structuring element is a cross.
CONNECTIVITY_8 The structuring element is a square.
enumeration CONNECTIVITY_8
input
tiling_mode
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
tile_size
The tile width and height in pixels. This parameter is used only in USER_DEFINED tiling mode. vector2u32 >=3 [1024, 1024]
input
cuda_context
CUDA context information. cuda_context None
output
output_image
The output image. Its dimensions and type are forced to the same values as the input image. image None
Parameter Name Description Type Supported Values Default Value
input
inputImage
The input image. The image type can be integer or float. Image Binary, Label, Grayscale or Multispectral null
input
kernelRadius
The number of iterations (the half size of the structuring element, in pixels). A square structuring element always has an odd side length (3x3, 5x5, etc.) which is defined by twice the kernel radius + 1. UInt32 >=1 3
input
neighborhood
The 2D neighborhood configuration.
CONNECTIVITY_4 The structuring element is a cross.
CONNECTIVITY_8 The structuring element is a square.
Enumeration CONNECTIVITY_8
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 >=3 {1024, 1024}
input
cudaContext
CUDA context information. CudaContext null
output
outputImage
The output image. Its dimensions and type are forced to the same values as the input image. Image null

Object Examples

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

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

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

cuda_dilation_2d_algo = imagedev.CudaDilation2d()
cuda_dilation_2d_algo.input_image = polystyrene
cuda_dilation_2d_algo.kernel_radius = 3
cuda_dilation_2d_algo.neighborhood = imagedev.CudaDilation2d.CONNECTIVITY_8
cuda_dilation_2d_algo.tiling_mode = imagedev.CudaDilation2d.NONE
cuda_dilation_2d_algo.tile_size = [264, 264]
cuda_dilation_2d_algo.cuda_context = None
cuda_dilation_2d_algo.execute()

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

CudaDilation2d cudaDilation2dAlgo = new CudaDilation2d
{
    inputImage = polystyrene,
    kernelRadius = 3,
    neighborhood = CudaDilation2d.Neighborhood.CONNECTIVITY_8,
    tilingMode = CudaDilation2d.TilingMode.NONE,
    tileSize = new uint[]{264, 264},
    cudaContext = null
};
cudaDilation2dAlgo.Execute();

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

Function Examples

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

auto result = cudaDilation2d( polystyrene, 3, CudaDilation2d::Neighborhood::CONNECTIVITY_8, CudaDilation2d::TilingMode::NONE, {264, 264}, nullptr , iolink::ImageViewFactory::allocate( iolink::VectorXu64( { 1, 1 } ), iolink::DataTypeId::UINT8 ));

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

result = imagedev.cuda_dilation_2d(polystyrene, 3, imagedev.CudaDilation2d.CONNECTIVITY_8, imagedev.CudaDilation2d.NONE, [264, 264], None)

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

IOLink.ImageView result = Processing.CudaDilation2d( polystyrene, 3, CudaDilation2d.Neighborhood.CONNECTIVITY_8, CudaDilation2d.TilingMode.NONE, new uint[]{264, 264}, null );

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