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:
# coding=utf-8
from PIL importImage
# 读取图片
img =Image.open(‘qq_image.jpg‘)
# 裁剪图片 box为裁剪图片的区域范围
box =(100,100,250,250)
region = img.crop(box)
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!