ImageDev

ResampleAffine2d

Resamples a two-dimensional image by defining an oriented bounding box and a geometric transform.

Access to parameter description

This algorithm allows the resampling of an input image onto an arbitrary image domain, and optionally apply a geometric transform on it.

The output image domain is defined by a non-axis aligned bounding box (nAABB). To represent the nAABB, we use an AABB (boundingBoxMin, boundingBoxMax) and a angle (boundingBoxAngle).
An additional transformation can be applied to each output voxel position to produce the final resampled image. Each output voxel intensity is extracted from the input with a user-defined interpolation.

For example, this algorithm can be used: See also

Function Syntax

This function returns outputImage.
// Function prototype
std::shared_ptr< iolink::ImageView > resampleAffine2d( std::shared_ptr< iolink::ImageView > inputImage, ResampleAffine2d::InterpolationType interpolationType, iolink::Vector2d boundingBoxMin, iolink::Vector2d boundingBoxMax, double boundingBoxAngle, ResampleAffine2d::SamplingMode samplingMode, iolink::Vector2u32 imageDimensions, double paddingValue, iolink::Matrix3d transform, std::shared_ptr< iolink::ImageView > outputImage = nullptr );
This function returns outputImage.
// Function prototype.
resample_affine_2d(input_image: idt.ImageType,
                   interpolation_type: ResampleAffine2d.InterpolationType = ResampleAffine2d.InterpolationType.LINEAR,
                   bounding_box_min: Union[Iterable[int], Iterable[float]] = [0, 0],
                   bounding_box_max: Union[Iterable[int], Iterable[float]] = [1, 1],
                   bounding_box_angle: float = 0,
                   sampling_mode: ResampleAffine2d.SamplingMode = ResampleAffine2d.SamplingMode.AUTOMATIC,
                   image_dimensions: Iterable[int] = [100, 100],
                   padding_value: float = 0,
                   transform: Union[idt.NDArrayAny, iolink.Matrix3d, iolink.Matrix3f] = _np.identity(3),
                   output_image: idt.ImageType = None) -> idt.ImageType
This function returns outputImage.
// Function prototype.
public static IOLink.ImageView
ResampleAffine2d( IOLink.ImageView inputImage,
                  ResampleAffine2d.InterpolationType interpolationType = ImageDev.ResampleAffine2d.InterpolationType.LINEAR,
                  double[] boundingBoxMin = null,
                  double[] boundingBoxMax = null,
                  double boundingBoxAngle = 0,
                  ResampleAffine2d.SamplingMode samplingMode = ImageDev.ResampleAffine2d.SamplingMode.AUTOMATIC,
                  uint[] imageDimensions = null,
                  double paddingValue = 0,
                  IOLink.Matrix3d transform = null,
                  IOLink.ImageView outputImage = null );

Class Syntax

Parameters

Parameter Name Description Type Supported Values Default Value
input
inputImage
The input image to resample. It can have integer or floating point data type. Image Binary, Label, Grayscale or Multispectral nullptr
input
boundingBoxMin
Minimum coordinates in X and Y of the box that defines the image domain after rotation. Note that the output image domain is the previously defined box rotated to an angle equal to the value of the parameter "boundingBoxAngle". Vector2d Any value {0.f, 0.f}
input
boundingBoxMax
Maximum coordinates in X and Y of the box that defines the image domain after rotation. Note that the output image domain is the previously defined box rotated to an angle equal to the value of the parameter "boundingBoxAngle". Vector2d Any value {1.f, 1.f}
input
boundingBoxAngle
The rotation to apply to the box defined by boundingBoxMin and boundingBoxMax in order to define the domain of the output image. Float64 Any value 0
input
samplingMode
The way to determine the resolution of the output image.
AUTOMATIC The pixel size is automatically computed to be as close as possible to that of the input image. This mode does not work if the transform is not the identity.
MANUAL The output image dimensions are user-defined and the output pixel size is defined accordingly.
Enumeration AUTOMATIC
input
imageDimensions
The size in pixels of the output image in each axis direction. If the samplingMode parameter is set to AUTOMATIC, this parameter is ignored. Vector2u32 != 0 {100, 100}
input
interpolationType
The method used to calculate the intensity of each pixel in the result image.
LINEAR The value of the intensity is linearly interpolated in all directions.
NEAREST_NEIGHBOR The value of the intensity is equal to the nearest intensity.
Enumeration LINEAR
input
paddingValue
Specifies the output value if an output pixel position is outside the bounding box of the input image. Float64 Any value 0
input
transform
The geometric transformation applied to all output pixel positions before the interpolation, represented by a 3x3 matrix. Matrix3d IDENTITY
output
outputImage
The output image. Its dimensions are either defined by the imageDimensions parameter, if the samplingMode parameter is MANUAL, or automatically computed to match the user-defined bounding box with a resolution close to that of the input image. Its calibration is automatically adapted. Its type and interpretation are the same as the input image. Image nullptr
Parameter Name Description Type Supported Values Default Value
input
input_image
The input image to resample. It can have integer or floating point data type. image Binary, Label, Grayscale or Multispectral None
input
bounding_box_min
Minimum coordinates in X and Y of the box that defines the image domain after rotation. Note that the output image domain is the previously defined box rotated to an angle equal to the value of the parameter "boundingBoxAngle". vector2d Any value [0, 0]
input
bounding_box_max
Maximum coordinates in X and Y of the box that defines the image domain after rotation. Note that the output image domain is the previously defined box rotated to an angle equal to the value of the parameter "boundingBoxAngle". vector2d Any value [1, 1]
input
bounding_box_angle
The rotation to apply to the box defined by boundingBoxMin and boundingBoxMax in order to define the domain of the output image. float64 Any value 0
input
sampling_mode
The way to determine the resolution of the output image.
AUTOMATIC The pixel size is automatically computed to be as close as possible to that of the input image. This mode does not work if the transform is not the identity.
MANUAL The output image dimensions are user-defined and the output pixel size is defined accordingly.
enumeration AUTOMATIC
input
image_dimensions
The size in pixels of the output image in each axis direction. If the samplingMode parameter is set to AUTOMATIC, this parameter is ignored. vector2u32 != 0 [100, 100]
input
interpolation_type
The method used to calculate the intensity of each pixel in the result image.
LINEAR The value of the intensity is linearly interpolated in all directions.
NEAREST_NEIGHBOR The value of the intensity is equal to the nearest intensity.
enumeration LINEAR
input
padding_value
Specifies the output value if an output pixel position is outside the bounding box of the input image. float64 Any value 0
input
transform
The geometric transformation applied to all output pixel positions before the interpolation, represented by a 3x3 matrix. matrix _np.identity(3)
output
output_image
The output image. Its dimensions are either defined by the imageDimensions parameter, if the samplingMode parameter is MANUAL, or automatically computed to match the user-defined bounding box with a resolution close to that of the input image. Its calibration is automatically adapted. Its type and interpretation are the same as the input image. image None
Parameter Name Description Type Supported Values Default Value
input
inputImage
The input image to resample. It can have integer or floating point data type. Image Binary, Label, Grayscale or Multispectral null
input
boundingBoxMin
Minimum coordinates in X and Y of the box that defines the image domain after rotation. Note that the output image domain is the previously defined box rotated to an angle equal to the value of the parameter "boundingBoxAngle". Vector2d Any value {0f, 0f}
input
boundingBoxMax
Maximum coordinates in X and Y of the box that defines the image domain after rotation. Note that the output image domain is the previously defined box rotated to an angle equal to the value of the parameter "boundingBoxAngle". Vector2d Any value {1f, 1f}
input
boundingBoxAngle
The rotation to apply to the box defined by boundingBoxMin and boundingBoxMax in order to define the domain of the output image. Float64 Any value 0
input
samplingMode
The way to determine the resolution of the output image.
AUTOMATIC The pixel size is automatically computed to be as close as possible to that of the input image. This mode does not work if the transform is not the identity.
MANUAL The output image dimensions are user-defined and the output pixel size is defined accordingly.
Enumeration AUTOMATIC
input
imageDimensions
The size in pixels of the output image in each axis direction. If the samplingMode parameter is set to AUTOMATIC, this parameter is ignored. Vector2u32 != 0 {100, 100}
input
interpolationType
The method used to calculate the intensity of each pixel in the result image.
LINEAR The value of the intensity is linearly interpolated in all directions.
NEAREST_NEIGHBOR The value of the intensity is equal to the nearest intensity.
Enumeration LINEAR
input
paddingValue
Specifies the output value if an output pixel position is outside the bounding box of the input image. Float64 Any value 0
input
transform
The geometric transformation applied to all output pixel positions before the interpolation, represented by a 3x3 matrix. Matrix3d IDENTITY
output
outputImage
The output image. Its dimensions are either defined by the imageDimensions parameter, if the samplingMode parameter is MANUAL, or automatically computed to match the user-defined bounding box with a resolution close to that of the input image. Its calibration is automatically adapted. Its type and interpretation are the same as the input image. Image null

Object Examples

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

ResampleAffine2d resampleAffine2dAlgo;
resampleAffine2dAlgo.setInputImage( polystyrene );
resampleAffine2dAlgo.setInterpolationType( ResampleAffine2d::InterpolationType::LINEAR );
resampleAffine2dAlgo.setBoundingBoxMin( {10, 15} );
resampleAffine2dAlgo.setBoundingBoxMax( {40, 50} );
resampleAffine2dAlgo.setBoundingBoxAngle( 0 );
resampleAffine2dAlgo.setSamplingMode( ResampleAffine2d::SamplingMode::AUTOMATIC );
resampleAffine2dAlgo.setImageDimensions( {100, 100} );
resampleAffine2dAlgo.setPaddingValue( 0 );
resampleAffine2dAlgo.setTransform( iolink::Matrix3d::identity() );
resampleAffine2dAlgo.execute();

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

resample_affine_2d_algo = imagedev.ResampleAffine2d()
resample_affine_2d_algo.input_image = polystyrene
resample_affine_2d_algo.interpolation_type = imagedev.ResampleAffine2d.LINEAR
resample_affine_2d_algo.bounding_box_min = [10, 15]
resample_affine_2d_algo.bounding_box_max = [40, 50]
resample_affine_2d_algo.bounding_box_angle = 0
resample_affine_2d_algo.sampling_mode = imagedev.ResampleAffine2d.AUTOMATIC
resample_affine_2d_algo.image_dimensions = [100, 100]
resample_affine_2d_algo.padding_value = 0
resample_affine_2d_algo.transform = np.identity(3)
resample_affine_2d_algo.execute()

print("output_image:", str(resample_affine_2d_algo.output_image))
ImageView polystyrene = ViewIO.ReadImage( @"Data/images/polystyrene.tif" );
IOLink.Matrix3d transform = IOLink.Matrix3d.Identity();

ResampleAffine2d resampleAffine2dAlgo = new ResampleAffine2d
{
    inputImage = polystyrene,
    interpolationType = ResampleAffine2d.InterpolationType.LINEAR,
    boundingBoxMin = new double[]{10, 15},
    boundingBoxMax = new double[]{40, 50},
    boundingBoxAngle = 0,
    samplingMode = ResampleAffine2d.SamplingMode.AUTOMATIC,
    imageDimensions = new uint[]{100, 100},
    paddingValue = 0,
    transform = transform
};
resampleAffine2dAlgo.Execute();

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

Function Examples

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

auto result = resampleAffine2d( polystyrene, ResampleAffine2d::InterpolationType::LINEAR, {10, 15}, {40, 50}, 0, ResampleAffine2d::SamplingMode::AUTOMATIC, {100, 100}, 0, iolink::Matrix3d::identity() );

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

result = imagedev.resample_affine_2d(polystyrene, imagedev.ResampleAffine2d.LINEAR, [10, 15], [40, 50], 0, imagedev.ResampleAffine2d.AUTOMATIC, [100, 100], 0, np.identity(3))

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

IOLink.ImageView result = Processing.ResampleAffine2d( polystyrene, ResampleAffine2d.InterpolationType.LINEAR, new double[]{10, 15}, new double[]{40, 50}, 0, ResampleAffine2d.SamplingMode.AUTOMATIC, new uint[]{100, 100}, 0, transform );

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