Python image Processing!

Source: Internet
Author: User

Welcome to join thousands of people Exchange Learning Group: 125240963

Third, some basic operation of the image

1. Output picture information (format, size and image type)

4. Rotate the picture

To rotate an image, you can use a counterclockwise representation of the rotation angle, and then call the Rotate () method:

After 45 degrees of rotation, it will be filled with the same size.

Rorate2:

Note: Only choose 90 degrees, 180 degrees and 270 degrees to use Img.transpose (image.rotate_90), other angles with ROTATE

Rorate4:

6. Zoom image

To adjust the size of an image, we can call the Resize () method. The parameter for this method is a tuple that specifies the size of the new image:

After running:

9. Cropping a picture

Use the crop () method to crop a specified area from an image:

    1. # coding=utf-8

    2. from PIL importImage

    3. # 读取图片

    4. img =Image.open(‘qq_image.jpg‘)

    5. # 裁剪图片 box为裁剪图片的区域范围

    6. box =(100,100,250,250)

    7. region = img.crop(box)

    8. region.show()

Run output:

Note: python specifies that the upper-left corner is a coordinate point (0, 0), and that the box is defined by a 4-tuple (left, top, right, bottom), represented as coordinates: (Ieft, Upper, R, Lower), and the last two digits must be larger than the previous two.

10. Paste the picture

To effect, crop a portion of the picture and rotate it, and finally paste it into the specified area:

Run:

Summarize:

If you need more powerful image manipulation, you can use the Matplotlib class library, which has more powerful drawing capabilities than PIL, such as a powerful bar chart, pie chart, scatter plot, and more.

Python image Processing!

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.