python skimage是什么呢?一起來看下吧:
scikit-image是基于scipy的一款圖像處理包,它將圖片作為numpy數(shù)組進(jìn)行處理,正好與matlab一樣,因此,我們最終選擇scikit-image進(jìn)行數(shù)字圖像處理。
Image讀出來的是PIL的類型,而skimage.io讀出來的數(shù)據(jù)是numpy格式的
import?Image?as?img import?os from?matplotlib?import?pyplot?as?plot from?skimage?import?io,transform #Image和skimage讀圖片 img_file1?=?img.open('./CXR_png/MCUCXR_0042_0.png') img_file2?=?io.imread('./CXR_png/MCUCXR_0042_0.png')
輸出可以看出Img讀圖片的大小是圖片的(width, height);而skimage的是(height,width, channel), [這也是為什么caffe在單獨(dú)測(cè)試時(shí)要要在代碼中設(shè)置:transformer.set_transpose('data',(2,0,1)),因?yàn)閏affe可以處理的圖片的數(shù)據(jù)格式是(channel,height,width),所以要轉(zhuǎn)換數(shù)據(jù)]
#讀圖片后數(shù)據(jù)的大小: print?"the?picture's?size:?",?img_file1.size print?"the?picture's?shape:?",?img_file2.shape
the?picture's?size:??(4892,?4020) the?picture's?shape:??(4020,?4892)
#得到像素: print(img_file1.getpixel((500,1000)),?img_file2[500][1000]) print(img_file1.getpixel((500,1000)),?img_file2[1000][500]) print(img_file1.getpixel((1000,500)),?img_file2[500][1000])
(0,?139) (0,?0) (139,?139)
如果我們想知道一些skimage圖片信息
from?skimage?import?io,?data img?=?data.chelsea() io.imshow(img) print(type(img))??#顯示類型 print(img.shape)??#顯示尺寸 print(img.shape[0])??#圖片高度 print(img.shape[1])??#圖片寬度 print(img.shape[2])??#圖片通道數(shù) print(img.size)???#顯示總像素個(gè)數(shù) print(img.max())??#最大像素值 print(img.min())??#最小像素值 print(img.mean())?#像素平均值 print(img[0][0])#圖像的像素值
skimage提供了io模塊,顧名思義,這個(gè)模塊是用來圖片輸入輸出操作的。為了方便練習(xí),也提供一個(gè)data模塊,里面嵌套了一些示例圖片,我們可以直接使用。
以上就是小編今天的分享,希望可以幫助到大家。