9.Picture mirroring

There are two types of image mirroring transformation: horizontal mirroring and vertical mirroring. Horizontal mirroring takes the vertical centerline of the image as the axis and swaps the pixels of the image, that is, swapping the left and right halves of the image. Vertical mirroring takes the horizontal centerline of the image as the axis and swaps the upper and lower parts of the image.

Transformation principle: Let the width of the image be width and the length be height. (x,y) are the transformed coordinates, (x0,y0) are the coordinates of the original image

Horizontal mirror transformation

forward mapping

Its inverse transformation is

backward mapping

Vertical mirror transformation

Its inverse transformation is

Summary:

During horizontal mirror transformation, the entire image is traversed, and then each pixel is processed according to the mapping relationship. In fact, the horizontal mirror transformation is to change the image coordinate column to the right, and the right column to the left. The transformation can be done in column units. The same is true for vertical mirror transformation, which can be transformed in row units. Here we take vertical transformation as an example to see how Python is written:

Code path:muto/Samples/OpenCV/02_OpenCV Transform/04 Image mirroring.ipynb

You can see the mirror image from the picture.