我想要计算在二值图像中六角形细胞的百分比,这意味着有另外6个相邻细胞的单元格的数目。例如,标记为1号、2号、3号和4号的细胞都有6个相邻的细胞。
我在寻找一个可以在Matlab中实现的函数。我尝试过不同的Matlab函数,例如区域道具和bwconncomp。然而,没有人为我工作。你知不知道。
这里有一个简单的图像:

发布于 2016-03-01 23:26:22
嗨,你可以使用钟声函数和一个连续的形态学函数。
以下代码执行此任务:
% load image and post processing
A = imread('LR0gx.png');
I = rgb2gray(A);
I = imcomplement(I);
% labelling of the image
L = bwlabeln(I);
figure; subplot 121;
imagesc(L); title('cells labeling')
% search and count the neighbours using the dilate function
label = unique(L);
for ii = label(2:end)'
I_temp = L == ii;
I_temp = bwmorph(I_temp,'dilate',2) - I_temp;
I_temp2 = L; I_temp2(~I_temp) = 0;
number_of_neighbours(ii) = size(unique(I_temp2), 1)-1;
end
L_2 = zeros(size(L));
for ii = label(2:end)'
L_2(L == ii) = number_of_neighbours(ii);
end
subplot 122;
imagesc(L_2); title('number of neighbours'); colorbar;其结果如下:

Ps:您必须将一个删除到count,因为单元格的分区存在于函数unique中。
imcomplement是必需的,因为bwlabeln标记为白色值。
https://stackoverflow.com/questions/35735426
复制相似问题