ClassesClassesClassesClasses | | | | Operators

affine_trans_image_sizeT_affine_trans_image_sizeAffineTransImageSizeaffine_trans_image_sizeAffineTransImageSizeAffineTransImageSize (Operator)


affine_trans_image_sizeT_affine_trans_image_sizeAffineTransImageSizeaffine_trans_image_sizeAffineTransImageSizeAffineTransImageSize — Apply an arbitrary affine 2D transformation to an image and specify the output image size.


affine_trans_image_size(Image : ImageAffinTrans : HomMat2D, Interpolation, Width, Height : )

Herror T_affine_trans_image_size(const Hobject Image, Hobject* ImageAffinTrans, const Htuple HomMat2D, const Htuple Interpolation, const Htuple Width, const Htuple Height)

Herror affine_trans_image_size(Hobject Image, Hobject* ImageAffinTrans, const HTuple& HomMat2D, const HTuple& Interpolation, const HTuple& Width, const HTuple& Height)

HImage HImage::AffineTransImageSize(const HTuple& HomMat2D, const HTuple& Interpolation, const HTuple& Width, const HTuple& Height) const

HImageArray HImageArray::AffineTransImageSize(const HTuple& HomMat2D, const HTuple& Interpolation, const HTuple& Width, const HTuple& Height) const

void AffineTransImageSize(const HObject& Image, HObject* ImageAffinTrans, const HTuple& HomMat2D, const HTuple& Interpolation, const HTuple& Width, const HTuple& Height)

HImage HImage::AffineTransImageSize(const HHomMat2D& HomMat2D, const HString& Interpolation, Hlong Width, Hlong Height) const

HImage HImage::AffineTransImageSize(const HHomMat2D& HomMat2D, const char* Interpolation, Hlong Width, Hlong Height) const

HImage HHomMat2D::AffineTransImageSize(const HImage& Image, const HString& Interpolation, Hlong Width, Hlong Height) const

HImage HHomMat2D::AffineTransImageSize(const HImage& Image, const char* Interpolation, Hlong Width, Hlong Height) const

void HOperatorSetX.AffineTransImageSize(
[in] IHUntypedObjectX* Image, [out] IHUntypedObjectX*ImageAffinTrans, [in] VARIANT HomMat2d, [in] VARIANT Interpolation, [in] VARIANT Width, [in] VARIANT Height)

IHImageX* HImageX.AffineTransImageSize(
[in] IHHomMat2DX* HomMat2d, [in] BSTR Interpolation, [in] Hlong Width, [in] Hlong Height)

IHImageX* HHomMat2DX.AffineTransImageSize(
[in] IHImageX* Image, [in] BSTR Interpolation, [in] Hlong Width, [in] Hlong Height)

static void HOperatorSet.AffineTransImageSize(HObject image, out HObject imageAffinTrans, HTuple homMat2D, HTuple interpolation, HTuple width, HTuple height)

HImage HImage.AffineTransImageSize(HHomMat2D homMat2D, string interpolation, int width, int height)

HImage HHomMat2D.AffineTransImageSize(HImage image, string interpolation, int width, int height)


affine_trans_image_sizeaffine_trans_image_sizeAffineTransImageSizeaffine_trans_image_sizeAffineTransImageSizeAffineTransImageSize applies an arbitrary affine 2D transformation, i.e., scaling, rotation, translation, and slant (skewing), to the images given in ImageImageImageImageImageimage and returns the transformed images in ImageAffinTransImageAffinTransImageAffinTransImageAffinTransImageAffinTransimageAffinTrans. The affine transformation is described by the homogeneous transformation matrix given in HomMat2DHomMat2DHomMat2DHomMat2DHomMat2DhomMat2D, which can be created using the operators hom_mat2d_identityhom_mat2d_identityHomMat2dIdentityhom_mat2d_identityHomMat2dIdentityHomMat2dIdentity, hom_mat2d_scalehom_mat2d_scaleHomMat2dScalehom_mat2d_scaleHomMat2dScaleHomMat2dScale, hom_mat2d_rotatehom_mat2d_rotateHomMat2dRotatehom_mat2d_rotateHomMat2dRotateHomMat2dRotate, hom_mat2d_translatehom_mat2d_translateHomMat2dTranslatehom_mat2d_translateHomMat2dTranslateHomMat2dTranslate, etc., or be the result of operators like vector_angle_to_rigidvector_angle_to_rigidVectorAngleToRigidvector_angle_to_rigidVectorAngleToRigidVectorAngleToRigid.

