删除图像中两个对象之间的连接 [英] Removing connection between two objects in an image

查看:59
本文介绍了删除图像中两个对象之间的连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试使用侵蚀移除下图中的2和0之间的连接,但仍然无法做到这一点.还有没有其他可能的方法来消除两个数字之间的这种联系?

I have been trying to remove the connection between the 2 and the 0 in the image below using erosion, but still can't manage to do it. Is there any other possible way of removing this connection between the two numbers?

推荐答案

您可以使用形态学操作腐蚀扩张解决问题.

You can solve the problem using the morphological operations erode and dilate.

要删除的连接需要一些假设.
我做了以下假设:

Some assumptions are required about the connection you want to remove.
I made the following assumptions:

  • 连接区域是图像中最大的连续区域.
  • 连接区域的宽度约为11个像素.
  • 连接区域的形状又高又薄.

这是示例代码:

I = imread('202.png'); %Read image.
I = rgb2gray(I); %Convert from RGB to grayscale.
I = imbinarize(I); %Convert to binary image.   

%Erode using large kernel - only the largest area in I is kept white.
Mask = imerode(I, ones(11)); %Result is the only the connection between 2 and the 0

%Expand the mask in the vertical direction
Mask = imdilate(Mask, ones(25, 1));

%Erase the connection by placing zeros.
I(Mask) = 0;

figure;imshow(I)  

上面的代码:

  • 通过腐蚀所有细节来构建遮罩,仅保留连接重新加入.
  • 垂直扩展遮罩.
  • 擦除原始图像中的蒙版像素.

蒙版结果:

最终结果:

这篇关于删除图像中两个对象之间的连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