In this paper, we describe the image processing method of Python. Share to everyone for your reference. The specific analysis is as follows:
Image changes do not change the shape of the image. Image transformation is divided into three kinds: horizontal mirror, vertical mirror, diagonal mirror
Set the image size to MXN, the
Horizontal mirroring can be by formula
i = i
J = n-j + 1
Vertical mirroring can be by formula
I = m-i + 1
j = J
Diagonal mirrors can be by formula
I = m-i + 1
J = n-j + 1
It is important to note that in OpenCV the coordinates start with [0,0].
So, the +1 in the formula needs to be changed to-1 when programming
Here the operating environment is:
Python is: Python2.7.6
Version OpenCV2.4.10 (available to http://sourceforge.net/projects/opencvlibrary/files/opencv-win/download)
NumPy: numpy-1.9.1-win32-superpack-python2.7 (available to http://sourceforge.net/projects/numpy/files/NumPy/1.9.1/download)
The following code still takes baby beauty as an example of a specific program as follows:
Import CV2.CV as Cvimage = 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.heightw = Image.widthfor i in range (h): to 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)
The results of the operation are as follows:
Hopefully this article will help you with Python programming.