ImageDev

OnnxPredictionFiltering2d

Computes a prediction on a two-dimensional image from an ONNX model and generates an image representing the prediction scores.

Access to parameter description

For an overview, please refer to the Deep Learning section.
This algorithm produces an image containing the raw prediction scores given by the model. Depending on how the model has been trained, it can be used either to perform image filtering, or segmentation by applying an appropriate post-processing step afterwards.

The following steps are applied:
<b>Figure 1.</b> Membrane segmentation by deep learning prediction with noise to noise model.
Figure 1. Membrane segmentation by deep learning prediction with noise to noise model.


See also

Function Syntax

This function returns outputImage.
// Function prototype
std::shared_ptr< iolink::ImageView > onnxPredictionFiltering2d( std::shared_ptr< iolink::ImageView > inputImage, std::string modelPath, OnnxPredictionFiltering2d::DataFormat dataFormat, OnnxPredictionFiltering2d::InputNormalizationType inputNormalizationType, iolink::Vector2d normalizationRange, OnnxPredictionFiltering2d::NormalizationScope normalizationScope, iolink::Vector2u32 tileSize, uint32_t tileOverlap, OnnxPredictionFiltering2d::OutputNormalizationType outputNormalizationType, OnnxPredictionFiltering2d::OutputType outputType, std::shared_ptr< iolink::ImageView > outputImage = NULL );
This function returns outputImage.
// Function prototype.
onnx_prediction_filtering_2d( input_image,
                              model_path = "",
                              data_format = OnnxPredictionFiltering2d.DataFormat.NHWC,
                              input_normalization_type = OnnxPredictionFiltering2d.InputNormalizationType.STANDARDIZATION,
                              normalization_range = [0, 1],
                              normalization_scope = OnnxPredictionFiltering2d.NormalizationScope.GLOBAL,
                              tile_size = [256, 256],
                              tile_overlap = 32,
                              output_normalization_type = OnnxPredictionFiltering2d.OutputNormalizationType.NONE,
                              output_type = OnnxPredictionFiltering2d.OutputType.SAME_AS_INPUT,
                              output_image = None )
This function returns outputImage.
// Function prototype.
public static IOLink.ImageView
OnnxPredictionFiltering2d( IOLink.ImageView inputImage,
                           String modelPath = "",
                           OnnxPredictionFiltering2d.DataFormat dataFormat = ImageDev.OnnxPredictionFiltering2d.DataFormat.NHWC,
                           OnnxPredictionFiltering2d.InputNormalizationType inputNormalizationType = ImageDev.OnnxPredictionFiltering2d.InputNormalizationType.STANDARDIZATION,
                           double[] normalizationRange = null,
                           OnnxPredictionFiltering2d.NormalizationScope normalizationScope = ImageDev.OnnxPredictionFiltering2d.NormalizationScope.GLOBAL,
                           uint[] tileSize = null,
                           UInt32 tileOverlap = 32,
                           OnnxPredictionFiltering2d.OutputNormalizationType outputNormalizationType = ImageDev.OnnxPredictionFiltering2d.OutputNormalizationType.NONE,
                           OnnxPredictionFiltering2d.OutputType outputType = ImageDev.OnnxPredictionFiltering2d.OutputType.SAME_AS_INPUT,
                           IOLink.ImageView outputImage = null );

Class Syntax

Parameters

Class Name OnnxPredictionFiltering2d

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.
NHWC The layout is organized with interlaced channels. For instance, if the input is a color image, each pixel presents its RGB components successively.
NCHW The layout is organized with separate channels. Each channel is an individual plan.
Enumeration NHWC
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_SLICE The normalization is applied individually on each image of the input batch.
Enumeration GLOBAL
input
tileSize
The width and height in pixels of the sliding window. This size includes the user defined tile overlap. Vector2u32 Any value {256, 256}
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 32
input
outputNormalizationType
The type of normalization to apply after computing the prediction. This parameter is ignored if the input normalization type is set to none.
NONE No normalization is applied on the output image.
INVERSE The inverse operation is applied to set the output image in the same range as the input.
Enumeration NONE
input
outputType
The output data type. It can either be the same as the input type or forced to float. This parameter is ignored if the input normalization type is set to none.
SAME_AS_INPUT The output image has the same type as the input image.
FLOAT_32_BIT The output image type is forced to floating point.
Enumeration SAME_AS_INPUT
output
outputImage
The output image. Dimensions, and calibration of the output image are forced to the same values as the input. Its number of channels depends on the selected model. Its type depends on the selected output type. Image nullptr

Object Examples

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

