当前位置:   article > 正文

踩坑:skimage中对图像做的归一化处理_skimage.img_as_float报错

skimage.img_as_float报错

 skimage在读使用io.imread读取灰度图像时(as_grey=True / as_gray=True)会做归一化处理数据类型转化为float64;

图像缩放transform.resize同样会将uint8的图像转化为float64类型,这里注意的是!!!!!!!如果已经归一化,但是类型依然是uint8的图像,在缩放之后图像的范围将不再是(0-1)。

总结:skimage需要慎用,cv2,PIL都挺好用的!

  1. import skimage
  2. from skimage import io,transform
  3. import numpy as np
  4. image= io.imread('test.jpg',as_grey=False)
  5. # 第一个参数是文件名可以是网络地址,第二个参数默认为False,True时为灰度图
  6. print type(image) # out: numpy.ndarray
  7. print image.dtype # out: dtype('uint8')
  8. print image.shape # out: (300, 400, 3) (h,w,c)前面介绍了ndarray的特点
  9. # mode也是RGB
  10. print image
  11. '''
  12. 注意此时image里都是整数uint8,范围[0-255]
  13. array([
  14. [ [143, 198, 201 (dim=3)],[143, 198, 201],... (w=200)],
  15. [ [143, 198, 201],[143, 198, 201],... ],
  16. ...(h=100)
  17. ], dtype=uint8)
  18. '''
  19. image= io.imread('test.jpg',as_grey=True)
  20. print image.shape # out: (300, 400)
  21. print image
  22. '''
  23. 此时image范围变为[0-1]
  24. array([[ 0.73148549, 0.73148549, 0.73148549, ..., 0.73148549,
  25. 0.73148549, 0.73148549],
  26. [ 0.73148549, 0.73148549, 0.73148549, ..., 0.73148549,
  27. .....]])
  28. '''
  29. print image.dtype # out: dtype('float64')
  30. image = io.imread('test.jpg',as_grey=False)
  31. # h*w
  32. image = transform.resize(image,(100, 200),order=1) # order默认是1,双线性
  33. #resize后image范围又变成[0-1]
  34. print image.dtype # out: dtype('float64')
  35. print image.shape # out: (100, 200, 3)
  36. print image
  37. '''
  38. array([[[ 0.56078431, 0.77647059, 0.78823529],
  39. [ 0.56078431, 0.77647059, 0.78823529],
  40. [ 0.56078431, 0.77647059, 0.78823529],
  41. ..., ...]])
  42. '''
  43. '''
  44. resize函数接口
  45. resize(image, output_shape, order=1, mode='constant', cval=0, clip=True, preserve_range=False)
  46. order : int, optional
  47. The order of interpolation. The order has to be in the range 0-5:
  48. - 0: Nearest-neighbor
  49. - 1: Bi-linear (default)
  50. - 2: Bi-quadratic
  51. - 3: Bi-cubic
  52. - 4: Bi-quartic
  53. - 5: Bi-quintic
  54. '''
  55. print skimage.img_as_float(image).dtype # out: float64
  56. # img_as_float可以把image转为double,即float64
  57. ---------------------
  58. 作者:爆米花好美啊
  59. 来源:CSDN
  60. 原文:https://blog.csdn.net/u013010889/article/details/54347089
  61. 版权声明:本文为博主原创文章,转载请附上博文链接!

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/从前慢现在也慢/article/detail/86828
推荐阅读
相关标签
  

闽ICP备14008679号