Home  >  Article  >  Backend Development  >  How to output pictures in python

How to output pictures in python

(*-*)浩
(*-*)浩Original
2019-06-28 11:54:1026462browse

Therefore, we use the python language here for digital image processing.

To use python, you must first install python, usually version 2.7 or above. Whether it is a windows system or a linux system, the installation is very simple.

How to output pictures in python

#To use python for various development, you must install the corresponding library. (Recommended learning: Python video tutorial)

This is very similar to matlab, except that it is called a toolbox in matlab, and it is called a library or package in python. To install these libraries, you usually use pip to install them.

To use python for digital image processing, you must also install the Pillow package. Although python comes with a PIL (python images library), this library has stopped being updated, so Pillow is used, which is developed from PIL.

Opening and displaying images

from PIL import Image
img=Image.open('d:/dog.png')
img.show()

Although Pillow is used, it is forked from PIL, so it still needs to be imported from PIL . Use the open() function to open the image and the show() function to display the image.

This method of displaying images is to call the image browser that comes with the operating system to open the image. Sometimes this method is not convenient, so we can also use another method. , and let the program draw the picture.

from PIL import Image
import matplotlib.pyplot as plt
img=Image.open('d:/dog.png')
plt.figure("dog")
plt.imshow(img)
plt.show()

Although this method is a bit more complicated, it is recommended. It uses a matplotlib library to draw pictures for display. matplotlib is a professional drawing library, equivalent to plot in matlab. You can set multiple figures, set the title of the figure, and even use subplot to display multiple pictures in one figure.

For more Python related technical articles, please visit the Python Tutorial column to learn!

The above is the detailed content of How to output pictures in python. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn