Distinguish a simply connected figures?

前端 未结 1 1282
星月不相逢
星月不相逢 2020-12-11 11:23

So I have a binary matrix in Matlab. It is basically a blob (pixels of value 1) surrounded by a neutral background (value 0).

I want to figure out whether this blo

相关标签:
1条回答
  • 2020-12-11 12:01

    Code

    %// Assuming bw1 is the input binary matrix
    
    [L,num] = bwlabel( ~bw1 );
    counts = sum(bsxfun(@eq,L(:),1:num));
    [~,ind] = max(counts);
    bw2 = ~(L==ind);
    
    %// Output decision
    [L,num] = bwlabel( bw1 );
    if ~nnz(bw1~=bw2) && num==1
        disp('Yes it is a simply connected blob.')
    else
        disp('Nope, not a simply connected blob.')
    end
    
    0 讨论(0)
提交回复
热议问题