ImageDev

OnnxPredictionSegmentation3d

Computes a prediction on a three-dimensional image from an ONNX model and applies a post processing to generate a label or a binary image.

Access to parameter description

For an introduction, please refer to the Deep Learning section.

The following steps are applied: If the prediction output contains only one channel, the prediction score normalized between 0 and 1 is thresholded. The scores lower than 0.5 are considered as background and set to 0. Other scores are set to 1. The output image has the binary interpretation in this case.

If the prediction output contains two channels or more, the channel index presenting the highest score is assigned to each pixel of the output image. The first class, represented in the channel of index 0, is considered as background. The output image has the label interpretation in this case.



Figure 1. Segmentation by deep learning prediction with a model trained with the Avizo software.


See also

Function Syntax

This function returns outputObjectImage.
// Function prototype
std::shared_ptr< iolink::ImageView > onnxPredictionSegmentation3d( std::shared_ptr< iolink::ImageView > inputImage, std::string modelPath, OnnxPredictionSegmentation3d::DataFormat dataFormat, OnnxPredictionSegmentation3d::InputNormalizationType inputNormalizationType, iolink::Vector2d normalizationRange, OnnxPredictionSegmentation3d::NormalizationScope normalizationScope, iolink::Vector3u32 tileSize, uint32_t tileOverlap, std::shared_ptr< iolink::ImageView > outputObjectImage = nullptr );
This function returns outputObjectImage.
// Function prototype.
onnx_prediction_segmentation_3d(input_image: idt.ImageType,
                                model_path: str = "",
                                data_format: OnnxPredictionSegmentation3d.DataFormat = OnnxPredictionSegmentation3d.DataFormat.NDHWC,
                                input_normalization_type: OnnxPredictionSegmentation3d.InputNormalizationType = OnnxPredictionSegmentation3d.InputNormalizationType.STANDARDIZATION,
                                normalization_range: Union[Iterable[int], Iterable[float]] = [0, 1],
                                normalization_scope: OnnxPredictionSegmentation3d.NormalizationScope = OnnxPredictionSegmentation3d.NormalizationScope.GLOBAL,
                                tile_size: Iterable[int] = [128, 128, 128],
                                tile_overlap: int = 16,
                                output_object_image: idt.ImageType = None) -> idt.ImageType
This function returns outputObjectImage.
// Function prototype.
public static IOLink.ImageView
OnnxPredictionSegmentation3d( IOLink.ImageView inputImage,
                              String modelPath = "",
                              OnnxPredictionSegmentation3d.DataFormat dataFormat = ImageDev.OnnxPredictionSegmentation3d.DataFormat.NDHWC,
                              OnnxPredictionSegmentation3d.InputNormalizationType inputNormalizationType = ImageDev.OnnxPredictionSegmentation3d.InputNormalizationType.STANDARDIZATION,
                              double[] normalizationRange = null,
                              OnnxPredictionSegmentation3d.NormalizationScope normalizationScope = ImageDev.OnnxPredictionSegmentation3d.NormalizationScope.GLOBAL,
                              uint[] tileSize = null,
                              UInt32 tileOverlap = 16,
                              IOLink.ImageView outputObjectImage = null );

Class Syntax

Parameters

Parameter Name Description Type Supported Values Default Value
input
inputImage
The input image. It can be a grayscale or color image, depending on the selected model. Image Binary, Label, Grayscale or Multispectral nullptr
input
modelPath
The path to the ONNX model file. String ""
input
dataFormat
The tensor layout expected as input by the model. The input image is automatically converted to this layout by the algorithm.
NDHWC The layout is organized with interlaced channels. For instance, if the input is a color image, each pixel presents its RGB components successively.
NCDHW The layout is organized with separate channels. Each channel is an individual plan.
Enumeration NDHWC
input
inputNormalizationType
The type of normalization to apply before computing the prediction. It is recommended to apply the same pre-processing as during the training.
NONE No normalization is applied before executing the prediction.
STANDARDIZATION A normalization is applied by subtracting the mean and dividing by the standard deviation.
MIN_MAX A normalization is applied by subtracting the minimum and dividing by data range.
Enumeration STANDARDIZATION
input
normalizationRange
The data range in which the input image is normalized before computing the prediction. It is recommended to apply the same pre-processing as during the training. This parameter is ignored if the normalization type is set to NONE. Vector2d Any value {0.f, 1.f}
input
normalizationScope
The scope for computing normalization (mean, standard deviation, minimum or maximum). This parameter is ignored if the normalization type is set to NONE.
GLOBAL The normalization is applied globally on the input batch.
PER_VOLUME The normalization is applied individually on each image of the input batch.
Enumeration GLOBAL
input
tileSize
The width, height, and depth in pixels of the sliding window. This size includes the user defined tile overlap. It must be a multiple of 2 to the power of the number of downsampling or upsampling layers.
Guidelines to select an appropriate tile size are available in the Tiling section.
Vector3u32 != 0 {128, 128, 128}
input
tileOverlap
The number of pixels used as overlap between the tiles. An overlap of zero may lead to artifacts in the prediction result. A non-zero overlap reduces such artifacts but increases the computation time. UInt32 Any value 16
output
outputObjectImage
The output image. Its dimensions, and calibration are forced to the same values as the input. Its interpretation is binary if the model produces one channel, label otherwise. Image nullptr
Parameter Name Description Type Supported Values Default Value
input
input_image
The input image. It can be a grayscale or color image, depending on the selected model. image Binary, Label, Grayscale or Multispectral None
input
model_path
The path to the ONNX model file. string ""
input
data_format
The tensor layout expected as input by the model. The input image is automatically converted to this layout by the algorithm.
NDHWC The layout is organized with interlaced channels. For instance, if the input is a color image, each pixel presents its RGB components successively.
NCDHW The layout is organized with separate channels. Each channel is an individual plan.
enumeration NDHWC
input
input_normalization_type
The type of normalization to apply before computing the prediction. It is recommended to apply the same pre-processing as during the training.
NONE No normalization is applied before executing the prediction.
STANDARDIZATION A normalization is applied by subtracting the mean and dividing by the standard deviation.
MIN_MAX A normalization is applied by subtracting the minimum and dividing by data range.
enumeration STANDARDIZATION
input
normalization_range
The data range in which the input image is normalized before computing the prediction. It is recommended to apply the same pre-processing as during the training. This parameter is ignored if the normalization type is set to NONE. vector2d Any value [0, 1]
input
normalization_scope
The scope for computing normalization (mean, standard deviation, minimum or maximum). This parameter is ignored if the normalization type is set to NONE.
GLOBAL The normalization is applied globally on the input batch.
PER_VOLUME The normalization is applied individually on each image of the input batch.
enumeration GLOBAL
input
tile_size
The width, height, and depth in pixels of the sliding window. This size includes the user defined tile overlap. It must be a multiple of 2 to the power of the number of downsampling or upsampling layers.
Guidelines to select an appropriate tile size are available in the Tiling section.
vector3u32 != 0 [128, 128, 128]
input
tile_overlap
The number of pixels used as overlap between the tiles. An overlap of zero may lead to artifacts in the prediction result. A non-zero overlap reduces such artifacts but increases the computation time. uint32 Any value 16
output
output_object_image
The output image. Its dimensions, and calibration are forced to the same values as the input. Its interpretation is binary if the model produces one channel, label otherwise. image None
Parameter Name Description Type Supported Values Default Value
input
inputImage
The input image. It can be a grayscale or color image, depending on the selected model. Image Binary, Label, Grayscale or Multispectral null
input
modelPath
The path to the ONNX model file. String ""
input
dataFormat
The tensor layout expected as input by the model. The input image is automatically converted to this layout by the algorithm.
NDHWC The layout is organized with interlaced channels. For instance, if the input is a color image, each pixel presents its RGB components successively.
NCDHW The layout is organized with separate channels. Each channel is an individual plan.
Enumeration NDHWC
input
inputNormalizationType
The type of normalization to apply before computing the prediction. It is recommended to apply the same pre-processing as during the training.
NONE No normalization is applied before executing the prediction.
STANDARDIZATION A normalization is applied by subtracting the mean and dividing by the standard deviation.
MIN_MAX A normalization is applied by subtracting the minimum and dividing by data range.
Enumeration STANDARDIZATION
input
normalizationRange
The data range in which the input image is normalized before computing the prediction. It is recommended to apply the same pre-processing as during the training. This parameter is ignored if the normalization type is set to NONE. Vector2d Any value {0f, 1f}
input
normalizationScope
The scope for computing normalization (mean, standard deviation, minimum or maximum). This parameter is ignored if the normalization type is set to NONE.
GLOBAL The normalization is applied globally on the input batch.
PER_VOLUME The normalization is applied individually on each image of the input batch.
Enumeration GLOBAL
input
tileSize
The width, height, and depth in pixels of the sliding window. This size includes the user defined tile overlap. It must be a multiple of 2 to the power of the number of downsampling or upsampling layers.
Guidelines to select an appropriate tile size are available in the Tiling section.
Vector3u32 != 0 {128, 128, 128}
input
tileOverlap
The number of pixels used as overlap between the tiles. An overlap of zero may lead to artifacts in the prediction result. A non-zero overlap reduces such artifacts but increases the computation time. UInt32 Any value 16
output
outputObjectImage
The output image. Its dimensions, and calibration are forced to the same values as the input. Its interpretation is binary if the model produces one channel, label otherwise. Image null

