<link rel="stylesheet" href="https://js.how234.com/third-party/SyntaxHighlighter/shCoreDefault.css" type="text/css" /><script type="text/javascript" src="https://js.how234.com/third-party/SyntaxHighlighter/shCore.js"></script><script type="text/javascript"> SyntaxHighlighter.all(); </script>
python skimage是什麼呢?一起來看下吧:
scikit-image是基於scipy的一款圖像處理包,它將圖片作爲numpy數組進行處理,正好與matlab一樣,因此,我們最終選擇scikit-image進行數字圖像處理。
Image讀出來的是PIL的類型,而skimage.io讀出來的數據是numpy格式的
import Image as imgimport osfrom matplotlib import pyplot as plotfrom 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在單獨測試時要要在代碼中設定:transformer.set_transpose('data',(2,0,1)),因爲caffe可以處理的圖片的數據格式是(channel,height,width),所以要轉換數據]
#讀圖片後數據的大小:print "the picture's size: ", img_file1.sizeprint "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, dataimg = data.chelsea()io.imshow(img)print(type(img)) #顯示類型print(img.shape) #顯示尺寸print(img.shape[0]) #圖片高度print(img.shape[1]) #圖片寬度print(img.shape[2]) #圖片通道數print(img.size) #顯示總像素個數print(img.max()) #最大像素值print(img.min()) #最小像素值print(img.mean()) #像素平均值print(img[0][0])#圖像的像素值
skimage提供了io模組,顧名思義,這個模組是用來圖片輸入輸出操作的。爲了方便練習,也提供一個data模組,裏面嵌套了一些示例圖片,我們可以直接使用。