Herror ::affine_trans_image (
    Hobject Image,
    Hobject *ImageAffinTrans,
    const HTuple &HomMat2D,
    const HTuple &Interpolation,
    const HTuple &AdaptImageSize
)
HImage HImage::AffineTransImage (
    const HTuple &HomMat2D,
    const HTuple &Interpolation,
    const HTuple &AdaptImageSize
) const
HImageArray HImageArray::AffineTransImage (
    const HTuple &HomMat2D,
    const HTuple &Interpolation,
    const HTuple &AdaptImageSize
) const

Apply an arbitrary affine transformation to an image.

::affine_trans_image applies an arbitrary affine transformation, i.e., scaling, rotation, translation, and skewing, to an image. The affine map is described by the transformation matrix given in HomMat2D , which is built up by using ::hom_mat2d_identity, ::hom_mat2d_scale, ::hom_mat2d_rotate, and ::hom_mat2d_translate. 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, which is assumed for the homogeneous transformation matrices, also for the image. In particular, by doing so roatations 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 wighted 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 and int2 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 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 controled by the paramter AdaptImageSize: With value 'true' the size will be adapted so that no clipping occures. With value 'false' the target image has the same size as the input image.


Attention

The region of the input image is ignored.

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, which is assumed for the homogeneous transformation matrices, also for the image. In particular, by doing so roatations 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.


Parameters

Image (input_object)
(multichannel-)image(-array) -> Hobject: HImage(Array) ( byte / real )
Input image.

ImageAffinTrans (output_object)
(multichannel-)image(-array) -> Hobject * : HImage(Array) ( byte / real )
Transformed image.

HomMat2D (input_control)
affine2d-array -> HTuple.double
Input transformation matrix.
Number of elements: 6

Interpolation (input_control)
string -> HTuple.char *
Type of interpolation.
Default value: 'constant'
List of values: 'none', 'constant', 'weighted'

AdaptImageSize (input_control)
string -> HTuple.char *
Adaption of size of result image.
Default value: 'false'
List of values: 'true', 'false'


Example
/* 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).

Result

::affine_trans_image returns 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.


Possible Predecessors

::hom_mat2d_identity, ::hom_mat2d_translate, ::hom_mat2d_rotate, ::hom_mat2d_scale


Alternatives

::zoom_image_size, ::zoom_image_factor, ::mirror_image, ::rotate_image, ::affine_trans_region


See also

::set_part_style


Module

Image filters



Copyright © 1996-2002 MVTec Software GmbH