Object Examples

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

OnnxPredictionSegmentation3d onnxPredictionSegmentation3dAlgo;
onnxPredictionSegmentation3dAlgo.setInputImage( chocolate_bar );
onnxPredictionSegmentation3dAlgo.setModelPath( std::string( IMAGEDEVDATA_OBJECTS_FOLDER ) + "segmentation3d.onnx" );
onnxPredictionSegmentation3dAlgo.setDataFormat( OnnxPredictionSegmentation3d::DataFormat::NDHWC );
onnxPredictionSegmentation3dAlgo.setInputNormalizationType( OnnxPredictionSegmentation3d::InputNormalizationType::NONE );
onnxPredictionSegmentation3dAlgo.setNormalizationRange( {0, 1} );
onnxPredictionSegmentation3dAlgo.setNormalizationScope( OnnxPredictionSegmentation3d::NormalizationScope::GLOBAL );
onnxPredictionSegmentation3dAlgo.setTileSize( {128, 128, 128} );
onnxPredictionSegmentation3dAlgo.setTileOverlap( 16 );
onnxPredictionSegmentation3dAlgo.execute();

std::cout << "outputObjectImage:" << onnxPredictionSegmentation3dAlgo.outputObjectImage()->toString();
chocolate_bar = imagedev.read_vip_image(imagedev_data.get_image_path("chocolate_bar.vip"))

onnx_prediction_segmentation_3d_algo = imagedev.OnnxPredictionSegmentation3d()
onnx_prediction_segmentation_3d_algo.input_image = chocolate_bar
onnx_prediction_segmentation_3d_algo.model_path = imagedev_data.get_object_path("segmentation3d.onnx")
onnx_prediction_segmentation_3d_algo.data_format = imagedev.OnnxPredictionSegmentation3d.NDHWC
onnx_prediction_segmentation_3d_algo.input_normalization_type = imagedev.OnnxPredictionSegmentation3d.NONE
onnx_prediction_segmentation_3d_algo.normalization_range = [0, 1]
onnx_prediction_segmentation_3d_algo.normalization_scope = imagedev.OnnxPredictionSegmentation3d.GLOBAL
onnx_prediction_segmentation_3d_algo.tile_size = [128, 128, 128]
onnx_prediction_segmentation_3d_algo.tile_overlap = 16
onnx_prediction_segmentation_3d_algo.execute()

print("output_object_image:", str(onnx_prediction_segmentation_3d_algo.output_object_image))
ImageView chocolate_bar = Data.ReadVipImage( @"Data/images/chocolate_bar.vip" );

OnnxPredictionSegmentation3d onnxPredictionSegmentation3dAlgo = new OnnxPredictionSegmentation3d
{
    inputImage = chocolate_bar,
    modelPath = @"Data/objects/segmentation3d.onnx",
    dataFormat = OnnxPredictionSegmentation3d.DataFormat.NDHWC,
    inputNormalizationType = OnnxPredictionSegmentation3d.InputNormalizationType.NONE,
    normalizationRange = new double[]{0, 1},
    normalizationScope = OnnxPredictionSegmentation3d.NormalizationScope.GLOBAL,
    tileSize = new uint[]{128, 128, 128},
    tileOverlap = 16
};
onnxPredictionSegmentation3dAlgo.Execute();

Console.WriteLine( "outputObjectImage:" + onnxPredictionSegmentation3dAlgo.outputObjectImage.ToString() );

Function Examples

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

auto result = onnxPredictionSegmentation3d( chocolate_bar, std::string( IMAGEDEVDATA_OBJECTS_FOLDER ) + "segmentation3d.onnx", OnnxPredictionSegmentation3d::DataFormat::NDHWC, OnnxPredictionSegmentation3d::InputNormalizationType::NONE, {0, 1}, OnnxPredictionSegmentation3d::NormalizationScope::GLOBAL, {128, 128, 128}, 16 );

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

result = imagedev.onnx_prediction_segmentation_3d(chocolate_bar, imagedev_data.get_object_path("segmentation3d.onnx"), imagedev.OnnxPredictionSegmentation3d.NDHWC, imagedev.OnnxPredictionSegmentation3d.NONE, [0, 1], imagedev.OnnxPredictionSegmentation3d.GLOBAL, [128, 128, 128], 16)

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

IOLink.ImageView result = Processing.OnnxPredictionSegmentation3d( chocolate_bar, @"Data/objects/segmentation3d.onnx", OnnxPredictionSegmentation3d.DataFormat.NDHWC, OnnxPredictionSegmentation3d.InputNormalizationType.NONE, new double[]{0, 1}, OnnxPredictionSegmentation3d.NormalizationScope.GLOBAL, new uint[]{128, 128, 128}, 16 );

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