Mirror implementation method in python

PHPz
Release: 2017-04-02 13:50:07
Original
5503 people have browsed it

Mirroring changes to the image do not change the shape of the image. There are three types of mirror transformations of images: horizontal mirroring, vertical mirroring, and diagonal mirroring

Suppose the size of the image is M×N, then

Horizontal mirroring can be done according to the formula

I = i

J = N - j + 1

The vertical mirror can be calculated according to the formula

I = M - i + 1

J = j

The diagonal mirror can be calculated according to the formula

I = M - i + 1

J = N - j + 1

It is worth noting that in OpenCV The coordinates start from [0,0]

So, the +1 in the formula needs to be changed to -1 when programming

#The running environment here is:

Python is: Python2.7.6
OpenCV2.4.10 version
numpy is: numpy-1.9.1-win32-superpack-python2.7

The following The code still takes baby pictures as an example. The specific procedure is as follows:

import cv2.cv as cv
image = cv.LoadImage('angelababy.jpg',1)
size = (image.width,image.height)
iUD = cv.CreateImage(size,image.depth,image.nChannels)
iLR = cv.CreateImage(size,image.depth,image.nChannels)
iAcross = cv.CreateImage(size,image.depth,image.nChannels)
h = image.height
w = image.width
for i in range(h):
  for j in range(w):
    iUD[h-1-i,j] = image[i,j]
    iLR[i,w-1-j] = image[i,j]
    iAcross[h-1-i,w-1-j] = image[i,j]
cv.ShowImage('image',image)
cv.ShowImage('iUD',iUD)
cv.ShowImage('iLR',iLR)
cv.ShowImage('iAcross',iAcross)
cv.WaitKey(0)
Copy after login

Mirror implementation method in python

The above is the detailed content of Mirror implementation method in python. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!