The components of the homogeneous transformation matrix are interpreted as follows: The row coordinate of the image corresponds to x and the column coordinate corresponds to y of the coordinate system in which the transformation matrix was defined. 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 InterpolationInterpolationInterpolationInterpolationInterpolationinterpolation:


Nearest-neighbor interpolation: The gray value is determined from the nearest pixel's gray value (possibly low quality, very fast).


Bilinear interpolation. The gray value is determined from the four nearest pixels through bilinear interpolation. If the affine transformation contains a scaling with a scale factor < 1, no smoothing is performed, which may cause severe aliasing effects (medium quality and run time).


Bilinear interpolation. The gray value is determined from the four nearest pixels through bilinear interpolation. If the affine transformation contains a scaling with a scale factor < 1, a kind of mean filter is used to prevent aliasing effects (medium quality and run time).


Bilinear interpolation. The gray value is determined from the four nearest pixels through bilinear interpolation. If the affine transformation contains a scaling with a scale factor < 1, a kind of Gaussian filter is used to prevent aliasing effects (best quality, slow).

In addition, the system parameter 'int_zooming'"int_zooming""int_zooming""int_zooming""int_zooming""int_zooming" (see set_systemset_systemSetSystemset_systemSetSystemSetSystem) affects the accuracy of the transformation. If 'int_zooming'"int_zooming""int_zooming""int_zooming""int_zooming""int_zooming" is set to 'true'"true""true""true""true""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'"int_zooming""int_zooming""int_zooming""int_zooming""int_zooming" = 'false'"false""false""false""false""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. Additionally, if a large scale factor is applied and a large output image is obtained, then undefined gray values at the lower and at the right image border may result. The maximum width B_max of this border of undefined gray values can be estimated as B_max = 0.5 * S * I / 2^15, where S is the scale factor in one dimension and I is the size of the output image in the corresponding dimension. For real images, the parameter 'int_zooming'"int_zooming""int_zooming""int_zooming""int_zooming""int_zooming" does not affect the accuracy, since the internal calculations are always done using floating point arithmetic.

The size of the target image is specifed by the parameters WidthWidthWidthWidthWidthwidth and HeightHeightHeightHeightHeightheight. Note that 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. If the affine transformation (in particular, the translation) is chosen appropriately, a part of the image can be transformed as well as cropped in one call. This is useful, for example, when using the variation model (see compare_variation_modelcompare_variation_modelCompareVariationModelcompare_variation_modelCompareVariationModelCompareVariationModel), because with this mechanism only the parts of the image that should be examined, are transformed.


The region of the input image is ignored.

affine_trans_image_sizeaffine_trans_image_sizeAffineTransImageSizeaffine_trans_image_sizeAffineTransImageSizeAffineTransImageSize does not use the HALCON standard coordinate system (with the origin in the center of the upper left pixel), but instead uses the same coordinate system as in affine_trans_pixelaffine_trans_pixelAffineTransPixelaffine_trans_pixelAffineTransPixelAffineTransPixel, i.e., the origin lies in the upper left corner of the upper left pixel. Therefore, applying affine_trans_image_sizeaffine_trans_image_sizeAffineTransImageSizeaffine_trans_image_sizeAffineTransImageSizeAffineTransImageSize corresponds to a chain of transformations (see affine_trans_pixelaffine_trans_pixelAffineTransPixelaffine_trans_pixelAffineTransPixelAffineTransPixel), which is applied to each point of the image (input and output pixels as homogeneous vectors). As an effect, you might get unexpected results when creating affine transformations based on coordinates that are derived from the image, e.g., by operators like area_center_grayarea_center_grayAreaCenterGrayarea_center_grayAreaCenterGrayAreaCenterGray. For example, if you use this operator to calculate the center of gravity of a rotationally symmetric image and then rotate the image around this point using hom_mat2d_rotatehom_mat2d_rotateHomMat2dRotatehom_mat2d_rotateHomMat2dRotateHomMat2dRotate, the resulting image will not lie on the original one. In such a case, you can compensate this effect by applying the following translations to HomMat2DHomMat2DHomMat2DHomMat2DHomMat2DhomMat2D before using it in affine_trans_image_sizeaffine_trans_image_sizeAffineTransImageSizeaffine_trans_image_sizeAffineTransImageSizeAffineTransImageSize:

  hom_mat2d_translate(HomMat2D, 0.5, 0.5, HomMat2DTmp)
  hom_mat2d_translate_local(HomMat2DTmp, -0.5, -0.5, HomMat2DAdapted)
  affine_trans_image_size(Image, ImageAffinTrans, HomMat2DAdapted,
	                    'constant', Width, Height)



