2016-03-01 87 views
1

我想计算一个二进制图像中的六角形单元格的百分比,这意味着有另外6个邻居单元格的单元格的数量。例如,用1,2,3和4标记的单元都有6个邻居单元。如何计算每个单元格的邻居数量?

我正在寻找一个可以在Matlab中做到的功能。我已经尝试了不同的Matlab函数,比如regionprops和bwconncomp。但是,没有人为我工作。有什么想法。

一个简单的形象是在这里:

enter image description here

+0

亲爱的安德拉斯, 其实,我试过删除它,但我不能为什么? –

+0

亲爱的安德拉斯, 相信我,我做到了,但我不知道有什么问题!!你怎么知道有人发布了问题或他需要帮助?我的个人资料中可以设置任何设置吗?我是这个网站的新手。 –

+0

Alaa我看到你已经成功删除了你之前的问题。我在这里删除了我的评论(因为它们现在已经过时了),我建议你对你的评论也一样(如果你用鼠标悬停在你的评论上,在它的末尾会出现一个小的“x”图标)。 –

回答

1

嗨,你可以使用bwlabeln功能和形态功能的继承。

下面的代码做这项工作:

% 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; 

结果是以下之一:

enter image description here

PS:你必须删除一个count因为细胞的分区目前在功能unique

Pss:需要imcomplement,因为bwlabeln标签为白色值。

+0

亲爱的R. Bergamote 感谢您的帮助,但我认为它不能解决问题。我需要的是找到每个单元的邻居数量。 –

+0

真的!我的回答与问题完全无关,请让我看看:D –

+0

@AlaaAlwaisy,我更新了答案,现在应该没问题 –