Matlab 将灰度图像转换为二进制,但在写入图像时,我不';无法获得二值图像
我有一个Matlab 将灰度图像转换为二进制,但在写入图像时,我不';无法获得二值图像,matlab,binary,grayscale,Matlab,Binary,Grayscale,我有一个灰度图像,我已将其转换为二进制。但是,当我imwrite它时,我不会得到二进制图像。也就是说,一个图像有两个值(即: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 dat
灰度
图像,我已将其转换为二进制
。但是,当我imwrite
它时,我不会得到二进制图像。也就是说,一个图像有两个值(即: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.
这可能就是问题所在。好吧,让我们看看如何将图像转换为BW并保存它,我希望您能找到缺少的一点:
首先读一个图像:
im = imread('img_name.jpg');
第二,将其转换为BW:
bw = im2bw(im, graythresh(im));
第三,保存它:
imwrite(bw, 'binary_image_name.jpg', 'jpg');
我猜,您在'imwrite'函数('binary_image_name.jpg')的第二个参数处错过了图像格式。从文档中,我猜强制转换为逻辑
应该是技巧所在。检查注意,使用im2bw
您应该已经直接获得了一个逻辑映像。我按照您提到的那样做了,但没有得到预期的结果。我将使用另一个映像再次检查它,它将正常工作!所以我想你可能会错过一些转换之前!请多解释一下你在做什么?