Python使用scipy保存圖片的一些注意點
首先我們載入一張灰度圖片,一般灰度圖片像素為0-255.
可以發(fā)現(xiàn)該圖片的最大像素為254,最小像素為2。一般處理圖片時會轉(zhuǎn)化為double類型。
我們將圖片使用scipy保存為pgm格式。
然后我們重新讀取該圖片信息。
其像素值發(fā)生了變化,自動標(biāo)準(zhǔn)化到了0-255范圍,最小值變?yōu)?,最大值變?yōu)?55.
所以,使用scipy保存圖像時,加上2個參數(shù),cmin和cmax。就可以了
重新讀取圖片。結(jié)果正確
補充:from scipy import misc 讀取和保存圖片
from scipy import misc
def imread(name, flatten=False, mode=None) pass """ 讀取一張圖片返回array,uint8,""" def imsave(name, arr, format=None): pass """ Save an array as an image. 自動的調(diào)用將圖片轉(zhuǎn)成0-255范圍內(nèi)的 arr : ndarray, MxN or MxNx3 or MxNx4 Array containing image values. If the shape is ``MxN``, the array represents a grey-level image. Shape ``MxNx3`` stores the red, green and blue bands along the last dimension. An alpha layer may be included, specified as the last colour band of an ``MxNx4`` array. """
注意上面對圖片讀取和保存的函數(shù)會被棄用,使用如下代替:
import imageio imageio.imread() imageio.imwrite()
以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持本站。
版權(quán)聲明:本站文章來源標(biāo)注為YINGSOO的內(nèi)容版權(quán)均為本站所有,歡迎引用、轉(zhuǎn)載,請保持原文完整并注明來源及原文鏈接。禁止復(fù)制或仿造本網(wǎng)站,禁止在非www.sddonglingsh.com所屬的服務(wù)器上建立鏡像,否則將依法追究法律責(zé)任。本站部分內(nèi)容來源于網(wǎng)友推薦、互聯(lián)網(wǎng)收集整理而來,僅供學(xué)習(xí)參考,不代表本站立場,如有內(nèi)容涉嫌侵權(quán),請聯(lián)系alex-e#qq.com處理。