詳解python讀取image
python 讀取image
在python中我們有兩個(gè)庫可以處理圖像文件,scipy和matplotlib.
安裝庫
pip install matplotlib pillow scipy
用法
from scipy.misc import imread data = imread(image_root) #data是 ndarray對(duì)象
import matplotlib.image as mpimg data = mpimg.imread(image_root) #data是 ndarray對(duì)象
skimage
安裝 pip install -U scikit-image
from skimage.io import imread img = imread(file_path) # 返回的是 ndarray # 這里需要注意的是 # imread 讀取 8-bit png 的時(shí)候莫名奇妙的讀出個(gè) 3-channel 的圖片 # from scipy.misc import imread 這個(gè) imread 也是一個(gè)尿性
PIL
安裝 pip install pillow
from PIL import Image import numpy as np img_obj = Image.open(file_path) img_array = np.array(img_obj, dtype=np.uint8) # 無論是 jpg 還是 png 都能正確讀取 \
matplotlib
安裝 pip install matplotlib
from matplotlib.image import imread img = imread(img_path) # 返回 ndarray # 這個(gè)imread 讀 png 的時(shí)候,返回ndarray 的類型是 uint8 # 讀 png 的時(shí)候,返回 ndarray 是 float32, 8-bit png 也能讀出 3-channel,活在夢(mèng)里
以上所述是小編給大家介紹的python讀取image詳解整合,希望對(duì)大家有所幫助,如果大家有任何疑問請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!
- 對(duì)python PLT中的image和skimage處理圖片方法詳解
- Python圖像濾波處理操作示例【基于ImageFilter類】
- Python圖像的增強(qiáng)處理操作示例【基于ImageEnhance類】
- Python3實(shí)現(xiàn)轉(zhuǎn)換Image圖片格式
- Python讀取視頻的兩種方法(imageio和cv2)
- python使用Image處理圖片常用技巧分析
- 使用ImageMagick進(jìn)行圖片縮放、合成與裁剪(js+python)
- python使用pil進(jìn)行圖像處理(等比例壓縮、裁剪)實(shí)例代碼
- python圖像處理之反色實(shí)現(xiàn)方法
- Python圖像處理之識(shí)別圖像中的文字(實(shí)例講解)
- python圖像處理之鏡像實(shí)現(xiàn)方法
- Python Image模塊基本圖像處理操作小結(jié)
相關(guān)文章
python實(shí)現(xiàn)簡易猜數(shù)小游戲
大家好,本篇文章主要講的是python實(shí)現(xiàn)簡易猜數(shù)小游戲,感興趣的同學(xué)趕快來看一看吧,對(duì)你有幫助的話記得收藏一下,方便下次瀏覽2022-01-01
Pandas檢查dataFrame中的NaN實(shí)現(xiàn)
本文主要介紹了Pandas檢查dataFrame中的NaN實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2023-01-01
python 使用遞歸實(shí)現(xiàn)打印一個(gè)數(shù)字的每一位示例
今天小編就為大家分享一篇python 使用遞歸實(shí)現(xiàn)打印一個(gè)數(shù)字的每一位示例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2020-02-02

