ImageDev

DrawRectangleColor2d

Draws a color rectangle on a two-dimensional image.

Access to parameter description

This algorithm draws a single rectangle based on the given center position, side sizes and rotation in the given color. The rectangle can be filled or just the outline.

See also

Function Syntax

This function returns outputColorImage.
// Function prototype
std::shared_ptr< iolink::ImageView > drawRectangleColor2d( std::shared_ptr< iolink::ImageView > inputImage, const iolink::Vector2d& center, const iolink::Vector2d& sides, double rotation, bool isFilled, const iolink::Vector3d& value, std::shared_ptr< iolink::ImageView > outputColorImage = nullptr );
This function returns outputColorImage.
// Function prototype.
draw_rectangle_color_2d(input_image: idt.ImageType,
                        center: Union[Iterable[int], Iterable[float]] = [128, 128],
                        sides: Union[Iterable[int], Iterable[float]] = [32, 32],
                        rotation: float = 0,
                        is_filled: bool = False,
                        value: Union[Iterable[int], Iterable[float]] = [255, 0, 0],
                        output_color_image: idt.ImageType = None) -> idt.ImageType
This function returns outputColorImage.
// Function prototype.
public static IOLink.ImageView
DrawRectangleColor2d( IOLink.ImageView inputImage,
                      double[] center = null,
                      double[] sides = null,
                      double rotation = 0,
                      bool isFilled = false,
                      double[] value = null,
                      IOLink.ImageView outputColorImage = null );

Class Syntax

Parameters

Parameter Name Description Type Supported Values Default Value
input
inputImage
The input grayscale or RGB image. Image Grayscale or Multispectral nullptr
input
center
The pixel coordinates of the rectangle center. Vector2d >=0 {128.f, 128.f}
input
sides
The rectangle x-aligned and y-aligned sides before rotation, in pixels. Vector2d >=0 {32.f, 32.f}
input
rotation
The rectangle rotation in degrees. Float64 Any value 0
input
isFilled
The rectangle is filled if equal to true. Default is false. Bool false
input
value
The intensity to assign to rectangle pixels. Default is [255.0, 0.0, 0.0] Vector3d Any value {255.f, 0.f, 0.f}
output
outputColorImage
The output RGB image. Its size and type are forced to the same values as the input. Image nullptr
Parameter Name Description Type Supported Values Default Value
input
input_image
The input grayscale or RGB image. image Grayscale or Multispectral None
input
center
The pixel coordinates of the rectangle center. vector2d >=0 [128, 128]
input
sides
The rectangle x-aligned and y-aligned sides before rotation, in pixels. vector2d >=0 [32, 32]
input
rotation
The rectangle rotation in degrees. float64 Any value 0
input
is_filled
The rectangle is filled if equal to true. Default is false. bool False
input
value
The intensity to assign to rectangle pixels. Default is [255.0, 0.0, 0.0] vector3d Any value [255, 0, 0]
output
output_color_image
The output RGB image. Its size and type are forced to the same values as the input. image None
Parameter Name Description Type Supported Values Default Value
input
inputImage
The input grayscale or RGB image. Image Grayscale or Multispectral null
input
center
The pixel coordinates of the rectangle center. Vector2d >=0 {128f, 128f}
input
sides
The rectangle x-aligned and y-aligned sides before rotation, in pixels. Vector2d >=0 {32f, 32f}
input
rotation
The rectangle rotation in degrees. Float64 Any value 0
input
isFilled
The rectangle is filled if equal to true. Default is false. Bool false
input
value
The intensity to assign to rectangle pixels. Default is [255.0, 0.0, 0.0] Vector3d Any value {255f, 0f, 0f}
output
outputColorImage
The output RGB image. Its size and type are forced to the same values as the input. Image null

Object Examples

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

DrawRectangleColor2d drawRectangleColor2dAlgo;
drawRectangleColor2dAlgo.setInputImage( polystyrene );
drawRectangleColor2dAlgo.setCenter( {132, 351} );
drawRectangleColor2dAlgo.setSides( {72, 140} );
drawRectangleColor2dAlgo.setRotation( 10 );
drawRectangleColor2dAlgo.setIsFilled( false );
drawRectangleColor2dAlgo.setValue( {255, 0, 0} );
drawRectangleColor2dAlgo.execute();

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

draw_rectangle_color_2d_algo = imagedev.DrawRectangleColor2d()
draw_rectangle_color_2d_algo.input_image = polystyrene
draw_rectangle_color_2d_algo.center = [132, 351]
draw_rectangle_color_2d_algo.sides = [72, 140]
draw_rectangle_color_2d_algo.rotation = 10
draw_rectangle_color_2d_algo.is_filled = False
draw_rectangle_color_2d_algo.value = [255, 0, 0]
draw_rectangle_color_2d_algo.execute()

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

DrawRectangleColor2d drawRectangleColor2dAlgo = new DrawRectangleColor2d
{
    inputImage = polystyrene,
    center = new double[]{132, 351},
    sides = new double[]{72, 140},
    rotation = 10,
    isFilled = false,
    value = new double[]{255, 0, 0}
};
drawRectangleColor2dAlgo.Execute();

Console.WriteLine( "outputColorImage:" + drawRectangleColor2dAlgo.outputColorImage.ToString() );

Function Examples

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

auto result = drawRectangleColor2d( polystyrene, {132, 351}, {72, 140}, 10, false, {255, 0, 0} );

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

result = imagedev.draw_rectangle_color_2d(polystyrene, [132, 351], [72, 140], 10, False, [255, 0, 0])

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

IOLink.ImageView result = Processing.DrawRectangleColor2d( polystyrene, new double[]{132, 351}, new double[]{72, 140}, 10, false, new double[]{255, 0, 0} );

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



© 2026 Thermo Fisher Scientific Inc. All rights reserved.