Python wants to call the image processing function. You need to import a library with image processing functions first. For example, PIL (Python Imaging Library, image processing library), Matplotlib library, NumPy library, SciPy library, etc.
When dealing with mathematics and drawing or drawing points, straight lines, and curves on images, Matplotlib is a good drawing library. It is better than The PIL library provides more powerful features.
The NumPy library is another core data science module for Python (just like NumPy) that can be used for basic image processing and processing tasks. (Recommended learning: Python Video Tutorial)
SciPy library is one of the core libraries in Python and provides support for arrays. Images are essentially standard NumPy arrays containing the pixels of data points.
Here we mainly introduce the most commonly used PIL library.
PIL (Python Imaging Library, image processing library) provides general image processing functions, as well as a large number of useful basic image operations. The PIL library has been integrated into the Anaconda library. It is recommended to use Anaconda. It is simple and convenient, and all commonly used libraries have been integrated.
Example:
from PIL import Image from pylab import * # 添加中文字体支持 from matplotlib.font_manager import FontProperties font = FontProperties(fname=r"c:\windows\fonts\SimSun.ttc", size=14) figure() pil_im = Image.open('E:\python\Python Computer Vision\Image data\empire.jpg') gray() subplot(121) title(u'原图',fontproperties=font) axis('off') imshow(pil_im) pil_im = Image.open('E:\python\Python Computer Vision\Image data\empire.jpg').convert('L') subplot(122) title(u'灰度图',fontproperties=font) axis('off') imshow(pil_im) show()
For more Python-related technical articles, please visit the Python Tutorial column to learn!
The above is the detailed content of How to call image processing in python. For more information, please follow other related articles on the PHP Chinese website!