将灰度图像转换为二进制,但在写入图像时,我没有得到二进制图像

时间:2013-11-13 10:21:01

标签: matlab binary grayscale

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

2 个答案:

答案 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.

这可能就是问题所在。

答案 1 :(得分:0)

好吧,让我们看看如何将图像转换为BW并保存,我希望你能找到缺失点:

第一次阅读图片:

im = imread('img_name.jpg');

第二次将其转换为BW:

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

第3次保存:

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

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

相关问题