• Computer Science
  • Max-Trees
  • Visual Computing
  • Data Science
  • Connected Components

To:
M.P. van de Weerd
From:
Date:
Re:
Attributes for Connected Components
Cc:
Public
Letterhead

Attributes for
Connected Components

Connected components are fundamental to the fields of image processing and computer vision, providing the basis for segmenting and analyzing images. In my Introduction to Max-Trees I delve into the methods of extracting these components from images in order to construct a Max-Tree — a data structure centered around the concept of connected components. However, the true utility of connected components emerges when we compute attributes that provide meaningful information about the image.

This article compiles a set of attributes that can be computed relatively easily, offering insights into the properties and characteristics of connected components. Additionally, a comprehensive collection of GNU Octave implementations for these attributes is provided, facilitating practical application. Some of these implementations are included in the body of this article as well.

While many of these attributes are particularly relevant for connected components within a max-tree structure, they are also applicable in other contexts. The content of this article is derived from my master’s thesis, “Detecting Astronomical Objects with Machine Learning” and aims to make its insights more accessible to a broader audience.

Area

An attribute that can easily be computed is the area. Berger et al. define this attribute as the number of elements within the component.1 Tushabe provides the formal mathematical definition of area A(X) of component X as2

A(X)=xX1X(x).

Here, 1X(x) is the so-called identicator function, which is 1 if xX or 0 otherwise. While the term “area” originated from two-dimensional components, it can also apply to higher dimensions, such as indicating the volume of a cube in three dimensions. Berger et al. provide an algorithm for computing the area of a component in the context of a max-tree, which is included below in GNU Octave code.1

function a = area(f, R, parent)
    a = ones(size(R));

    [_, v] = sort(R(:));

    for x = v'
        if parent(x) == x
            continue
        end

        a(parent(x)) = a(parent(x)) + a(x);
    end
end

Perimeter

The perimeter is closely related to the area attribute. Gonzalez and Woods describe the perimeter as the length of the boundary of a component.3 Interpreting the boundary as the number of elements not exclusively connected to elements within the same component, a novel approach to computing the perimeter is presented in my master’s thesis6. The complexity of computing the perimeter arises from the fact that an element on the boundary of its own component can also contribute to the boundary of its parent, its parent’s parent, etc. To address this, a boundary vector (X) is constructed, indicating the contribution of a component X to each layer in the tree. These contributions apply only to the direct and indirect parents of the component. First, we compute the intermediate contribution set Λ(x) for each element x, composed of the layers where x is part of the perimeter:

Λ(x)={y : argminn𝒩(x) λ(n)<uλ(x)}.

Here, 𝒩(x) are the neighbors of x and λ(x) its level. With Λ(x) computed for every element x, the contribution of X to the perimeter of layer λ is the number of λ inclusions in the contribution set of elements in X:

(X)λ=|{xX : λΛ(x)}|.

The perimeter 𝔅(Xλμ) of component Xλμ in branch μ and layer λ is determined by summing the contributions of all components to λ:

𝔅(Xλμ)=νN(Xγv)λ,

where N=ν : μ  v and γλ. The set of branches N includes all branches ν that are either equal to or divarications of branch μ (written as μ  ν).

Below is a GNU Octave implementation of the perimeter attribute:

function l = per(f, R, parent)
    b = zeros(size(f));
    l = zeros(size(f));

    for a = unique(f)'
        g = f >= a;
        c = zeros(size(f));

        c = c | g > [zeros(1, size(g, 2)); g(1:end-1, :)]; % n
        c = c | g > [zeros(size(g, 1), 1), g(:, 1:end-1)]; % e
        c = c | g > [g(2:end, :); zeros(1, size(g, 2))];   % s
        c = c | g > [g(:, 2:end), zeros(size(f, 1), 1)];   % w

        b = b + c;
    end

    [_, s] = sort(f(:), "descend");

    for x = s'
        y = x;

        while b(x) > 0
            l(y) = l(y) + 1;
            b(x) = b(x) - 1;
            y = parent(y);
        end
    end
end

Compactness & Circularity Ratio

Using the area A(X) and perimeter 𝔅(X) attributes, composite attributes like compactness and the circularity ratio can be computed. Gonzales and Woods provide the following formal definitions of compactnes C(X) and circularity ratio Rc(X):3

