通过保留叶齿形状的分割来填充二进制叶图像中的间隙

Fill gaps in binary leaf image occured from segmentation preserving leaf teeth shape

叶分割后我得到以下二值图像: 有没有办法填补因静脉与背景相似而造成的空白?我试过使用 imclose 或 imdilate 等,但它会影响牙齿形状。我找不到如何在不影响牙齿形状的情况下填补这些空隙。

您可以尝试 bwfill(I, 'hols'),没有 imclose

I = imbinarize(rgb2gray(imread('leaf.jpg')));
I = I(3:end-4, 1:end-8); %Remove white frame
J = imclose(I, ones(2)); %Minor affect the teeth shape (result looks better with imclose).
K = bwfill(J, 'hols'); %Fill the black hols

结果:


如果你想填写"vein gaps",你可以尝试以下方法:

I = imbinarize(rgb2gray(imread('leaf.jpg')));
I = I(3:end-4, 1:end-8); %Remove white frame
I = bwfill(I, 'hols'); %Fill small black hols.
J = imerode(imdilate(I, strel('disk',5)), strel('disk',10)); %Dilate with radius 5 and erode with 10
T = (I == 0) & (J == 1); %Create mask with 1 where I is black and J is white "vein mask".
K = I;
K(T) = 1; %Fill "vein mask" in I with white.
K = bwfill(K, 'hols'); %Fill small black hols (fill tiny holds left).

结果: