Image implementation in python image processing

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.