📅  最后修改于: 2023-12-03 15:34:04.404000             🧑  作者: Mango
Python is a powerful programming language widely used in various domains. It has many libraries that allow easy creation and manipulation of different file formats, including images. In this article, we will explore how to show a PNG image in Python using some of the popular libraries.
Pillow is a popular Python library for image processing. It allows us to open, create, and manipulate various image formats. To show a PNG image using the Pillow library, we need to follow these steps:
from PIL import Image
from IPython.display import display
img = Image.open('sample.png')
display(img)
Matplotlib is a popular Python library for creating high-quality scientific visualizations. It has a submodule called pyplot, which provides a user-friendly interface to create various charts and plots. To show a PNG image using Matplotlib, we need to follow these steps:
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
img = mpimg.imread('sample.png')
plt.imshow(img)
plt.show()
In this article, we have explored how to show a PNG image in Python using the Pillow and Matplotlib libraries. It is essential to have prior knowledge about these libraries to efficiently use them for image processing tasks.