Processing math: 100%
ImageDev

RotateImage2d

Applies a rotation of a given angle and center on a two-dimensional image.

Access to parameter description

This command is deprecated, it will be removed in ImageDev 2024.2.
You can use Rotate2d instead.

This algorithm performs a rotation of an image by a user-defined angle θ and a center C. The new coordinates (x,y) can be expressed as a function of the old coordinates (x,y): {x=(xx0)cosθ(yy0)sinθ+x0y=(xx0)sinθ+(yy0)cosθ+y0} where (x0,y0) are the coordinates of the center of the rotation. Or in matrix notation: [xy]=[cosθsinθsinθcosθ][xx0yy0]+[x0y0] Destination pixels may be outside the image, and normally these pixels are ignored. Furthermore, the (x,y) coordinates obtained are not always integers, even though an image is a discrete space. The following figure illustrates the grid of the resultant image, the point M being a pixel in this image. The points are generated from the rotation of the original image and do not fit on the grid.
<b> Figure 1.</b> Image grid rotation
Figure 1. Image grid rotation

To calculate the intensity of each pixel M, two methods are possible:
If dj denotes the distance MjM, fi is defined as: fi=j=4j=1jidj e.g. f1=d2d3d4.

The choice of the fi's ensures that the interpolated value is equal to gj if M matches Mj. This method gives better results but requires more computation time.

Notice: RotateImage2d considers the image as a cylinder, where the information outside the image area wraps around and is placed in the blank part.

See also

Function Syntax

This function returns outputImage.
// Function prototype
std::shared_ptr< iolink::ImageView > rotateImage2d( std::shared_ptr< iolink::ImageView > inputImage, iolink::Vector2i32 rotationCenter, double rotationAngle, RotateImage2d::InterpolationType interpolationType, std::shared_ptr< 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
rotationCenter
The rotation center coordinates. Vector2i32 >=0 {1, 1}
input
rotationAngle
The angle of the rotation in degrees. Float64 Any value 10
input
interpolationType
The interpolation mode. Method used to calculate the intensity of each pixel in the result image.
NEAREST_NEIGHBOR Assign the gray level of the nearest pixel.
LINEAR Assign the bilinear interpolation from the four nearest pixels.
Enumeration NEAREST_NEIGHBOR
output
outputImage
The output image. Its dimensions and type are forced to the same values as the input. Image nullptr

Object Examples

std::shared_ptr< iolink::ImageView > polystyrene = ioformat::readImage( std::string( IMAGEDEVDATA_IMAGES_FOLDER ) + "polystyrene.tif" );

RotateImage2d rotateImage2dAlgo;
rotateImage2dAlgo.setInputImage( polystyrene );
rotateImage2dAlgo.setRotationCenter( {1, 1} );
rotateImage2dAlgo.setRotationAngle( 10.0 );
rotateImage2dAlgo.setInterpolationType( RotateImage2d::InterpolationType::NEAREST_NEIGHBOR );
rotateImage2dAlgo.execute();

std::cout << "outputImage:" << rotateImage2dAlgo.outputImage()->toString();

Function Examples

std::shared_ptr< iolink::ImageView > polystyrene = ioformat::readImage( std::string( IMAGEDEVDATA_IMAGES_FOLDER ) + "polystyrene.tif" );

auto result = rotateImage2d( polystyrene, {1, 1}, 10.0, RotateImage2d::InterpolationType::NEAREST_NEIGHBOR );

std::cout << "outputImage:" << result->toString();