【问题标题】:Converted a grayscale image to binary, but when writing the image I don't get a binary image将灰度图像转换为二进制,但是在写入图像时我没有得到二进制图像
【发布时间】:2013-11-25 21:35:24
【问题描述】:

我有一个grayscale 图像,我已将其转换为binary。但是,当我 imwrite 它时,我没有得到 binary 图像。也就是一张图片有两个值(即0,1),这是为什么呢?

【问题讨论】:

    标签: matlab binary grayscale


    【解决方案1】:

    根据imwrite的文档:

    If the input array is of class double, and the image is a grayscale
    or RGB color image, IMWRITE assumes the dynamic range is [0,1] and
    automatically scales the data by 255 before writing it to the file as
    8-bit values.
    

    这可能是问题所在。

    【讨论】:

    【解决方案2】:

    那么让我们看看如何将图片转成黑白并保存,希望你能找到缺失的地方:

    第一次读取图像:

    im = imread('img_name.jpg');
    

    第二次将其转换为 BW:

    bw = im2bw(im, graythresh(im));
    

    第三次保存:

    imwrite(bw, 'binary_image_name.jpg', 'jpg');
    

    我猜,你在 'imwrite' 函数 ('binary_image_name.jpg') 的第二个参数处错过了图像格式

    【讨论】:

    • 我按照你说的做了,但没有得到预期的结果
    • 好吧,我用另一张图片再次检查它,它正在工作!所以我想你可能会在转换之前错过某事!请解释一下你在做什么?
    猜你喜欢
    • 1970-01-01
    • 2013-12-16
    • 2015-12-07
    • 2019-12-01
    • 1970-01-01
    • 2011-02-28
    • 2018-03-18
    • 1970-01-01
    • 2014-01-01
    相关资源
    最近更新 更多