• 1-图像读取


    1 格式说明

    1 Andor相机默认采集16bit图像img = io.imread('radiography image 1.tif')读取后即为uint16,运算中自动转为float64
    2 ImageJ中,图像经过image calculator加减乘除运算后,会自己转为float32(32bit)储存。同python中的float32格式储存。

    tiff格式存储
    jpg\png格式不能无损保存,会自动转为uint8保存,推荐tiff储存
    float64存储无法预览,float32的tif图像可以预览。np中默认float64运算,可以改为float32储存
    (uint8/16/32可以预览,但是,float64转化为uint8/16/32/64保存后,低数值的像素会丢失信息,不要转为uint。float64转float32基本不丢失信息)
    在这里插入图片描述

    读取
    img = io.imread('radiography image 1.tif')
    img = skimage.img_as_float32(img)
    存储tiff
    image = np.array(image, dtype=np.float32)
    io.imsave('img-dealed.tiff',image)

    2 读取

    skimage

    import skimage
    from skimage import io, color
    
    # 读取灰度图,能做到16bit无损
    img = io.imread('CT-220s_681.tif')   # 直接就是numpy类型,dtype根据图片格式决定
    img = skimage.img_as_float32(img)    # dtype转换为float32
    
    print(img.shape, type(img), img.dtype)
    
    
    # 读取彩色图,默认RGB
    img = io.imread('0006.png')   
    print(img.shape, type(img), img.dtype)
    print(img)
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14

    输出

    (721, 1994)  uint16
    [[47532 46889 47658 ... 46906 46789 46942]
     [48233 47433 47538 ... 47491 47502 47378]
     [47926 46989 46765 ... 46272 46423 46601]
     ...
     [47306 45753 46147 ... 47469 47149 47082]
     [46289 46380 46739 ... 47196 46787 47083]
     [46588 46007 46457 ... 46843 47372 47149]]
    
    (2040, 1356, 3)  uint8
    [[[158 120  97]
      ...
      [126 109  79]]]
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13

    请添加图片描述
    请添加图片描述

    3 RGB转换为灰度图

    # RGB转换为灰度图。自动转化到[0,1],float64
    gray_img = color.rgb2gray(img)
    print(gray_img.shape, type(gray_img), gray_img.dtype)
    
    • 1
    • 2
    • 3

    输出

    (2040, 1356)  float64
    
    • 1

    在这里插入图片描述

  • 相关阅读:
    【Git 全功能解析: 探索版本控制的强大工具】
    Java 蓝桥杯校赛 谁最长?
    CMT2380F32模块开发19-LVD例程
    001、JDK环境配置
    Spring声明式事务管理(基于Annotation注解方式实现)
    机器学习实战(11)——初识人工神经网络
    网络网络层之(1)IPv4地址
    数据安全与个人隐私:美国人的焦虑与变化
    git工具基本操作命令
    FPGA时序分析与约束(1)——组合电路时序
  • 原文地址:https://blog.csdn.net/qq_43328166/article/details/133850100