ImageImageImageImageImageimage (input_object)  (multichannel-)image(-array) objectHImageHImageHImageHImageXHobject (byte / int2 / uint2 / real)

Input image.

ImageAffinTransImageAffinTransImageAffinTransImageAffinTransImageAffinTransimageAffinTrans (output_object)  (multichannel-)image(-array) objectHImageHImageHImageHImageXHobject * (byte / int2 / uint2 / real)

Transformed image.

HomMat2DHomMat2DHomMat2DHomMat2DHomMat2DhomMat2D (input_control)  hom_mat2d HHomMat2D, HTupleHTupleHTupleHHomMat2DX, VARIANTHtuple (real) (double) (double) (double) (double) (double)

Input transformation matrix.

InterpolationInterpolationInterpolationInterpolationInterpolationinterpolation (input_control)  string HTupleHTupleHTupleVARIANTHtuple (string) (string) (HString) (char*) (BSTR) (char*)

Type of interpolation.

Default value: 'constant' "constant" "constant" "constant" "constant" "constant"

List of values: 'bilinear'"bilinear""bilinear""bilinear""bilinear""bilinear", 'constant'"constant""constant""constant""constant""constant", 'nearest_neighbor'"nearest_neighbor""nearest_neighbor""nearest_neighbor""nearest_neighbor""nearest_neighbor", 'weighted'"weighted""weighted""weighted""weighted""weighted"

WidthWidthWidthWidthWidthwidth (input_control)  extent.x HTupleHTupleHTupleVARIANTHtuple (integer) (int / long) (Hlong) (Hlong) (Hlong) (Hlong)

Width of the output image.

Default value: 640

Suggested values: 128, 160, 192, 256, 320, 384, 512, 640, 768

HeightHeightHeightHeightHeightheight (input_control)  extent.y HTupleHTupleHTupleVARIANTHtuple (integer) (int / long) (Hlong) (Hlong) (Hlong) (Hlong)

Height of the output image.

Default value: 480

Suggested values: 120, 128, 144, 240, 256, 288, 480, 512, 576


If the matrix HomMat2DHomMat2DHomMat2DHomMat2DHomMat2DhomMat2D represents an affine transformation (i.e., not a projective transformation), affine_trans_image_sizeaffine_trans_image_sizeAffineTransImageSizeaffine_trans_image_sizeAffineTransImageSizeAffineTransImageSize returns 2 (H_MSG_TRUE). If the input is empty the behavior can be set via set_system(::'no_object_result',<Result>:)set_system("no_object_result",<Result>)SetSystem("no_object_result",<Result>)set_system("no_object_result",<Result>)SetSystem("no_object_result",<Result>)SetSystem("no_object_result",<Result>). If necessary, an exception is raised.

Possible Predecessors

hom_mat2d_identityhom_mat2d_identityHomMat2dIdentityhom_mat2d_identityHomMat2dIdentityHomMat2dIdentity, hom_mat2d_translatehom_mat2d_translateHomMat2dTranslatehom_mat2d_translateHomMat2dTranslateHomMat2dTranslate, hom_mat2d_rotatehom_mat2d_rotateHomMat2dRotatehom_mat2d_rotateHomMat2dRotateHomMat2dRotate, hom_mat2d_scalehom_mat2d_scaleHomMat2dScalehom_mat2d_scaleHomMat2dScaleHomMat2dScale, hom_mat2d_reflecthom_mat2d_reflectHomMat2dReflecthom_mat2d_reflectHomMat2dReflectHomMat2dReflect


affine_trans_imageaffine_trans_imageAffineTransImageaffine_trans_imageAffineTransImageAffineTransImage, zoom_image_sizezoom_image_sizeZoomImageSizezoom_image_sizeZoomImageSizeZoomImageSize, zoom_image_factorzoom_image_factorZoomImageFactorzoom_image_factorZoomImageFactorZoomImageFactor, mirror_imagemirror_imageMirrorImagemirror_imageMirrorImageMirrorImage, rotate_imagerotate_imageRotateImagerotate_imageRotateImageRotateImage, affine_trans_regionaffine_trans_regionAffineTransRegionaffine_trans_regionAffineTransRegionAffineTransRegion

See also




ClassesClassesClassesClasses | | | | Operators