【发布时间】:2013-11-25 21:35:24
【问题描述】:
我有一个grayscale 图像,我已将其转换为binary。但是,当我 imwrite 它时,我没有得到 binary 图像。也就是一张图片有两个值(即0,1),这是为什么呢?
【问题讨论】:
我有一个grayscale 图像,我已将其转换为binary。但是,当我 imwrite 它时,我没有得到 binary 图像。也就是一张图片有两个值(即0,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.
这可能是问题所在。
【讨论】:
logical 转换为诀窍。检查mathworks.nl/help/matlab/ref/imwrite.html注意,使用im2bw你应该已经直接得到了一个逻辑图像。
那么让我们看看如何将图片转成黑白并保存,希望你能找到缺失的地方:
第一次读取图像:
im = imread('img_name.jpg');
第二次将其转换为 BW:
bw = im2bw(im, graythresh(im));
第三次保存:
imwrite(bw, 'binary_image_name.jpg', 'jpg');
我猜,你在 'imwrite' 函数 ('binary_image_name.jpg') 的第二个参数处错过了图像格式
【讨论】: