<a id="easyimage-geometric-transforms"></a>

# Geometric Transforms

* Geometric transformation moves selected pixels in an image, which is useful if a shape in an image is too large / small / distorted, to make point-to-point comparisons possible.
* The selected area may be any shape, but the resulting image is always rectangular. Pixels in the destination image that have corresponding pixels that are outside the selected area are considered not relevant and are left black.
* When the source coordinates for a destination pixel are not integer, an interpolation technique is required.
  * The nearest neighborhood method is the quickest - it uses the closest source pixel.
  * The bi-linear interpolation method is more accurate but slower - it uses a weighted average of the four neighboring source pixels.

<a id="easyimage-geometric-transforms-realignment"></a>

## Re-Alignment

The simplest way to realign two misaligned images is to accurately locate features in both images (landmarks or pivots, using pattern matching, point measurement or other) and realign one of the images so that these features are superimposed.

You can [`EasyImage::Register`](../../../doxygen_cpp/classeVision_1_1EasyImage.html#a71ce58e1fa46d3c04fc1fbf47d2b5ce6) [<sub>.NET</sub>](../../../doxygen_cs/classeVision_1_1EasyImage.html#a9bd5d28ce15ffc3a06ee9243bd87068d) [<sub>Python</sub>](../../../doxygen_python/classeVision_1_1EasyImage.html#a6e1bca51e08b85cd15061433919043cd) an image by realigning one, two or three pivot points to reference positions. For best accuracy, the pivot points should be as far apart as possible.

* A **single pivot point** transform is a simple translation. If interpolation bits are used, sub-pixel translation is achieved.
* **Two pivot points** use a combination of translation, rotation and optionally scaling. If scaling is not allowed, the second pivot point may not be matched exactly. Scaling should not normally be used unless it corresponds to a change of lens magnification or viewing distance.
* **Three pivot points** use a combination of translation, rotation, shear correction and optionally scaling. A shear effect can arise when acquiring images with a misaligned line-scan camera.

<a id="easyimage-geometric-transforms-mirroring"></a>

## Mirroring

This destructive feature modifies the source image to create a mirror image:

* [`EasyImage::HorizontalMirror`](../../../doxygen_cpp/classeVision_1_1EasyImage.html#a55a087adcc4be81386f4b749ea5ed65c) [<sub>.NET</sub>](../../../doxygen_cs/classeVision_1_1EasyImage.html#a548123aabbc38a5642b52d9c81a882ca) [<sub>Python</sub>](../../../doxygen_python/classeVision_1_1EasyImage.html#a32468146b512daa9cb8c9e9d08c1a2e3): the columns are swapped or
* [`EasyImage::VerticalMirror`](../../../doxygen_cpp/classeVision_1_1EasyImage.html#adc0935efdf220d502b57f7240a9bebc3) [<sub>.NET</sub>](../../../doxygen_cs/classeVision_1_1EasyImage.html#ae880cbfed7ca9a010dda4e9f93c7705d) [<sub>Python</sub>](../../../doxygen_python/classeVision_1_1EasyImage.html#a4dbe83730ad2de77149a71977cb1688e): the rows are swapped.

<a id="easyimage-geometric-transforms-resizing"></a>

## Resizing

If you need to resize an image, you can use the method [`EasyImage::Resize`](../../../doxygen_cpp/classeVision_1_1EasyImage.html#a0d5c968f1af25054be71e8d58971e307) [<sub>.NET</sub>](../../../doxygen_cs/classeVision_1_1EasyImage.html#a239560fe391abaf3761cf24de0bf3e77) [<sub>Python</sub>](../../../doxygen_python/classeVision_1_1EasyImage.html#a304de7e061e0900d890bf66257585a95), which resizes your image to the size of the destination image.

#### HINT
It is always faster than using the method [`EasyImage::ScaleRotate`](../../../doxygen_cpp/classeVision_1_1EasyImage.html#a8f2294863da8f51c43dc3da72e401953) [<sub>.NET</sub>](../../../doxygen_cs/classeVision_1_1EasyImage.html#a1109064fed71be45d77da6d46e891de2) [<sub>Python</sub>](../../../doxygen_python/classeVision_1_1EasyImage.html#a8b25eeb6d2c87bd1c48e99885055bb2b).

<a id="easyimage-geometric-transforms-scale-rotate"></a>

## Translation, Scaling and Rotation

To apply a transformation involving a scaling, rotation and translation, you can use [`EasyImage::ScaleRotate`](../../../doxygen_cpp/classeVision_1_1EasyImage.html#a8f2294863da8f51c43dc3da72e401953) [<sub>.NET</sub>](../../../doxygen_cs/classeVision_1_1EasyImage.html#a1109064fed71be45d77da6d46e891de2) [<sub>Python</sub>](../../../doxygen_python/classeVision_1_1EasyImage.html#a8b25eeb6d2c87bd1c48e99885055bb2b). In one call, it performs:

* Image translation: you provide the position coordinates of a pivot-point in the source image and a corresponding pivot point in the destination image.
* Image scaling: you provide scaling factor values for X- and Y-axis.
* Image rotation: you provide a rotation angle value.

For resampling, the nearest neighbor rule or bilinear interpolation with 4 or 8 bits of accuracy is used. The size of the destination image is arbitrary.

![](assets/images/easyimage/geometric_transformation/nearest_output.webp)![](assets/images/easyimage/geometric_transformation/nearest_roi.webp)![](assets/images/easyimage/geometric_transformation/linear_output.webp)![](assets/images/easyimage/geometric_transformation/linear_roi.webp)![](assets/images/easyimage/geometric_transformation/cubic_output.webp)![](assets/images/easyimage/geometric_transformation/cubic_roi.webp)

<a id="easyimage-geometric-transforms-shrink"></a>

## Shrink

[`EasyImage::Shrink`](../../../doxygen_cpp/classeVision_1_1EasyImage.html#addff91a1b47e6a41e681a55db95f77b3) [<sub>.NET</sub>](../../../doxygen_cs/classeVision_1_1EasyImage.html#a4a3259c39e6ea55516918f7ffc1ca23e) [<sub>Python</sub>](../../../doxygen_python/classeVision_1_1EasyImage.html#ab3a348c727d9140ddc30d9362c1c5cfa) resizes an image to be smaller, applying pre-filtering to avoid aliasing.

<a id="easyimage-geometric-transforms-lut-unwarp"></a>

## LUT-Based Unwarping

* If the feature of interest is distorted due to its shape (anamorphosized), you can unwarp a circular ring-wedge shape (such as text on CD labels) into a straight rectangle. A ring-wedge is delimited by two concentric circles and two straight lines passing through the center.
* [`EasyImage::SetCircleWarp`](../../../doxygen_cpp/classeVision_1_1EasyImage.html#a1925d9aec18e744330d2a4a66182f433) [<sub>.NET</sub>](../../../doxygen_cs/classeVision_1_1EasyImage.html#a27744b0fb553ab53f8666838c6ff7aa2) [<sub>Python</sub>](../../../doxygen_python/classeVision_1_1EasyImage.html#a1d845a6283a2260f873be571ee2ac850) prepares warp images for use with function [`EasyImage::Warp`](../../../doxygen_cpp/classeVision_1_1EasyImage.html#a79133ed6f4d53f4c7a4c36076acdf781) [<sub>.NET</sub>](../../../doxygen_cs/classeVision_1_1EasyImage.html#a5c764d59dd4b0b264aa90561557da68a) [<sub>Python</sub>](../../../doxygen_python/classeVision_1_1EasyImage.html#a7892094f5db6da5a4041e54cd5055abc) which moves each pixel to locations specified in the “warp” images which are used as lookup tables.
* To warp back the image to the circular ring:
  1. Use [`EasyImage::SetInvCircleWarp`](../../../doxygen_cpp/classeVision_1_1EasyImage.html#abbe7d38639110c634206a11a6d83194d) [<sub>.NET</sub>](../../../doxygen_cs/classeVision_1_1EasyImage.html#af8fcd9fcfbaa3672a8a68076cabf06f9) [<sub>Python</sub>](../../../doxygen_python/classeVision_1_1EasyImage.html#a3bce1e793a38b46ac81482368dab6123) with the same parameters as above.
  2. Use the method [`EasyImage::Warp`](../../../doxygen_cpp/classeVision_1_1EasyImage.html#a79133ed6f4d53f4c7a4c36076acdf781) [<sub>.NET</sub>](../../../doxygen_cs/classeVision_1_1EasyImage.html#a5c764d59dd4b0b264aa90561557da68a) [<sub>Python</sub>](../../../doxygen_python/classeVision_1_1EasyImage.html#a7892094f5db6da5a4041e54cd5055abc).
* Additionally, if the LUT-based unwarping is more peculiar:
  1. Use the method [`EasyImage::SetupInverseWarp`](../../../doxygen_cpp/classeVision_1_1EasyImage.html#a0a379a1af76ee26c4922e76dbcc474ba) [<sub>.NET</sub>](../../../doxygen_cs/classeVision_1_1EasyImage.html#a362425f01847a4f71dd4d9288edb27d5) [<sub>Python</sub>](../../../doxygen_python/classeVision_1_1EasyImage.html#ae8e2454ec796e1f3208bb12d8e959ab1) to inverse any inversible LUT
  2. Use it with the method [`EasyImage::Warp`](../../../doxygen_cpp/classeVision_1_1EasyImage.html#a79133ed6f4d53f4c7a4c36076acdf781) [<sub>.NET</sub>](../../../doxygen_cs/classeVision_1_1EasyImage.html#a5c764d59dd4b0b264aa90561557da68a) [<sub>Python</sub>](../../../doxygen_python/classeVision_1_1EasyImage.html#a7892094f5db6da5a4041e54cd5055abc).

<a id="easyimage-geometric-transforms-quick-links"></a>

## See Also

Easy to understand, ready to copy code snippets to use when resizing images.

Easy to understand, ready to copy code snippets to use when (un)warpping images.