OnnxPredictionFiltering2d onnxPredictionFiltering2dAlgo;
onnxPredictionFiltering2dAlgo.setInputImage( autorad );
onnxPredictionFiltering2dAlgo.setModelPath( std::string( IMAGEDEVDATA_OBJECTS_FOLDER ) + "noise2noise.onnx" );
onnxPredictionFiltering2dAlgo.setDataFormat( OnnxPredictionFiltering2d::DataFormat::NHWC );
onnxPredictionFiltering2dAlgo.setInputNormalizationType( OnnxPredictionFiltering2d::InputNormalizationType::NONE );
onnxPredictionFiltering2dAlgo.setNormalizationRange( {0, 1} );
onnxPredictionFiltering2dAlgo.setNormalizationScope( OnnxPredictionFiltering2d::NormalizationScope::GLOBAL );
onnxPredictionFiltering2dAlgo.setTileSize( {128, 128} );
onnxPredictionFiltering2dAlgo.setTileOverlap( 32 );
onnxPredictionFiltering2dAlgo.setOutputNormalizationType( OnnxPredictionFiltering2d::OutputNormalizationType::NONE );
onnxPredictionFiltering2dAlgo.setOutputType( OnnxPredictionFiltering2d::OutputType::SAME_AS_INPUT );
onnxPredictionFiltering2dAlgo.execute();

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

onnx_prediction_filtering_2d_algo = imagedev.OnnxPredictionFiltering2d()
onnx_prediction_filtering_2d_algo.input_image = autorad
onnx_prediction_filtering_2d_algo.model_path = imagedev_data.get_object_path("noise2noise.onnx")
onnx_prediction_filtering_2d_algo.data_format = imagedev.OnnxPredictionFiltering2d.NHWC
onnx_prediction_filtering_2d_algo.input_normalization_type = imagedev.OnnxPredictionFiltering2d.InputNormalizationType.NONE
onnx_prediction_filtering_2d_algo.normalization_range = [0, 1]
onnx_prediction_filtering_2d_algo.normalization_scope = imagedev.OnnxPredictionFiltering2d.GLOBAL
onnx_prediction_filtering_2d_algo.tile_size = [128, 128]
onnx_prediction_filtering_2d_algo.tile_overlap = 32
onnx_prediction_filtering_2d_algo.output_normalization_type = imagedev.OnnxPredictionFiltering2d.OutputNormalizationType.NONE
onnx_prediction_filtering_2d_algo.output_type = imagedev.OnnxPredictionFiltering2d.SAME_AS_INPUT
onnx_prediction_filtering_2d_algo.execute()

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

OnnxPredictionFiltering2d onnxPredictionFiltering2dAlgo = new OnnxPredictionFiltering2d
{
    inputImage = autorad,
    modelPath = @"Data/objects/noise2noise.onnx",
    dataFormat = OnnxPredictionFiltering2d.DataFormat.NHWC,
    inputNormalizationType = OnnxPredictionFiltering2d.InputNormalizationType.NONE,
    normalizationRange = new double[]{0, 1},
    normalizationScope = OnnxPredictionFiltering2d.NormalizationScope.GLOBAL,
    tileSize = new uint[]{128, 128},
    tileOverlap = 32,
    outputNormalizationType = OnnxPredictionFiltering2d.OutputNormalizationType.NONE,
    outputType = OnnxPredictionFiltering2d.OutputType.SAME_AS_INPUT
};
onnxPredictionFiltering2dAlgo.Execute();

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

Function Examples

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

auto result = onnxPredictionFiltering2d( autorad, std::string( IMAGEDEVDATA_OBJECTS_FOLDER ) + "noise2noise.onnx", OnnxPredictionFiltering2d::DataFormat::NHWC, OnnxPredictionFiltering2d::InputNormalizationType::NONE, {0, 1}, OnnxPredictionFiltering2d::NormalizationScope::GLOBAL, {128, 128}, 32, OnnxPredictionFiltering2d::OutputNormalizationType::NONE, OnnxPredictionFiltering2d::OutputType::SAME_AS_INPUT );

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

result = imagedev.onnx_prediction_filtering_2d( autorad, imagedev_data.get_object_path("noise2noise.onnx"), imagedev.OnnxPredictionFiltering2d.NHWC, imagedev.OnnxPredictionFiltering2d.InputNormalizationType.NONE, [0, 1], imagedev.OnnxPredictionFiltering2d.GLOBAL, [128, 128], 32, imagedev.OnnxPredictionFiltering2d.OutputNormalizationType.NONE, imagedev.OnnxPredictionFiltering2d.SAME_AS_INPUT )

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

IOLink.ImageView result = Processing.OnnxPredictionFiltering2d( autorad, @"Data/objects/noise2noise.onnx", OnnxPredictionFiltering2d.DataFormat.NHWC, OnnxPredictionFiltering2d.InputNormalizationType.NONE, new double[]{0, 1}, OnnxPredictionFiltering2d.NormalizationScope.GLOBAL, new uint[]{128, 128}, 32, OnnxPredictionFiltering2d.OutputNormalizationType.NONE, OnnxPredictionFiltering2d.OutputType.SAME_AS_INPUT );

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