【Python】圖像數據讀寫利器 -- imageio

Backto Python Index

極簡化的圖像數據讀寫庫,官方文檔 .

兩大特性

  1. 依賴少
Python 3.5+
Numpy
Pillow

有擴展包,歷史版本 Imageio version 2.6.x supports Python 2.7 and 3.4.

  1. 接口簡潔
import imageio
im = imageio.imread('imageio:chelsea.png')  # read a standard image
im.shape  # im is a numpy array
>> (300, 451, 3)
imageio.imwrite('~/chelsea-gray.jpg', im[:, :, 0])

API style

imread() and imwrite() - for single images
mimread() and mimwrite() - for image series (animations)
volread() and volwrite() - for volumetric image data
get_reader() and get_writer() - for more control (e.g. streaming or compression)
See the user api for more information

最近 ImageIO 的應用越來越廣泛,一大原因就是 scipy.misc.imread is deprecated! imread is deprecated in SciPy 1.0.0, and will be removed in 1.2.0. Use imageio.imread instead

# old
#import scipy.misc 
#input_image = imread(IMG_PATH) 

# new
import imageio
input_image = imageio.imread(IMG_PATH)
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章