A method of image processing for Python images

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

  • Related Article

    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.