ImageDev

ResampleAffine3d

Resamples an 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 transformation (boundingBoxTransform).
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 > resampleAffine3d( std::shared_ptr< iolink::ImageView > inputImage, iolink::Vector3d boundingBoxMin, iolink::Vector3d boundingBoxMax, iolink::Matrix4d boundingBoxTransform, ResampleAffine3d::SamplingMode samplingMode, iolink::Vector3u32 imageDimensions, ResampleAffine3d::InterpolationType interpolationType, double paddingValue, iolink::Matrix4d transform, std::shared_ptr< iolink::ImageView > outputImage = nullptr );
This function returns outputImage.
// Function prototype.
resample_affine_3d(input_image: idt.ImageType,
                   bounding_box_min: Union[Iterable[int], Iterable[float]] = [0, 0, 0],
                   bounding_box_max: Union[Iterable[int], Iterable[float]] = [1, 1, 1],
                   bounding_box_transform: Union[idt.NDArrayAny, iolink.Matrix4d, iolink.Matrix4f] = _np.identity(4),
                   sampling_mode: ResampleAffine3d.SamplingMode = ResampleAffine3d.SamplingMode.AUTOMATIC,
                   image_dimensions: Iterable[int] = [1, 1, 1],
                   interpolation_type: ResampleAffine3d.InterpolationType = ResampleAffine3d.InterpolationType.LINEAR,
                   padding_value: float = 0,
                   transform: Union[idt.NDArrayAny, iolink.Matrix4d, iolink.Matrix4f] = _np.identity(4),
                   output_image: idt.ImageType = None) -> idt.ImageType
This function returns outputImage.
// Function prototype.
public static IOLink.ImageView
ResampleAffine3d( IOLink.ImageView inputImage,
                  double[] boundingBoxMin = null,
                  double[] boundingBoxMax = null,
                  IOLink.Matrix4d boundingBoxTransform = null,
                  ResampleAffine3d.SamplingMode samplingMode = ImageDev.ResampleAffine3d.SamplingMode.AUTOMATIC,
                  uint[] imageDimensions = null,
                  ResampleAffine3d.InterpolationType interpolationType = ImageDev.ResampleAffine3d.InterpolationType.LINEAR,
                  double paddingValue = 0,
                  IOLink.Matrix4d 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
The origin of the bounding box defining the output image, in world coordinates. The resulting bounding box is an axis aligned box in the 3D space. Vector3d Any value {0.f, 0.f, 0.f}
input
boundingBoxMax
The end point of the bounding box defining the output image, in world coordinates. The resulting bounding box is an axis aligned box in the 3D space. Vector3d Any value {1.f, 1.f, 1.f}
input
boundingBoxTransform
The geometric transformation defining the bounding box orientation of the output image, represented by a 4x4 matrix. Matrix4d IDENTITY
input
samplingMode
The way to determine the resolution of the output image.
AUTOMATIC The voxel 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 voxel 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. Vector3u32 != 0 {1, 1, 1}
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 voxel position is outside the bounding box of the input image. Float64 Any value 0
input
transform
The geometric transformation applied to all output voxel positions before the interpolation, represented by a 4x4 matrix. Matrix4d 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
The origin of the bounding box defining the output image, in world coordinates. The resulting bounding box is an axis aligned box in the 3D space. vector3d Any value [0, 0, 0]
input
bounding_box_max
The end point of the bounding box defining the output image, in world coordinates. The resulting bounding box is an axis aligned box in the 3D space. vector3d Any value [1, 1, 1]
input
bounding_box_transform
The geometric transformation defining the bounding box orientation of the output image, represented by a 4x4 matrix. matrix _np.identity(4)
input
sampling_mode
The way to determine the resolution of the output image.
AUTOMATIC The voxel 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 voxel 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. vector3u32 != 0 [1, 1, 1]
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 voxel position is outside the bounding box of the input image. float64 Any value 0
input
transform
The geometric transformation applied to all output voxel positions before the interpolation, represented by a 4x4 matrix. matrix _np.identity(4)
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
The origin of the bounding box defining the output image, in world coordinates. The resulting bounding box is an axis aligned box in the 3D space. Vector3d Any value {0f, 0f, 0f}
input
boundingBoxMax
The end point of the bounding box defining the output image, in world coordinates. The resulting bounding box is an axis aligned box in the 3D space. Vector3d Any value {1f, 1f, 1f}
input
boundingBoxTransform
The geometric transformation defining the bounding box orientation of the output image, represented by a 4x4 matrix. Matrix4d IDENTITY
input
samplingMode
The way to determine the resolution of the output image.
AUTOMATIC The voxel 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 voxel 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. Vector3u32 != 0 {1, 1, 1}
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 voxel position is outside the bounding box of the input image. Float64 Any value 0
input
transform
The geometric transformation applied to all output voxel positions before the interpolation, represented by a 4x4 matrix. Matrix4d 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 foam = readVipImage( std::string( IMAGEDEVDATA_IMAGES_FOLDER ) + "foam.vip" );

ResampleAffine3d resampleAffine3dAlgo;
resampleAffine3dAlgo.setInputImage( foam );
resampleAffine3dAlgo.setBoundingBoxMin( {0, 0, 0} );
resampleAffine3dAlgo.setBoundingBoxMax( {10, 10, 10} );
resampleAffine3dAlgo.setBoundingBoxTransform( iolink::Matrix4d::identity() );
resampleAffine3dAlgo.setSamplingMode( ResampleAffine3d::SamplingMode::AUTOMATIC );
resampleAffine3dAlgo.setImageDimensions( {10, 10, 10} );
resampleAffine3dAlgo.setInterpolationType( ResampleAffine3d::InterpolationType::LINEAR );
resampleAffine3dAlgo.setPaddingValue( 0 );
resampleAffine3dAlgo.setTransform( iolink::Matrix4d({1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0}) );
resampleAffine3dAlgo.execute();

std::cout << "outputImage:" << resampleAffine3dAlgo.outputImage()->toString();
foam = imagedev.read_vip_image(imagedev_data.get_image_path("foam.vip"))

resample_affine_3d_algo = imagedev.ResampleAffine3d()
resample_affine_3d_algo.input_image = foam
resample_affine_3d_algo.bounding_box_min = [0, 0, 0]
resample_affine_3d_algo.bounding_box_max = [10, 10, 10]
resample_affine_3d_algo.bounding_box_transform = np.identity(4)
resample_affine_3d_algo.sampling_mode = imagedev.ResampleAffine3d.AUTOMATIC
resample_affine_3d_algo.image_dimensions = [10, 10, 10]
resample_affine_3d_algo.interpolation_type = imagedev.ResampleAffine3d.LINEAR
resample_affine_3d_algo.padding_value = 0
resample_affine_3d_algo.transform = np.array([1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0]).reshape((4, 4))
resample_affine_3d_algo.execute()

print("output_image:", str(resample_affine_3d_algo.output_image))
ImageView foam = Data.ReadVipImage( @"Data/images/foam.vip" );
IOLink.Matrix4d boundingBoxTransform = IOLink.Matrix4d.Identity();
var transformValues = new double[]{1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0};
IOLink.Matrix4d transform = new IOLink.Matrix4d();
for ( uint i = 0;  i < 4; i++ )
{
  for ( uint j = 0;  j < 4; j++ )
  {
    transform.SetAt(i,j,transformValues[i*4+j]);
  }
}

ResampleAffine3d resampleAffine3dAlgo = new ResampleAffine3d
{
    inputImage = foam,
    boundingBoxMin = new double[]{0, 0, 0},
    boundingBoxMax = new double[]{10, 10, 10},
    boundingBoxTransform = boundingBoxTransform,
    samplingMode = ResampleAffine3d.SamplingMode.AUTOMATIC,
    imageDimensions = new uint[]{10, 10, 10},
    interpolationType = ResampleAffine3d.InterpolationType.LINEAR,
    paddingValue = 0,
    transform = transform
};
resampleAffine3dAlgo.Execute();

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

Function Examples

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

auto result = resampleAffine3d( foam, {0, 0, 0}, {10, 10, 10}, iolink::Matrix4d::identity(), ResampleAffine3d::SamplingMode::AUTOMATIC, {10, 10, 10}, ResampleAffine3d::InterpolationType::LINEAR, 0, iolink::Matrix4d({1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0}) );

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

result = imagedev.resample_affine_3d(foam, [0, 0, 0], [10, 10, 10], np.identity(4), imagedev.ResampleAffine3d.AUTOMATIC, [10, 10, 10], imagedev.ResampleAffine3d.LINEAR, 0, np.array([1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0]).reshape((4, 4)))

print("output_image:", str(result))
ImageView foam = Data.ReadVipImage( @"Data/images/foam.vip" );
IOLink.Matrix4d boundingBoxTransform = IOLink.Matrix4d.Identity();
var transformValues = new double[]{1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0};
IOLink.Matrix4d transform = new IOLink.Matrix4d();
for ( uint i = 0;  i < 4; i++ )
{
  for ( uint j = 0;  j < 4; j++ )
  {
    transform.SetAt(i,j,transformValues[i*4+j]);
  }
}

IOLink.ImageView result = Processing.ResampleAffine3d( foam, new double[]{0, 0, 0}, new double[]{10, 10, 10}, boundingBoxTransform, ResampleAffine3d.SamplingMode.AUTOMATIC, new uint[]{10, 10, 10}, ResampleAffine3d.InterpolationType.LINEAR, 0, transform );

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