This article mainly introduces the image implementation method of python image processing. The example analyzes the implementation principle and specific operation method of the image, for more information about how to implement python image processing, see the following example. Share it with you for your reference. The specific analysis is as follows:
Image changes do not change the image shape. There are three types of image transformations: horizontal image, vertical image, and diagonal image.
If the image size is M × N
Horizontal images can follow the formula
I = I
J = N-j + 1
Vertical images can follow the formula
I = M-I + 1
J = j
The diagonal image can be formatted as follows:
I = M-I + 1
J = N-j + 1
It is worth noting that the coordinates in OpenCV start from [0, 0 ].
Therefore, in the formula, + 1 needs to be changed to-1 during programming.
The running environment is as follows:
Python: Python2.7.6
OpenCV2.4.10 (available at http://sourceforge.net/projects/opencvlibrary/files/opencv-win)
Numpy is: numpy-1.9.1-win32-superpack-python2.7 (available at http://sourceforge.net/projects/numpy/files/numpy/1.9.1/download)
The following code uses baby Meitu as an example. the specific procedure is 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): 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)
Shows the running result:
I hope this article will help you with Python programming.