C(X)=𝔅(X)2A(X), andRc(X)=4πA(X)𝔅(X)2.

These attributes indicate the shape of the components they represent. For example, Rc(X) approaches a value of 1 as the shape of the component X becomes more circular.

Grayscale, Power & Volume

In addition to positional information, the value or intensity represented by elements can be indicative of a component attribute. Many examples are straightforward, such as the sum of (squared) intensities and grayscale (average value within a component). Tushabe provides the formal definition of the latter:

G(X)=xXf(x)A(X).

This can be implemented in GNU Octave code as follows:

function g = grayscale(f, R, parent)
    g = zeros(size(f));
    a = area(f, R, parent);

    [_, s] = sort(f(:), "descend");

    for x = s'
        y = x;

        while true
            g(y) = g(y) + f(x) / a(y);

            if y == parent(y)
                break;

            end

            y = parent(y);
        end
    end
end

More sophisticated measurements based on intensity levels include power

𝒫(X,f,α)=xX(f(x)α)2

for an image f and parent intensity level α, and volume

V(X,f,α)=xX(f(x)α).

Entropy

Gonzalez and Woods define the entropy attribute as the average amount of information conveyed by each element in a component.3 Given a discrete set of distinct grayscale values {a1,a2,,aJ} in a component of size M×N, the probability of encountering a grayscale value aj in the component is

P(aj)=aJMN.

This function can be used to compute a histogram of component X. Using this definition, Gonzalez and Woods provide the formal definition of entropy:3

H(X)=j=1JP(aj)logP(aj).

Invariant Moments

Westenberg, Roerdink, and Wilkinson provide definition for the four invariant moments: non-compactness, elongation, flatness and sparseness.4 These are suitable for usage in two- and three-dimensional components, unlike those presented by Hu, which only apply to two-dimensional components.5 Westenberg, Roerdink, and Wilkinson define the non-compactness attribute 𝒩(X) as

𝒩(X)=Tr𝐈(X)35A(X)

with the moment of inertia tensor 𝐈(X) defined as

𝐈ij(X)={X(ii¯)2+A(X)12if i=jX(ii¯)(jj¯)otherwise

for i,j{x,y,z}. Computing eigenvalues λi(X) of 𝐈(X) and ordering them such that

|λ1(X)||λ2(X)||λ3(X)|.

allows the computation of the attributes elongation (X), flatness (X) and sparseness 𝒮(X):

(X)=|λ1(X)λ2(X)|,(X)=|λ2(X)λ3(X)|, and𝒮(X)=π6A(X)i=1320|λi(X)|A(X).

  1. Christophe Berger, Theirry Géraud, Roland Levillain, Nicolas Widynski, Anthony Baillard and E. Berin. “Effective Component Tree Computation with Application to Pattern Recognition in Astronomical Imaging”. In Proceedings of the International Conference of image Processing, vol. 4, 2007, pp. 41 – 44. ISBN: 978-1-4244-1436-9. DOI: 10.1109/ICIP2007.4379949 

  2. Florence F. Tushabe. “Extending Attribute Filters to Color Processing and Multi-Media Applications”. 2010. ISBN: 978-90-367-4630-4. 

  3. Rafael C. Gonzalez and Richard E. Woods. “Digital Image Processing”. 3rd edition. 2008. ISBN: 978-0-13-505267-9. 

  4. Michael A. Westenberg, Jos B. Roerdink and Michael H.F. Wilkinson. “Volumetric Attribute Filtering and Interactive Visualization Using the Max-Tree Representation”. In: IEEE Transactions on Image Processing, vol. 16, issue 12, 2007, pp. 2943 – 2952. DOI: 10.1109/TIP.2007.909317

  5. Ming-Kuei Hu. “Visual Pattern Recognition by Moment Invariants”. In: IRE Transactions on Informational Technology, vol. 8, issue 2, 1962, pp. 179 – 187. DOI: 10.1109/tit.1962.1057692

  6. Michaël P. van de Weerd. “Detecting Astronomical Objects with Machine Learning”. 2021. URL: https://fse.studenttheses.ub.rug.nl/23854/

This website collects statistical data in order to improve your user experience.

Privacy Statement