关闭→
当前位置:科普经验站>IT科技>skimage python

skimage python

科普经验站 人气:1.48W

<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模块,里面嵌套了一些示例图片,我们可以直接使用。

python skimage

TAG标签:#Python #skimage #