- Chúng tôi sẽ làm việc với mô -đun hình ảnh ở đây cung cấp một lớp cùng tên và cung cấp nhiều chức năng để hoạt động trên hình ảnh của chúng tôi. Để nhập mô -đun hình ảnh, mã của chúng tôi sẽ bắt đầu với dòng sau:
try
:
Hoạt động với hình ảnh:
Mở một hình ảnh cụ thể từ một đường dẫn:
sudo apt-get update
sudo apt-get install python-pip
4
img
=
Image.
open
____10: The instances of Image class that are created have many attributes, one of its useful attribute is size.sudo apt-get update
sudo apt-get install python-pip
1 sudo apt-get update
sudo apt-get install python-pip
2Lấy kích thước của hình ảnh: Các trường hợp của lớp hình ảnh được tạo có nhiều thuộc tính, một trong những thuộc tính hữu ích của nó là kích thước.
from PIL import Image
2open
from PIL import Image
4sudo apt-get update
sudo apt-get install python-pip
5 sudo apt-get update
sudo apt-get install python-pip
6sudo apt-get update
sudo apt-get install python-pip
7 sudo apt-get update
sudo apt-get install python-pip
8sudo apt-get update
sudo apt-get install python-pip
9=
from PIL import Image
1
from PIL import Image
6__ from PIL import Image
8To save any changes that you have made to the image file, we need to give path as well as image format.- Một số thuộc tính khác là: Image.width, Image.height, Image.Format, Image.info & NBSP; ETC. The image rotation needs angle as parameter to get the image rotated.
sudo apt-get update
sudo apt-get install python-pip
1 sudo apt-get update
sudo apt-get install python-pip
2Lấy kích thước của hình ảnh: Các trường hợp của lớp hình ảnh được tạo có nhiều thuộc tính, một trong những thuộc tính hữu ích của nó là kích thước.
try
try
7
sudo apt-get update
sudo apt-get install python-pip
5 sudo apt-get update
sudo apt-get install python-pip
6sudo apt-get update
sudo apt-get install python-pip
7 sudo apt-get update
sudo apt-get install python-pip
8sudo apt-get update
sudo apt-get install python-pip
9=
from PIL import Image
1try
8
3
4
5
from PIL import Image
6__ from PIL import Image
8try
8
sudo apt-get update
sudo apt-get install python-pip
4Một số thuộc tính khác là: Image.width, Image.height, Image.Format, Image.info & NBSP; ETC.
img
8
Lưu các thay đổi trong hình ảnh: Để lưu bất kỳ thay đổi nào bạn đã thực hiện vào tệp hình ảnh, chúng ta cần đưa ra đường dẫn cũng như định dạng hình ảnh.
As seen in the above code snippet, I have used a relative path where my image is located in the same directory as my python code file, an absolute path can be used as well. - Xoay hình ảnh: Xoay hình ảnh cần góc làm tham số để có hình ảnh được xoay. Image.crop(box) takes a 4-tuple (left, upper, right, lower) pixel coordinate, and returns a
rectangular region from the used image.
sudo apt-get update
sudo apt-get install python-pip
1 sudo apt-get update
sudo apt-get install python-pip
2Lấy kích thước của hình ảnh: Các trường hợp của lớp hình ảnh được tạo có nhiều thuộc tính, một trong những thuộc tính hữu ích của nó là kích thước.
try
try
7
sudo apt-get update
sudo apt-get install python-pip
5 sudo apt-get update
sudo apt-get install python-pip
6sudo apt-get update
sudo apt-get install python-pip
7 sudo apt-get update
sudo apt-get install python-pip
8sudo apt-get update
sudo apt-get install python-pip
9=
from PIL import Image
1
from PIL import Image
6__ from PIL import Image
8Một số thuộc tính khác là: Image.width, Image.height, Image.Format, Image.info & NBSP; ETC.
try
8
3
sudo apt-get update
sudo apt-get install python-pip
10:
5
from PIL import Image
6__ from PIL import Image
8try
8
sudo apt-get update
sudo apt-get install python-pip
4Một số thuộc tính khác là: Image.width, Image.height, Image.Format, Image.info & NBSP; ETC.
img
8
- Lưu các thay đổi trong hình ảnh: Để lưu bất kỳ thay đổi nào bạn đã thực hiện vào tệp hình ảnh, chúng ta cần đưa ra đường dẫn cũng như định dạng hình ảnh. Image.resize(size)- Here size is provided as a
2-tuple width and height.
sudo apt-get update
sudo apt-get install python-pip
1 sudo apt-get update
sudo apt-get install python-pip
2Lấy kích thước của hình ảnh: Các trường hợp của lớp hình ảnh được tạo có nhiều thuộc tính, một trong những thuộc tính hữu ích của nó là kích thước.
try
try
7
sudo apt-get update
sudo apt-get install python-pip
5 sudo apt-get update
sudo apt-get install python-pip
6sudo apt-get update
sudo apt-get install python-pip
7 sudo apt-get update
sudo apt-get install python-pip
8sudo apt-get update
sudo apt-get install python-pip
9=
from PIL import Image
1
from PIL import Image
6__ from PIL import Image
8try
8
3
sudo apt-get update
sudo apt-get install python-pip
58:
5
from PIL import Image
6__ from PIL import Image
8try
8
sudo apt-get update
sudo apt-get install python-pip
4Một số thuộc tính khác là: Image.width, Image.height, Image.Format, Image.info & NBSP; ETC.
img
8
- Lưu các thay đổi trong hình ảnh: Để lưu bất kỳ thay đổi nào bạn đã thực hiện vào tệp hình ảnh, chúng ta cần đưa ra đường dẫn cũng như định dạng hình ảnh. The second argument can be a 2-tuple (specifying the top left corner), or a 4-tuple (left, upper, right, lower) – in this case the
size of pasted image must match the size of this box region, or None which is equivalent to (0, 0).
sudo apt-get update
sudo apt-get install python-pip
1 sudo apt-get update
sudo apt-get install python-pip
2Lấy kích thước của hình ảnh: Các trường hợp của lớp hình ảnh được tạo có nhiều thuộc tính, một trong những thuộc tính hữu ích của nó là kích thước.
try
try
7
sudo apt-get update
sudo apt-get install python-pip
5 sudo apt-get update
sudo apt-get install python-pip
6sudo apt-get update
sudo apt-get install python-pip
7 sudo apt-get update
sudo apt-get install python-pip
8sudo apt-get update
sudo apt-get install python-pip
9=
from PIL import Image
1try
8
sudo apt-get update
sudo apt-get install python-pip
99 from PIL import Image
00open
5 from PIL import Image
00sudo apt-get update
sudo apt-get install python-pip
55try
8
3
from PIL import Image
06
5
from PIL import Image
6__ from PIL import Image
8Một số thuộc tính khác là: Image.width, Image.height, Image.Format, Image.info & NBSP; ETC.
Một số thuộc tính khác là: Image.width, Image.height, Image.Format, Image.info & NBSP; ETC.
img
8
- Lưu các thay đổi trong hình ảnh: Để lưu bất kỳ thay đổi nào bạn đã thực hiện vào tệp hình ảnh, chúng ta cần đưa ra đường dẫn cũng như định dạng hình ảnh. This will return a histogram of the image as a list of
pixel counts, one for each pixel in the image. (A histogram of an image is a graphical representation of the tonal distribution in a digital image. It contains what all the brightness values contained in an image are. It plots the number of pixels for each brightness value. It helps in doing the exposure settings.)
from PIL import Imagetry
3 try
4
try
try
7
try
8try
9=
try
8
from PIL import Image
35 from PIL import Image
36
sudo apt-get update
sudo apt-get install python-pip
1 sudo apt-get update
sudo apt-get install python-pip
2try
8
sudo apt-get update
sudo apt-get install python-pip
4img
1 img
2______7 img
5try
7
img
8
- Chuyển hình ảnh: Tính năng này cho chúng ta hình ảnh phản chiếu của hình ảnhThis feature gives us the mirror image of an image
sudo apt-get update
sudo apt-get install python-pip
5 sudo apt-get update
sudo apt-get install python-pip
6sudo apt-get update
sudo apt-get install python-pip
7 sudo apt-get update
sudo apt-get install python-pip
8try
3 try
4
try
try
7
try
8try
9=
try
8
from PIL import Image
35 from PIL import Image
36try
8
from PIL import Image
73 from PIL import Image
74
5
sudo apt-get update
sudo apt-get install python-pip
1 sudo apt-get update
sudo apt-get install python-pip
2try
8
sudo apt-get update
sudo apt-get install python-pip
4img
1 img
2______7 img
5try
7
img
8
- Chuyển hình ảnh: Tính năng này cho chúng ta hình ảnh phản chiếu của hình ảnhSplitting an image in RGB mode, creates three new images each containing a copy of the original individual bands.
sudo apt-get update
sudo apt-get install python-pip
5 sudo apt-get update
sudo apt-get install python-pip
6sudo apt-get update
sudo apt-get install python-pip
7 sudo apt-get update
sudo apt-get install python-pip
8try
3 try
4
try
try
7
try
8try
9=
try
8
from PIL import Image
35 from PIL import Image
36
sudo apt-get update
sudo apt-get install python-pip
1 sudo apt-get update
sudo apt-get install python-pip
2try
8
sudo apt-get update
sudo apt-get install python-pip
4img
1 img
2______7 img
5try
7
img
8
- Chuyển hình ảnh: Tính năng này cho chúng ta hình ảnh phản chiếu của hình ảnh Converting an image to an X11 bitmap (A plain text binary image format). It returns a string containing an X11 bitmap, it can only be used for mode “1” images, i.e. 1 bit pixel black and white
images.
from PIL import Imagetry
3 try
4
try
try
7
try
8try
9=
try
8
from PIL import Image
35 from PIL import Image
36
sudo apt-get update
sudo apt-get install python-pip
1 sudo apt-get update
sudo apt-get install python-pip
2img
1 img
2______7 img
5try
7
sudo apt-get update
sudo apt-get install python-pip
1 sudo apt-get update
sudo apt-get install python-pip
2try
8
sudo apt-get update
sudo apt-get install python-pip
4img
1 img
2______7 img
5try
7
img
8
- Chuyển hình ảnh: Tính năng này cho chúng ta hình ảnh phản chiếu của hình ảnh This method creates a thumbnail of the image that is opened. It does not return a new image object, it makes in-place modification to the currently opened image object itself. If you do not want to change the original image object, create a copy and then apply this method. This method also evaluates the appropriate to maintain the aspect ratio of the image according to the size passed.
from PIL import Imagetry
3 try
4
sudo apt-get update
sudo apt-get install python-pip
5 sudo apt-get update
sudo apt-get install python-pip
6sudo apt-get update
sudo apt-get install python-pip
7 sudo apt-get update
sudo apt-get install python-pip
8try
8try
9=
try
8try
72try
73open
5try
73try
76
try
8
3try
79
5
sudo apt-get update
sudo apt-get install python-pip
1 sudo apt-get update
sudo apt-get install python-pip
2try
8
sudo apt-get update
sudo apt-get install python-pip
4img
1 img
2______7 img
5try
7
img
8