详解python读取image
python读取image
在python中我们有两个库可以处理图像文件,scipy和matplotlib.
安装库
pipinstallmatplotlibpillowscipy
用法
fromscipy.miscimportimread data=imread(image_root) #data是ndarray对象
importmatplotlib.imageasmpimg data=mpimg.imread(image_root) #data是ndarray对象
skimage
安装pipinstall-Uscikit-image
fromskimage.ioimportimread img=imread(file_path)#返回的是ndarray #这里需要注意的是 #imread读取8-bitpng的时候莫名奇妙的读出个3-channel的图片 #fromscipy.miscimportimread这个imread也是一个尿性
PIL
安装pipinstallpillow
fromPILimportImage importnumpyasnp img_obj=Image.open(file_path) img_array=np.array(img_obj,dtype=np.uint8) #无论是jpg还是png都能正确读取 \
matplotlib
安装pipinstallmatplotlib
frommatplotlib.imageimportimread img=imread(img_path)#返回ndarray #这个imread读png的时候,返回ndarray的类型是uint8 #读png的时候,返回ndarray是float32,8-bitpng也能读出3-channel,活在梦里
以上所述是小编给大家介绍的python读取image详解整合,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对毛票票网站的支持!
热门推荐
6 祝福语简短的微信
10 朝鲜元旦祝福语大全简短
11 学校生日祝福语简短独特
12 新年简短祝福语给亲人
13 生日祝福语 简短独特潮
14 孙子生日祝福语简短精辟
15 简短搞笑蛋糕生日祝福语
16 闺蜜小孩祝福语简短
17 宝贝生日祝福语简短独特
18 回归岗位文案祝福语简短