首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何计算每个单元的邻居数?

如何计算每个单元的邻居数?
EN

Stack Overflow用户
提问于 2016-03-01 23:07:57
回答 1查看 193关注 0票数 1

我想要计算在二值图像中六角形细胞的百分比,这意味着有另外6个相邻细胞的单元格的数目。例如,标记为1号、2号、3号和4号的细胞都有6个相邻的细胞。

我在寻找一个可以在Matlab中实现的函数。我尝试过不同的Matlab函数,例如区域道具和bwconncomp。然而,没有人为我工作。你知不知道。

这里有一个简单的图像:

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-03-01 23:26:22

嗨,你可以使用钟声函数和一个连续的形态学函数。

以下代码执行此任务:

代码语言:javascript
复制
% 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标记为白色值。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35735426

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档