- HDevelop
- .NET
- Python
- C++
- C
算子列表
名称
affine_trans_image
— Apply an arbitrary affine 2D transformation to images.
参数签名
affine_trans_image(Image : ImageAffineTrans : HomMat2D, Interpolation, AdaptImageSize : )
描述
affine_trans_image
applies an arbitrary affine 2Dtransformation, i.e., scaling, rotation, translation, and slant(skewing), to the images given in Image and returns thetransformed images in ImageAffineTrans. The affinetransformation is described by the homogeneous transformation matrixgiven in HomMat2D, which can be created using the operatorshom_mat2d_identity, hom_mat2d_scale,hom_mat2d_rotate, hom_mat2d_translate, etc., or bethe result of operators like vector_angle_to_rigid.
The components of the homogeneous transformation matrix areinterpreted as follows: The row coordinate of the imagecorresponds to x and the column coordinate corresponds toy of the coordinate system in which the transformation matrix wasdefined. This is necessary to obtain a right-handed coordinatesystem for the image. In particular, this assures that rotationsare 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 domain of the input image is ignored, i.e., assumed to be thefull rectangle of the image. The domain of the output image is theintersection of the transformed rectangle and the rectangle of theoutput image.
Generally, transformed points will lie between pixel coordinates.Therefore, an appropriate interpolation scheme must be used. Theinterpolation can also be used to avoid aliasing effects for scaledimages. The quality and speed of the interpolation can be set bythe parameter Interpolation:
- nearest_neighbor
Nearest-neighbor interpolation: Thegray value is determined from the nearest pixel's gray value(possibly low quality, very fast).
- bilinear
Bilinear interpolation. The gray value isdetermined from the four nearest pixels through bilinearinterpolation. If the affine transformation contains a scalingwith a scale factor < 1, no smoothing is performed, which maycause severe aliasing effects (medium quality and run time).
- bicubic
Bicubic interpolation. The gray value isdetermined from the nearest pixels throughbicubic interpolation. If the affine transformation contains ascaling with a scale factor < 1, no smoothing is performed,which may cause severe aliasing effects (high quality forenlargements, slow).
- constant
Bilinear interpolation. The gray value isdetermined from the four nearest pixels through bilinearinterpolation. If the affine transformation contains a scalingwith a scale factor < 1, a kind of mean filter is used toprevent aliasing effects (medium quality and run time).
- weighted
Bilinear interpolation. The gray value isdetermined from the four nearest pixels through bilinearinterpolation. If the affine transformation contains a scalingwith a scale factor < 1, a kind of Gaussian filter is used toprevent aliasing effects (high quality, slow).
In addition, the system parameter 'int_zooming' (seeset_system) affects the accuracy of the transformation. If'int_zooming' is set to 'true', the transformationfor byte, int2 and uint2 images is carried out internally usingfixed point arithmetic, leading to much shorter execution times.However, the accuracy of the transformed gray values is smaller inthis case. For byte images, the differences to the more accuratecalculation (using 'int_zooming' = 'false') istypically less than two gray levels. Correspondingly, for int2 anduint2 images, the gray value differences are less than 1/128 timesthe dynamic gray value range of the image, i.e., they can be aslarge as 512 gray levels if the entire dynamic range of 16 bit isused. When using fixed point arithmetic, the domain ofresulting images can differ as well.Additionally, if a large scale factor is applied and a largeoutput image is obtained, then undefined gray values at the lowerand at the right image border may result. The maximum width of this border of undefined gray values can beestimated as , where S is the scale factor in one dimensionand I is the size of the output image in the correspondingdimension. For real images, the parameter 'int_zooming' doesnot affect the accuracy, since the internal calculations are alwaysdone using floating point arithmetic.
The size of the target image can be controlled by the parameterAdaptImageSize: If set to 'true', the size will beadapted so that no clipping occurs at the right or lower edge. Ifset to 'false', the target image has the same size as theinput image. Note that, independent of AdaptImageSize, theimage is always clipped at the left and upper edge, i.e., all imageparts that have negative coordinates after the transformation areclipped.
注意
The region of the input image is ignored.
affine_trans_image
does not use the HALCON standardcoordinate system (with the origin in the center of the firstpixel), but instead uses the same coordinate system as inaffine_trans_pixel, i.e., the origin lies in the upper leftcorner of the first pixel. Therefore, applyingaffine_trans_image
corresponds to a chain of transformations(see affine_trans_pixel), which is applied to each point ofthe image (input and output pixels as homogeneous vectors). As aneffect, you might get unexpected results when creating affinetransformations based on coordinates that are derived from theimage, e.g., by operators like area_center_gray. Forexample, if you use this operator to calculate the center of gravityof a rotationally symmetric image and then rotate the image aroundthis point using hom_mat2d_rotate, the resulting image willnot lie on the original one. In such a case, you can compensate thiseffect by applying the following translations to HomMat2Dbefore using it in affine_trans_image
:
hom_mat2d_translate(HomMat2D, 0.5, 0.5, HomMat2DTmp) |
hom_mat2d_translate_local(HomMat2DTmp, -0.5, -0.5, HomMat2DAdapted) |
affine_trans_image(Image, ImageAffineTrans, HomMat2DAdapted, 'constant', 'false') |
For an explanation of the different 2D coordinate systemsused in HALCON, see the introduction of chapterTransformations / 2D Transformations.
运行信息
- Supports OpenCL compute devices.
- Multithreading type: reentrant (runs in parallel with non-exclusive operators).
- Multithreading scope: global (may be called from any thread).
- Automatically parallelized on tuple level.
- Automatically parallelized on channel level.
- Automatically parallelized on internal data level.
参数表
Image
(input_object) (multichannel-)image(-array) →
object (byte / int2 / uint2 / real)
Input image.
ImageAffineTrans
(output_object) (multichannel-)image(-array) →
object (byte / int2 / uint2 / real)
Transformed image.
HomMat2D
(input_control) hom_mat2d →
(real)
Input transformation matrix.
Interpolation
(input_control) string →
(string)
Type of interpolation.
Default: 'constant'
List of values: 'bicubic', 'bilinear', 'constant', 'nearest_neighbor', 'weighted'
AdaptImageSize
(input_control) string →
(string)
Adaption of size of result image.
Default: 'false'
List of values: 'false', 'true'
例程 (HDevelop)
* Reduction of an image (512 x 512 Pixels) by 50%, rotation* by 180 degrees and translation to the upper-left corner:read_image (Image, 'ic0')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,'constant','true')* Enlarging the part of an image in the interactively* chosen rectangular window sector:dev_get_window (WindowHandle)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,TransImage,Matrix4,'constant','true')
结果
If the matrix HomMat2D represents an affine transformation(i.e., not a projective transformation), affine_trans_image
returns 2 ( H_MSG_TRUE) . If the input is empty the behavior can be set viaset_system(::'no_object_result',<Result>:). If necessary,an exception is raised.
可能的前置算子
hom_mat2d_identity
, hom_mat2d_translate
, hom_mat2d_rotate
, hom_mat2d_scale
, hom_mat2d_reflect
可替代算子
affine_trans_image_size
, zoom_image_size
, zoom_image_factor
, mirror_image
, rotate_image
, affine_trans_region
参考其它
set_part_style
模块
Foundation
算子列表
HALCON算子参考手册 Copyright © 2015-2023 51Halcon