Mathematical morphology

    Using the search, I was surprised to find that on Habré there are absolutely no articles describing the apparatus of mathematical morphology, and yet this apparatus is indispensable in the field of low-level image processing. If you are interested, please, under cat.

    Key Definitions


    The term morphology refers to the description of the properties of the shape and structure of any objects. In the context of machine vision, this term refers to the description of the properties of the shape of the areas in the image. Operations of mathematical morphology were originally defined as operations on sets, but it soon became clear that they are also useful in problems of processing a set of points in two-dimensional space. The sets in mathematical morphology represent the objects in the image. It is easy to see that the set of all background pixels of a binary image is one of the options for its full description.
    First of all, mathematical morphology is used to extract some properties of the image, useful for its presentation and description. For example, contours, cores, convex hulls. Morphological methods used at the stages of preliminary and final image processing are also of interest. For example, morphological filtration, thickening or thinning.
    The input data for the apparatus of mathematical morphology are two images: processed and special, depending on the type of operation and the problem to be solved. Such a special image is usually called a primitive or structural element. As a rule, the structural element is much smaller than the processed image. A structural element can be considered a description of an area with some form. It is clear that the form can be any, the main thing is that it can be represented as a binary image of a given size. In many image processing packages, the most common structural elements have special names: BOX [H, W] - a rectangle of a given size, DISK [R] - a disk of a given size, RING [R] - a ring of a given size.

    The result of morphological processing depends both on the size and configuration of the original image, and on the structural primitive.
    The size of a structural element is usually 3 * 3, 4 * 4, or 5 * 5 pixels. This is due to the main idea of ​​morphological processing, during which the characteristic details of the image are found. The desired detail is described by a primitive, and as a result of morphological processing, it is possible to emphasize or remove such details in the entire image.
    One of the main advantages of morphological processing is its simplicity: both at the input and at the output of the processing procedure we get a binarized image. Other methods, as a rule, first get a grayscale from the original image, which is then reduced to a binary using a threshold function.

    Basic operations


    The main operations of mathematical morphology are build-up, erosion, closure and opening. The essence of the operations is reflected in these names: extension increases the image area, and erosion makes it smaller, the closure operation allows you to close the internal holes of the area and eliminate gaps along the area border, the opening operation helps to get rid of small fragments protruding outside the area near its border. Next, mathematical definitions of morphological operations will be presented.
    Unification, intersection, complement, difference

    Before proceeding to morphological operations, it makes sense to consider the set-theoretic operations that underlie mathematical morphology.
    The union of two sets A and B, which is denoted by C = A∪B, is by definition the set of all elements belonging to either the set A, or the set B, or both sets simultaneously. Similarly, the intersection of two sets A and B, which is denoted by C = A∩B, is by definition the set of all elements belonging to both sets A and B. The complement of A is the set of elements not contained in A: A c = {w | w∉A}. The difference of two sets A and B is denoted by A \ B and is defined as follows: A \ B = {w│w∈A, w∉B} = A∩B c . This set consists of elements of A that are not included in B.
    Consider all of the above operations on a specific example.

    Transfer

    The transfer operation X t of the set of pixels X to the vector t is given in the form X t = {x + t | x∈X}. Therefore, transferring a plurality of unit pixels in a binary image shifts all the pixels of the set by a predetermined distance. The transfer vector t can be specified as an ordered pair (∆r, ∆c), where ∆r is the component of the transfer vector in the direction of the rows, and ∆c is the component of the transfer vector in the direction of the image columns.

    Build-up, erosion, shorting, breaking

    We will consider the following operations using a specific example. Suppose we have the following binary image and structural element:

    Escalation

    Structural element S applies to all pixels of a binary image. Each time, when the coordinate origin of a structural element is combined with a single binary pixel, transfer and subsequent logical addition with the corresponding pixels of the binary image are applied to the entire structural element. The results of logical addition are written to the output binary image, which is initially initialized to zero values.

    Erosion

    When performing the erosion operation, the structural element also passes through all the pixels of the image. If at some position each single pixel of a structural element coincides with a single pixel of a binary image, then logical addition of the central pixel of the structural element with the corresponding pixel of the output image is performed. As a result of the erosion operation, all objects smaller than the structural element are erased, objects connected by thin lines become disconnected, and the sizes of all objects are reduced.


    Opening

    The erosion operation is useful for removing small objects and various noises, but this operation has a drawback - all remaining objects are reduced in size. This effect can be avoided if, after the erosion operation, an extension operation with the same structural element is used.
    Opening eliminates all objects smaller than the structural element, but at the same time helps to avoid a strong reduction in the size of the objects. Also, opening is ideal for removing lines whose thickness is less than the diameter of the structural element. It is also important to remember that after this operation, the contours of objects become smoother.

    Short circuit

    If we first apply the extension operation to the image, then we can get rid of small holes and gaps, but at the same time the contour of the object will increase. Avoid this increase allows the operation of erosion, performed immediately after building with the same structural element.

    Conditional build-up


    One of the typical applications of binary morphology is to isolate components in a binary image in which the shape and size satisfy specified constraints. In many such tasks, it is possible to construct a structural element that, after application to a binary image, removes components that do not satisfy the constraints and leaves a few unit pixels corresponding to the components that satisfy the constraints. But for subsequent processing, the entire components may be required, and not only their fragments remaining after erosion. To solve this problem, a conditional escalation operation was introduced.
    The set obtained as a result of erosion is cyclically expanded by the structural element S, and at each step the result is reduced to a subset of pixels that have unit values ​​in the original image B. The conditional extension operation is explained in the figure below. In this figure, the binary image B was eroded by element V to highlight components containing vertical fragments 3 pixels high. The resulting image C has two such components. To select these components as a whole, the image C is conditionally expanded by the element D relative to the original image B.

    Highlighting Borders


    Morphological operations can also be used to highlight the boundaries of a binary object. This operation is very important because the boundary is a complete, and at the same time very compact description of the object.
    It is easy to see that the boundary points have at least one background pixel in their vicinity. Thus, applying the erosion operator with a structural element containing all possible neighboring elements, we delete all boundary points ... Then the border will be obtained using the operation of the difference of the sets between the original image and the image obtained as a result of erosion. Thus, we have examined the basic operations of mathematical morphology, and several methods for their application. I hope this device comes in handy in future activities.



    Also popular now: