ImageDev

ResizeWithRatio2d

Generates a two-dimensional image with a new size preserving the input aspect ratio using a user-defined interpolation mode.

Access to parameter description

This algorithm resamples a 2D image to generate a new image with a different size by applying a user-defined interpolation mode. If the scaling factor is not the same for all axes, the image is padded to maintain the aspect ratio without changing the position of input pixels in the 2D space.

See also

Function Syntax

This function returns outputImage.
// Function prototype
std::shared_ptr< iolink::ImageView > resizeWithRatio2d( std::shared_ptr< iolink::ImageView > inputImage, const iolink::Vector2i32& shape, ResizeWithRatio2d::InterpolationType interpolationType, double paddingValue, bool preserveCalibration, std::shared_ptr< iolink::ImageView > outputImage = nullptr );
This function returns outputImage.
// Function prototype.
resize_with_ratio_2d(input_image: idt.ImageType,
                     shape: Iterable[int] = [1024, 1024],
                     interpolation_type: Union[Literal["NEAREST_NEIGHBOR"],Literal["LINEAR"],ResizeWithRatio2d.InterpolationType] = ResizeWithRatio2d.InterpolationType.NEAREST_NEIGHBOR,
                     padding_value: float = 0,
                     preserve_calibration: bool = False,
                     output_image: idt.ImageType = None) -> idt.ImageType
This function returns outputImage.
// Function prototype.
public static IOLink.ImageView
ResizeWithRatio2d( IOLink.ImageView inputImage,
                   int[] shape = null,
                   ResizeWithRatio2d.InterpolationType interpolationType = ImageDev.ResizeWithRatio2d.InterpolationType.NEAREST_NEIGHBOR,
                   double paddingValue = 0,
                   bool preserveCalibration = false,
                   IOLink.ImageView outputImage = null );

Class Syntax

Parameters

Parameter Name Description Type Supported Values Default Value
input
inputImage
The input image. Image Binary, Label, Grayscale or Multispectral nullptr
input
shape
The X and Y size of the new image, in pixels. Vector2i32 >0 {1024, 1024}
input
interpolationType
The interpolation mode. Method used to calculate the intensity of each pixel in the result image.
Value Description
NEAREST_NEIGHBOR Assigns the gray level of the nearest pixel.
LINEAR Assigns the bilinear interpolation from the four nearest pixels.
Enumeration NEAREST_NEIGHBOR
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
preserveCalibration
Defines how is managed the calibration.
If set to true the calibration is not changed. When displaying the image with respect of the calibration, if the shape is greater than the input shape, the image appears larger than initially.
If set to false, the calibration is adapted respectively to the ratio between the input and output shapes.
Bool false
output
outputImage
The output image. Its type is forced to the same value as the input. Its dimensions are defined by the shape parameter. Image nullptr
Parameter Name Description Type Supported Values Default Value
input
input_image
The input image. image Binary, Label, Grayscale or Multispectral None
input
shape
The X and Y size of the new image, in pixels. vector2i32 >0 [1024, 1024]
input
interpolation_type
The interpolation mode. Method used to calculate the intensity of each pixel in the result image.
Value Description
NEAREST_NEIGHBOR Assigns the gray level of the nearest pixel.
LINEAR Assigns the bilinear interpolation from the four nearest pixels.
enumeration NEAREST_NEIGHBOR
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
preserve_calibration
Defines how is managed the calibration.
If set to true the calibration is not changed. When displaying the image with respect of the calibration, if the shape is greater than the input shape, the image appears larger than initially.
If set to false, the calibration is adapted respectively to the ratio between the input and output shapes.
bool False
output
output_image
The output image. Its type is forced to the same value as the input. Its dimensions are defined by the shape parameter. image None
Parameter Name Description Type Supported Values Default Value
input
inputImage
The input image. Image Binary, Label, Grayscale or Multispectral null
input
shape
The X and Y size of the new image, in pixels. Vector2i32 >0 {1024, 1024}
input
interpolationType
The interpolation mode. Method used to calculate the intensity of each pixel in the result image.
Value Description
NEAREST_NEIGHBOR Assigns the gray level of the nearest pixel.
LINEAR Assigns the bilinear interpolation from the four nearest pixels.
Enumeration NEAREST_NEIGHBOR
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
preserveCalibration
Defines how is managed the calibration.
If set to true the calibration is not changed. When displaying the image with respect of the calibration, if the shape is greater than the input shape, the image appears larger than initially.
If set to false, the calibration is adapted respectively to the ratio between the input and output shapes.
Bool false
output
outputImage
The output image. Its type is forced to the same value as the input. Its dimensions are defined by the shape parameter. Image null

Object Examples

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

ResizeWithRatio2d resizeWithRatio2dAlgo;
resizeWithRatio2dAlgo.setInputImage( polystyrene );
resizeWithRatio2dAlgo.setShape( {1024, 512} );
resizeWithRatio2dAlgo.setInterpolationType( ResizeWithRatio2d::InterpolationType::NEAREST_NEIGHBOR );
resizeWithRatio2dAlgo.setPaddingValue( 5 );
resizeWithRatio2dAlgo.setPreserveCalibration( true );
resizeWithRatio2dAlgo.execute();

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

resize_with_ratio_2d_algo = imagedev.ResizeWithRatio2d()
resize_with_ratio_2d_algo.input_image = polystyrene
resize_with_ratio_2d_algo.shape = [1024, 512]
resize_with_ratio_2d_algo.interpolation_type = imagedev.ResizeWithRatio2d.NEAREST_NEIGHBOR
resize_with_ratio_2d_algo.padding_value = 5
resize_with_ratio_2d_algo.preserve_calibration = True
resize_with_ratio_2d_algo.execute()

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

ResizeWithRatio2d resizeWithRatio2dAlgo = new ResizeWithRatio2d
{
    inputImage = polystyrene,
    shape = new int[]{1024, 512},
    interpolationType = ResizeWithRatio2d.InterpolationType.NEAREST_NEIGHBOR,
    paddingValue = 5,
    preserveCalibration = true
};
resizeWithRatio2dAlgo.Execute();

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

Function Examples

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

auto result = resizeWithRatio2d( polystyrene, {1024, 512}, ResizeWithRatio2d::InterpolationType::NEAREST_NEIGHBOR, 5, true );

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

result = imagedev.resize_with_ratio_2d(polystyrene, [1024, 512], imagedev.ResizeWithRatio2d.NEAREST_NEIGHBOR, 5, True)

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

IOLink.ImageView result = Processing.ResizeWithRatio2d( polystyrene, new int[]{1024, 512}, ResizeWithRatio2d.InterpolationType.NEAREST_NEIGHBOR, 5, true );

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



© 2026 Thermo Fisher Scientific Inc. All rights reserved.