skimage图像的读取与保存

首先,说明用opencv与skimage.io.imread读取和保存图片的区别:

读取和保存后的都是numpy格式,但cv2的读取和存储格式是BGR,而skimage的读取和存储格式是RGB。

1.读取图片:

#skimage读取图片
img=skimage.io.imread(file_dir, as_grey=False)

#imread读取图片,0:grey,1:color,默认:color
img=cv2.imread(file_dir,1)

image.io.imread用法:

image.io.imread(fname, as_gray=False, plugin=None, **plugin_args)[source]

Load an image from file.

Parameters

fnamestring

Image file name, e.g. test.jpg or URL.

as_graybool, optional

If True, convert color images to gray-scale (64-bit floats). Images that are already in gray-scale format are not converted.

pluginstr, optional

Name of plugin to use. By default, the different plugins are tried (starting with imageio) until a suitable candidate is found. If not given and fname is a tiff file, the tifffile plugin will be used.

Returns

img_arrayndarray

The different color bands/channels are stored in the third dimension, such that a gray-image is MxN, an RGB-image MxNx3 and an RGBA-image MxNx4.

Other Parameters

plugin_argskeywords

Passed to the given plugin.

2.存储图片

#skimge
skimage.io.imsave(file_dir, img)

#存储的时候保存为unit8格式
img=np.array(img,dtype=np.uint8)

#cv2
cv2.imwrite(file_dir,img)

注意:如果float类型用imsave()保存,需要数值在-1到1之间,否则会报错.如果一开始就是uint8,保存的时候就无需除以255,如:

img=np.array(img,dtype=np.uint8)

3.将像素值转换为[0,1]之间的数值.也就是给每一个像素值除以255.

  img_as_float32

  Convert an image to single-precision (32-bit) floating point format, with values in [0, 1].

skimage.img_as_float(skimage.io.imread(filename, as_grey=not color))

 

  • 6
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值