DML_RESAMPLE3_OPERATOR_DESC structure (directml.h)

Resamples elements from the source to the destination tensor, using the scale factors to compute the destination tensor size. You can use a linear or nearest neighbor interpolation mode. The operator supports interpolation across multiple dimensions, not just 2D. So you can keep the same spatial size, but interpolate across channels or across batches. The relationship between the input and output coordinates is the following:

OutputTensorX = (InputTensorX + InputPixelOffset) * Scale + OutputPixelOffset

Important

This API is available as part of the DirectML standalone redistributable package (see Microsoft.AI.DirectML version 1.15.1 and later. Also see DirectML version history.

Syntax

struct DML_RESAMPLE3_OPERATOR_DESC
{
    const DML_TENSOR_DESC* InputTensor;
    const DML_TENSOR_DESC* OutputTensor;
    DML_INTERPOLATION_MODE InterpolationMode;
    DML_AXIS_DIRECTION RoundingDirection;
    UINT DimensionCount;
    _Field_size_(DimensionCount) const FLOAT* Scales;
    _Field_size_(DimensionCount) const FLOAT* InputPixelOffsets;
    _Field_size_(DimensionCount) const FLOAT* OutputPixelOffsets;
    BOOL Antialiased;
};

Members

InputTensor

Type: const DML_TENSOR_DESC*

The tensor containing the input data.

OutputTensor

Type: const DML_TENSOR_DESC*

The tensor to write the output data to.

InterpolationMode

Type: DML_INTERPOLATION_MODE

This field determines the kind of interpolation used to choose output pixels.

  • DML_INTERPOLATION_MODE_NEAREST_NEIGHBOR. Uses the nearest neighbor algorithm, which chooses the input element nearest to the corresponding pixel offset for each output element.

  • DML_INTERPOLATION_MODE_LINEAR. Uses the linear interpolation algorithm, which computes the output element by computing the weighted average of the two nearest neighboring input elements per dimension. Resampling is supported up to four dimensions (quadrilinear), where the weighted average is computed on a total of sixteen input elements for each output element.

RoundingDirection

Type: DML_AXIS_DIRECTION

The direction to round along each axis when mapping fractional coordinates back to input pixels. Since bilinear interpolation interpolates fractional coordinates anyway, this affects only DML_INTERPOLATION_MODE_NEAREST_NEIGHBOR.

  • DML_AXIS_DIRECTION_INCREASING. Round fractional coordinates toward increasing axis values (ceil).

  • DML_AXIS_DIRECTION_DECREASING. Round fractional coordinates toward decreasing axis values (floor).

DimensionCount

Type: UINT

The number of elements in the Scales, InputPixelOffsets, and OutputPixelOffsets arrays. This value must match the dimension count of InputTensor and OutputTensor.

Scales

Type: _Field_size_(DimensionCount) const FLOAT*

The scales to apply when resampling the input, where scales > 1 scale up the image, and scales < 1 scale down the image for that dimension. Note that the scales don't need to be exactly OutputSize / InputSize. If the input after scaling is larger than the output bound, then we crop it to the output size. On the other hand, if the input after scaling is smaller than the output bound, then the output edges are clamped.

InputPixelOffsets

Type: _Field_size_(DimensionCount) const FLOAT*

The offsets to apply to the input pixels before resampling. When this value is 0, the top left corner of the pixel is used instead of its center, which usually won't give the expected result. To resample the image by using the center of the pixels and to get the same behavior as DML_RESAMPLE_OPERATOR_DESC, this value must be 0.5.

OutputPixelOffsets

Type: _Field_size_(DimensionCount) const FLOAT*

The offsets to apply to the output pixels after resampling. When this value is 0, the top left corner of the pixel is used instead of its center, which usually won't give the expected result. To resample the image by using the center of the pixels and to get the same behavior as DML_RESAMPLE_OPERATOR_DESC, this value must be -0.5.

Antialiased

Type: BOOL

Antialiasing is achieved by stretching the resampling filter by a factor max(1, 1 / scale), which means that when downsampling, more input pixels contribute to an output pixel.

This occurs when this flag is set to TRUE, and assuming the following conditions:

  • InterpolationMode is DML_INTERPOLATION_MODE_LINEAR
  • 1/Scales > 2

Then this operator will use an antialiasing filter when downscaling.

Remarks

When Antialiased is false, this operator is equivalent to DML_RESAMPLE2_OPERATOR_DESC.

Availability

This operator was introduced in DML_FEATURE_LEVEL_6_4.

Tensor constraints

InputTensor and OutputTensor must have the same DataType and DimensionCount.

Tensor support

Tensor Kind Supported dimension counts Supported data types
InputTensor Input 1 to 4 FLOAT32, FLOAT16, INT8, UINT8
OutputTensor Output 1 to 4 FLOAT32, FLOAT16, INT8, UINT8

Requirements

   
Header directml.h