Labfans是一个针对大学生、工程师和科研工作者的技术社区。 | 论坛首页 | 联系我们(Contact Us) |
![]() |
![]() |
#1 |
高级会员
注册日期: 2019-11-21
帖子: 3,006
声望力: 66 ![]() |
![]()
我已经编写了一些用于图像分析的matlab代码,该代码在图像中搜索簇,并为这些簇建立邻接矩阵,从而说明哪些簇在图像中相互影响。
我可以使用此邻接矩阵来得出图。 为了完成算法,我现在必须为最大度为2的所有节点挖掘该图,其中节点索引高于其neigbor(当度为1时)或其两个邻居的索引之间。 基本上如此处的图片所示: ![]() 我需要在matlab中这样做,重要的是要知道我的尝试可以作为邻接矩阵来使用,如下所示: 1 2 3 4 1 0 0 1 1 2 0 0 0 1 3 1 0 0 1 4 1 1 1 0 可能很简单,但我看不到解决方案... 回答: 这是我的尝试: %# adjacency matrix M = [0 0 1 1; 0 0 0 1; 1 0 0 1; 1 1 1 0]; %# degree == 1 N = find(sum(M,2) == 1); %# nodes with degree(N)==1 nodes1 = N(N>find(M(N,:))); %# nodes where its index is higher than that of its neigbor %# degree == 2 N = find(sum(M,2) == 2); %# nodes with degree(N)==2 Nb = zeros(numel(N),2); for i=1:numel(N) Nb(i,:) = find( M(N(i),:) ); %# two-neighbors of node N(i) end %#Nb = sort(Nb,2); nodes2 = N(Nb(:,1) |
![]() |
![]() |