我想用简单的代码im2bw()将彩色图像转换成二值图像(0,1)。

但在这种情况下,晶界丢失或无法正确显示。

我想设计晶界

。
任何matlab或python的解释都是可以接受的。
发布于 2018-06-23 07:52:42
MATLAB有一个函数boundarymask,可以做你想做的事情。
如果输入图像lab是一个标记图像,那么只需执行bw=boundarymask(lab)。
如果输入图像是RGB,那么您可以这样做:
img = imread('https://i.stack.imgur.com/ZUFSq.png'); % color image from question
bw = boundarymask(img(:,:,1)); % pretend the red channel is a labeled image.请注意,两个区域可能具有相同的红色值,并且不会绘制边界。为了防止这种情况,将三个通道中的每个通道的结果按元素或组合在一起:
bw = boundarymask(img(:,:,1));
bw = bw | boundarymask(img(:,:,2));
bw = bw | boundarymask(img(:,:,3));https://stackoverflow.com/questions/50998679
复制相似问题