如何将彩色颗粒图像转换为黑白(0,1),以便可识别颗粒边界

时间:2018-06-23 06:45:47

标签: python matlab image-processing voronoi

我想使用简单的代码static_pointer_cast将彩色图像转换为二进制图像(0,1)。

但是在这种情况下,晶界消失了或看不到

我想像

那样设计晶界

任何matlab或python解释都是可以接受的。

1 个答案:

答案 0 :(得分:3)

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.

请注意,两个区域可能具有相同的红色值,并且不会绘制边界。为了避免这种情况,请对3个通道中的每个通道按元素进行“或”运算:

bw = boundarymask(img(:,:,1));
bw = bw | boundarymask(img(:,:,2));
bw = bw | boundarymask(img(:,:,3));