File: largest_component.m

package info (click to toggle)
suitesparse 1%3A5.12.0%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 176,720 kB
  • sloc: ansic: 1,193,914; cpp: 31,704; makefile: 6,638; fortran: 1,927; java: 1,826; csh: 765; ruby: 725; sh: 529; python: 333; perl: 225; sed: 164; awk: 35
file content (29 lines) | stat: -rw-r--r-- 936 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
function C = largest_component (A)
%LARGEST_COMPONENT finds the largest connected component in an image.
% C = largest_component (A) returns an image C whose entries are equal to 1
% if A(i,j) is in the largest component of A, or zero otherwise.  In case of
% a tie, the largest component with the largest label A(i,j) is returned.
% If still tied, the component the smallest index i is returned (where i is the
% linear index of A(i) for all entries in the component).
%
% Example:
%
%   A = [ 1 2 2 3
%         1 1 2 3
%         0 0 1 2
%         0 1 3 3 ]
%   C = largest_component (A)
%
%   returns C = [
%         0 1 1 0
%         0 0 1 0
%         0 0 0 0
%         0 0 0 0 ]
%
% See also FIND_COMPONENTS, FIND_COMPONENTS_EXAMPLE, DMPERM

% Copyright 2008, Timothy A. Davis, http://www.suitesparse.com

% return the new binary image with just the largest component
C = zeros (size (A), class (A)) ;
C (find_components (A)) = 1 ;