【问题标题】:Convert Matlab disparity image from single precision to uint8将 Matlab 视差图像从单精度转换为 uint8
【发布时间】:2017-04-25 17:04:15
【问题描述】:

我需要将视差图像保存到我的磁盘。视差图像的数据类型为单精度,视差范围为[0 128]。 使用imwrite(disparityMap,file_name) 时,保存的图像似乎是二进制的。

【问题讨论】:

    标签: matlab disparity-mapping


    【解决方案1】:

    当您使用浮点精度的 imwrite 时,matlab 认为您的数据在 [0 1] 范围内。所以任何大于 1 的值都将被视为 1。这就是为什么你有一张黑白图像。

    来自matlab doc

    如果 A 是数据类型为 double 或 single 的灰度或 RGB 彩色图像,则 imwrite 假定动态范围为 [0,1] 并在将数据作为 8 位值写入文件之前自动将数据缩放 255。

    那么,您有两个解决方案。我正在考虑 128 是您数据中的最大值,并且您想要一个从黑色到白色的颜色图。我会的

    第一个解决方案,标准化您的数据,以便 matlab 进行正确的转换:

    % Normalize your data between 0 and 1
    disparityMap = disparityMap/128;
    
    % write the image
    imwrite(disparityMap,file_name)
    

    第二种方案,自己做转换,直接把图片写成uint8:

    % Normalize your data between 0 and 255 and convert to uint8
    disparityMapU8 = uint8(disparityMap*255/128);
    
    % write the image as uint8
    imwrite(disparityMapU8,file_name)
    

    【讨论】:

      猜你喜欢
      • 2019-11-14
      • 2018-01-08
      • 1970-01-01
      • 1970-01-01
      • 2016-06-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-01-22
      相关资源
      最近更新 更多