Apply an arbitrary affine 2D transformation to images.
affine_trans_image applies an arbitrary affine 2D transformation, i.e., scaling, rotation, translation, and slant (skewing), to the images given in Image and returns the transformed images in ImageAffinTrans. The affine transformation is described by the homogeneous transformation matrix given in HomMat2D, which can be created using the operators hom_mat2d_identity, hom_mat2d_scale, hom_mat2d_rotate, hom_mat2d_translate, etc., or be the result of operators like vector_angle_to_rigid.
The components of the homogeneous transformation matrix are interpreted as follows: The row coordinate of the image corresponds to the x coordinate of the matrix, while the column coordinate of the image corresponds to the y coordinate of the matrix. This is necessary to obtain a right-handed coordinate system for the image. In particular, this assures that rotations are performed in the correct direction. Note that the (x,y) order of the matrices quite naturally corresponds to the usual (row,column) order for coordinates in the image.
The region of the input image is ignored, i.e., assumed to be the full rectangle of the image. The region of the resulting image is set to the transformed rectangle of the input image. If necessary, the resulting image is filled with zero (black) outside of the region of the original image.
Generally, transformed points will lie between pixel coordinates. Therefore, an appropriate interpolation scheme has to be used. The interpolation can also be used to avoid aliasing effects for scaled images. The quality and speed of the interpolation can be set by the parameter Interpolation:
none
No interpolation: The gray value is determined from the
nearest pixel's gray value (possibly low quality, very fast).
constant
Use equally weighted interpolation between adjacent pixels
(medium quality and run time).
weighted
Use Gaussian interpolation between adjacent pixels (best
quality, slow).
In addition, the system parameter 'int_zooming' (see set_system) affects the accuracy of the transformation. If 'int_zooming' is set to 'true', the transformation for byte, int2 and uint2 images is carried out internally using fixed point arithmetic, leading to much shorter execution times. However, the accuracy of the transformed gray values is smaller in this case. For byte images, the differences to the more accurate calculation (using 'int_zooming' = 'false') is typically less than two gray levels. Correspondingly, for int2 and uint2 images, the gray value differences are less than 1/128 times the dynamic gray value range of the image, i.e., they can be as large as 512 gray levels if the entire dynamic range of 16 bit is used. For real images, the parameter 'int_zooming' does not affect the accuracy, since the internal calculations are always done using floating point arithmetic.
The size of the target image can be controlled by the parameter AdaptImageSize: With value 'true' the size will be adapted so that no clipping occurs at the right or lower edge. With value 'false' the target image has the same size as the input image. Note that, independent of AdaptImageSize, the image is always clipped at the left and upper edge, i.e., all image parts that have negative coordinates after the transformation are clipped.
The region of the input image is ignored.
|
Image (input_object) |
(multichannel-)image(-array) -> object : byte / int2 / uint2 / real |
| Input image. | |
|
ImageAffinTrans (output_object) |
(multichannel-)image(-array) -> object : byte / int2 / uint2 / real |
| Transformed image. | |
|
HomMat2D (input_control) |
affine2d-array -> real |
| Input transformation matrix. | |
| Number of elements: 6 | |
|
Interpolation (input_control) |
string -> string |
| Type of interpolation. | |
| Default value: 'constant' | |
| List of values: 'none', 'constant', 'weighted' | |
|
AdaptImageSize (input_control) |
string -> string |
| Adaption of size of result image. | |
| Default value: 'false' | |
| List of values: 'true', 'false' | |
/* Reduction of an image (512 x 512 Pixels) by 50%, rotation */
/* by 180 degrees and translation to the upper-left corner: */
hom_mat2d_identity(Matrix1)
hom_mat2d_scale(Matrix1,0.5,0.5,256.0,256.0,Matrix2)
hom_mat2d_rotate(Matrix2,3.14,256.0,256.0,Matrix3)
hom_mat2d_translate(Matrix3,-128.0,-128.0,Matrix4,)
affine_trans_image(Image,TransImage,Matrix4,1).
/* Enlarging the part of an image in the interactively */
/* chosen rectangular window sector: */
draw_rectangle2(WindowHandle,L,C,Phi,L1,L2)
hom_mat2d_identity(Matrix1)
get_system(width,Width)
get_system(height,Height)
hom_mat2d_translate(Matrix1,Height/2.0-L,Width/2.0-C,Matrix2)
hom_mat2d_rotate(Matrix2,3.14-Phi,Height/2.0,Width/2.0,Matrix3)
hom_mat2d_scale(Matrix3,Height/(2.0*L2),Width/(2.0*L1),
Height/2.0,Width/2.0,Matrix4)
affine_trans_image(Image,Matrix4,TransImage,1).
affine_trans_image returns 2 (H_MSG_TRUE) if all parameter values are correct. If the input is empty the behaviour can be set via set_system(::'no_object_result',<Result>:). If necessary, an exception handling is raised.
affine_trans_image is reentrant and automatically parallelized (on tuple level, channel level).
hom_mat2d_identity, hom_mat2d_translate, hom_mat2d_rotate, hom_mat2d_scale
affine_trans_image_size, zoom_image_size, zoom_image_factor, mirror_image, rotate_image, affine_trans_region
Image filters