IMAGE Team - The Pantheon project

Tutorial: Mathematical Morphology

Identification

Resources

Table of contents

  1. Basis Concepts
    1. Images
    2. Structuring Elements
  2. Basis Operations
    1. Dilation (δB(f)) / Erosion (εB(f))
    2. Geodesic Transformations
  3. Composite Operations
    1. Opening (γB(f)) / Closing (ΦB(f))
    2. Top-Hat
    3. Gradient
    4. Extremum
  4. Image Processing
    1. Filtering
    2. Image Enhancement
    3. Edge detection
    4. Segmentation
    5. Image Analysis
  5. Variations
    1. Rotational Morphological Processing
    2. Fuzzy Morphological Processing

I. Basis Concepts

I.A. Images

The Pandore implementation of the morphological operations depends on the image type.

I.B. Structuring Elements

I.B.1. Flat Structuring Elements

Flat structuring elements are binary structuring elements considered as masks. Most of the time, the structuring elements are centered and are square matrices with an odd size: 3x3, 5x5, etc.

Diamond size 3. Square size 3. Disc size 3.
Diamond size 7. Square size 7. Disc size 7.

I.B.2. Predefined Structuring Elements

Most of the Pandore morphological operations use built-in flat structuring elements. Built-in structuring elements are centered and have an odd size: 3x3, 5x5, etc. Thus, the size parameter for the operator is actually the half-size (eg., 1 for 3x3, 3 for 7x7). In 2D, the predefined list of flat structuring elements is:

  1. diamond (◊)
  2. square (□)
  3. disc (○)
  4. horizontal line (-)
  5. horizontal line (\)
  6. horizontal line (|)
  7. horizontal line (/)
  8. cross (+)
  9. diagonal cross (x)

I.B.3. Custom Structuring Elements

It is always possible to create a structuring element as a separate image that can be used with specialized Pandore operators. Any binary or grayscale image is convenient. Thus, custom structuring element can be built using arithmetic, logical, and morphological operations between basis structuring elements since they are implemented as regular images.

Pandore script (bash)

II. Basis Operations

II.A. Dilation / Erosion

II.A.1. Dilation (δB(f))

The dilation of an image f by a structuring element B is the assignment to each pixel of the output image with the maximum value found over the neighborhood of the pixels where the neighborhood is defined by the structuring element B:

δB(f)x=max(β∈B)f(x+β)

Considering binary image, dilation can be interpreted as the answer of the boolean question at each pixel: "Does the structuring element hits the pixel neighborhood?".

Effects

Pandore script (bash)

  1. Dilation with a predefined structuring element (a diamond of size 7x7):

    pdilatation 0 3 tangrambin.pan tangramdil.pan
    
  2. Dilation with a customized structuring element (diamond of size 3x3 applied 3 times = a diamond of size 7x7):

    cat > se.txt <<EOF
    255 1 0
    255 0 1
    255 1 1
    255 2 1
    255 1 2
    EOF
    ptxt2pan 0 3 3 0 se.txt se.pan
    psedilatation 3 se.pan images/tangrambin.pan tangramdil.pan
    

Results

Black image with a white point. Dilation by a square of size 7. Dilation by a disc of size 7.
Binary image. Dilation by a square of size 9. Dilation by a disc of size 9.
Grayscale image. Dilation by a square of size 9. Dilation by a disc of size 9.
Color image. Dilation by a square of size 9. Dilation by a disc of size 9.

II.A.2. Erosion (εB(f))

The erosion of an image f by a structuring element B is the assignment to each pixel of the output image with the minimum value found over the neighborhood of the pixel where the neighborhood is defined by the structuring element B:

εB(f)x=min(β∈B)f(x+β)

Considering binary image, erosion can be interpreted as the answer of the boolean question at each pixel: "Does the structuring element fits the pixel neighborhood?"

Effects

Pandore script (bash)

  1. Erosion with a predefined structuring element (a diamond of size 7x7):

    perosion 2 3 tangrambin.pan tangramdil.pan
    
  2. Erosion with a customized structuring element (a diamond of size 3x3 applied 3 times = a diamond of size 7x7):

    cat > se.txt <<EOF
    255 1 0
    255 0 1
    255 1 1
    255 2 1
    255 1 2
    EOF
    ptxt2pan 0 3 3 0 se.txt se.pan
    pseerosion 3 se.pan images/tangrambin.pan tangramdil.pan
    

Results

White image with a dark point. Erosion by a square of size 7. Erosion by a disc of size 7.
Binary image. Erosion by a square of size 9. Erosion by a disc of size 9.
Grayscale image. Erosion by a square of size 9. Erosion by a disc of size 9.
Color image. Erosion by a square of size 9. Erosion by a disc of size 9.

II.A.3. Linear Dilation (δL(f))

Linear dilation is a special case of dilation with a linear structuring element L. The operator pdilatation performs linear dilation with horizontal, vertical, and diagonal structuring elements. The operator plineardilation is more specialized for linear dilation and uses a parameter for specifying the angle rather than the structuring element.

Effect

Pandore script (bash)

  1. Horizontal dilation with a predefined horizontal structuring element of size 7x7.

    pdilatation 3 4 images/tangrambin.pan tangrambinld1.pan
    
  2. Horizontal dilation with the angle=0° and the size 7x7.

    plineardilatation 0 0 4 images/tangrambin.pan tangrambinld2.pan
    
  3. Diagonal dilation with the angle=30° and the size 7x7.

    plineardilatation 30 0 4 images/tangrambin.pan tangrambinld3.pan
    

Results

Dark image with a white point. Horizontal dilation of size 7. Diagonal dilation of size 7.
Binary image. Horizontal dilation of size 7. Dilation with angle=30° and size=7.
Grayscale image. Horizontal dilation of size 4. Dilation with angle=30° and size=4.
Color image. Horizontal dilation of size 4. Dilation with angle=30° and size=4.

II.A.4. Linear Erosion (εL(f))

Linear erosion is a special case of erosion with a linear structuring element L. The operator perosion performs linear erosion with horizontal, vertical, and diagonal structuring elements. The operator plinearerosion is more specialized for linear erosion and uses a parameter for specifying the angle rather than the structuring element.

Effect

Pandore script (bash)

  1. Horizontal erosion with a predefined horizontal structuring element of size 7x7.

    perosion 3 4 images/tangrambin.pan tangrambinle1.pan
    
  2. Horizontal erosion with the angle=0° and the size 7x7.

    plinearerosion 0 0 4 images/tangrambin.pan tangrambinle2.pan
    
  3. Diagonal erosion with the angle=30° and the size 7x7.

    plinearerosion 30 0 4 images/tangrambin.pan tangrambinle3.pan
    

Results

White image with a dark point. Horizontal erosion of size 7. Diagonal erosion of size 7.
Binary image. Horizontal erosion of size 7. Erosion with angle=30° and size=7.
Grayscale image. Horizontal erosion of size 4. Erosion with angle=30° and size=4.
Color image. Horizontal erosion of size 4. Erosion with angle=30° and size=4.

II.B. Geodesic Transformations

II.B.1. Geodesic Dilation (δg(f))

A geodesic dilation is a conditional dilation. An additional mask image g(x,y) is used as a limit to the propagation of the dilation.

δg(f(x,y)) = δ(f(x,y)) ∧ g(x,y)

The geodesic dilation used 3 parameters. The first two ones defines the structuring element, whereas the last one specifies the number of iterations.

Our implementation of the geodesic dilation also keeps the pixels of the source image that are masked by the mask image. Practically, we use:

δg(f(x,y)) = δ(f(x,y)) ∧ g(x,y) ∨ f(x,y)

Effect

Pandore script (bash)

  1. Geodesic dilation with a disc of size 1 applied 4 times.

    pgeodesicdilatation 2 1 4 tangrammarkers1.pan fillholbin.pan out.pan
    
  2. Geodesic dilation with a disc of size 1 applied 30 times.

    pgeodesicdilatation 2 1 30 tangrammarkers1.pan fillholbin.pan out.pan
    

Results

Binary image. Mask image. Geodesic dilation by a disc applied 4 times. Geodesic dilation by a disc applied 30 times.

II.B.2. Geodesic Erosion (εg(f))

A geodesic erosion is a conditional erosion. An additional mask image g(x,y) is used as a limit to the propagation of the erosion.

εg(f(x,y)) = ε(f(x,y))C ∧ g(x,y)

The geodesic erosion used 3 parameters. The first two ones defines the structuring element, whereas the last one specifies the number of iterations.

Our implementation of the geodesic erosion also keeps the pixels of the source image that are masked by the mask image. Practically, we use:

εg(f(x,y)) = ε(f(x,y))C ∧ g(x,y) ∨ f(x,y)

Effect

Pandore script (bash)

  1. Geodesic erosion with a disc of size 1 applied 4 times.

    pgeodesicerosion 2 1 4 tangrammarkers2.pan fillholbin.pan out.pan
    
  2. Geodesic erosion with a disc of size 1 applied 30 times.

    pgeodesicerosion 2 1 30 tangrammarkers2.pan fillholebin.pan out.pan
    

Results

Binary image. Mask image. Geodesic erosion by a disc applied 4 times. Geodesic erosion by a disc applied 30 times.

II.B.3. Reconstruction by Dilation (Rgδ(f))

The reconstruction by dilation is similar to the geodesic dilation applied until idempotence (ie., until the resulting image at the iteration i+1 equals the resulting image at iteration i). However, the mask image does not act as a mask but to force the dilation to remain above the mask image. Thus, the mask image must be greater than or equal to the marker image. With reconstruction by dilation, the structuring element is no longer a parameter of the reconstruction. Only the connectivity (4 or 8 in 2D) is used.

Rgδ(f(x,y))= δg(f(x,y))

Effects

Pandore script (bash)

  1. Reconstruction by dilation.

    pdilatationreconstruction 8 tangrammarkers1.pan fillholbin.pan brd1.pan
    
  2. Geodesic dilation until idempotence with a disc of size 3x3.

    pgeodesicdilatation 2 1 -1 tangrammarkers1.pan fillholebin.pan brd2.pan
    

Results

Binary image. Mask image. Reconstruction by dilation with a disc applied 4 times. Geodesic dilation by a disc applied until idempotence.

II.B.4. Reconstruction by Erosion (Rgε(f))

The reconstruction by erosion is similar to the geodesic erosion applied until idempotence (ie., until the resulting image at the iteration i+1 equals the resulting image at iteration i). However, the mask image is used in the reconstruction does not act as a mask but to force the erosion to remain below the mask image. Thus, the mask image must be lower than or equal to the marker image. With reconstruction by erosion, the structuring element is no longer a parameter of the reconstruction. Only the connectivity (4 or 8 in 2D) is used.

Rgε(f(x,y))= εg(f(x,y))

Effects

Pandore script (bash)

  1. Reconstruction by erosion.

    perosionreconstruction 8 tangrammarkers1.pan fillholbin2.pan brd1.pan
    
  2. Geodesic erosion until idempotence with a disc of size 3x3.

    pgeodesicerosion 2 1 -1 tangrammarkers1.pan fillholebin.pan brd2.pan
    

Results

Binary image. Mask image. Reconstruction by erosion with a disc applied 4 times. Geodesic erosion by a disc applied until idempotence.

III. Composite Operations

III.A. Opening / Closing

III.A.1. Opening (γB(f))

An opening is an erosion followed by a dilation. Erosion opens dark holes and dilation recovers the shape.

γB(f) = δBB(f)) (i.e., opening(f(x,y)) = dilation(erosion(f(x,y))))

Effects

Pandore script (bash)

  1. Opening with a disc of size 7:

    perosion 2 3 images/tangrambin.pan i1.pan
    pdilatation 2 3 i1.pan tangram_opening.pan
    

Results

Binary image. Opening with a disc of size 7.
Grayscale image. Opening with a disc of size 7.
Color image. Opening with a disc of size 7.

III.A.2. Closing (ΦB(f))

A closing is a dilation followed by an erosion. Dilation closes dark holes and erosion recovers the shape.

ΦB(f)) = εBB(f)) (i.e., closing(f) = erosion(dilation(f)))

Effects

Pandore script (bash)

  1. Closing with a disc of size 19:

    pdilatation 2 3 images/tangrambin.pan i1.pan
    perosion 2 3 i1.pan tangramclo.pan
    

Results

Binary image. Closing with a disc of size 7.
Grayscale image. Closing with a disc of size 7.
Color image. Closing with a disc of size 7.

III.A.3. Opening by Reconstruction (γR(f))

In the opening operation, the dilation is replaced by a reconstruction by dilatation in order to recover the initial shape of the eroded objects.

γR(f) = δR(ε(f),f) (i.e., opening(f(x,y)) = dilationReconstruction(erosion(f(x,y)), f(x,y)))

Effects

Pandore script (bash)

  1. Opening with a disc of size 19:

    perosion 2 9 images/tangrambin.pan i1.pan
    pdilatationreconstruction 8 i1.pan tangrambin.pan tangram_opening.pan
    

Results

Binary image. Opening by reconstruction with a disc of size 23.
Grayscale image. Opening by recontruction with a disc of size 23.
Color image. Opening by reconstruction with a disc of size 15.

III.A.4. Closing by Reconstruction (ΦT(f))

In the closing operation, the erosion is replaced by a reconstruction by erosion in order to recover the initial shape of the dilated objects.

ΦR(f) = εR(δ(f),f) (i.e., closing(f) = erosion(dilation(f)),f)

Effects

Pandore script (bash)

  1. Closing with a square of size 15:

    pdilatation 1 7 images/tangrambin.pan i1.pan
    perosionreconstruction 8 i1.pan tangrambin.pan tangramclo.pan
    

Results

Binary image. Closing with a disc of size 15.
Grayscale image. Closing with a disc of size 15.
Color image. Closing with a disc of size 15.

III.A.5. Geodesic Reconstruction by Dilation

The geodesic reconstruction by dilation is the same operation as the reconstruction by dilatation, except that the operation has an additional parameter that can control the number of dilation. If this parameter is set to -1, the operation is the same as the reconstruction by dilatation.

III.A.6. Geodesic Reconstruction by Erosion

The geodesic reconstruction by erosion is the same operation as the reconstruction by erosion, except that the operation has an additional parameter that can control the number of erosion. If this parameter is set to -1, the operation is the same as the reconstruction by erosion.

III.A.7. Area opening

Area opening removes all white connected components whose area in number of pixels is smaller than a given threshold value. With this operation only the size information is taken into consideration; there is no restriction on the shape.

The algorithm presented in a naive way consists in:

  1. Thresholding image at each gray level.
  2. Removing white regions whose area is smaller than the specified area.
  3. The final result is the addition of the results at each level.

It can be extended to grayscale images to remove all bright structures that have less than the specified number of pixels.

Pandore script (bash)

  1. Area opening to remove tangram pieces smaller than 500 pixels:

    pareaopening 8 50 images/tangrambin.pan tangramao1.pan
    

Results

Binary image. Area opening of size 500 pixels.
Grayscale image. Area opening of size 800 pixels.

III.A.8. Area closing

Area closing removes all dark connected components whose area in number of pixels is smaller than a given threshold value. With this operation, only the size information is taken into consideration; there is no restriction on the shape.

The algorithm presented in a naive way consists in:

  1. Thresholding image at each gray level.
  2. Removing dark regions whose area is smaller than the specified area.
  3. The final result is the addition of the results at each level.

It can be extended to grayscale images to remove all dark structures that have less than threshold pixels.

Pandore script (bash)

  1. Area closing to remove black dots smaller than 20 pixels:

    pareaclosing 8 20 images/esophagusbin.pan esophagusac1.pan
    
  2. Area closing with an area of 500 to remove cells smaller than 500 pixels:

    pareaclosing 8 500 images/esophagusgray.pan esophagusac2.pan
    

Results

Binary image. Area closing of size 20 pixels.
Grayscale image. Area closing of size 500 pixels.

III.B. Top-Hat

These operations are used to detect in a binary or grayscale image peaks or troughs of a certain size independently from their hight.

Morphological top-hats proceeds a contrario. The approach undertaken with top-hats consists of using knowledge about the shape characteristics that are not shared by their relevant image structures. It is sometimes easier to remove relevant structures than trying to directly suppress irrelevant objects. The size and shape of the structuring element used for morphological top-hat depends on the morphology of the structures to be extracted. e.g., to detect bright features of width smaller than w, a WTH with a disc structuring element slightly larger than w should be considered.

If the image is corrupted by a high-frequency noise, it must be filtered before using the morphological top-hat: a closing by a small structuring element before calculating a WTH and an opening before a BTH.

III.B.1. White Top-Hat (WTH(f))

White top-hat is the difference between the original image and its opening:

WTH(f) = f-γ(f)

If the image is corrupted by noise, a closing by small structuring element should be applied first.

Effects

Pandore script (bash)

perosion 1 8 images/tangram.pan i1.pan
pdilatation 1 8 i1.pan i2.pan
psub tangram.pan i2.pan wth.pan

Results

Binary image. WTH with a disc of size 7.
Gray image. WTH with a disc of size 7.
Color image. WTH with a disc of size 7.

III.B.2 Black Top-Hat (BTH(f))

Black top-hat is the difference between the closing of an image and the image itself:

BTH(f) = Φ(f)-f

If the image is corrupted by noise, an opening by small structuring element should be applied first.

Effects

Pandore script (bash)

pdilatation 1 8 images/tangram.pan i1.pan
perosion 1 8 i1.pan i2.pan
psub i2.pan tangram.pan bth.pan

Results

Binary image. BTH with a disc of size 7.
Gray image. BTH with a disc of size 7.
Color image. BTH with a disc of size 7.

III.B.3. Self-Complementary Top-Hat (SCTH(f))

The sum of the black top-hat and white top-hats extracts both peaks and troughs.

SCTH(f) = WTH(f)+BTH(f)

Pandore script (bash)

perosion 2 2 images/tangramgray.pan i1.pan
pdilatation 2 2 i1.pan i2.pan
psub images/tangramgray.pan i2.pan wth.pan

pdilatation 2 2 images/tangramgray.pan i1.pan
perosion 2 2 i1.pan i2.pan
psub i2.pan images/tangramgray.pan bth.pan

padd wth.pan wth.pan self.pan

Results

Binary image. White Top-Hat. Black Top-Hat. Self-Complementary Top-Hat.

III.B.4. Geodesic White Top-Hat

The closing is replaced by a closing by reconstruction.

Pandore script (bash)

perosion 1 8 images/tangram.pan i1.pan
pdilatationreconstruction 8 i1.pan images/tangram.pan i2.pan
pdif images/tangram.pan i2.pan gwth.pan

III.B.5. Geodesic Black Top-Hat

The opening is replaced by an opening by reconstruction.

Pandore script (bash)

pdilatation 1 8 images/tangram.pan i1.pan
perosionreconstruction 8 i1.pan images/tangram.pan i2.pan
pdif images/tangram.pan i2.pan gbth.pan

III.C. Gradient

The gradient is used in image processing to detect edges. A common assumption is that object edges are located where there are high grayscale variation. The gradient returns the maximum variation of the grayscale intensities within the neighborhood defined by the structuring element.

III.C.1. Morphological Gradient (ρ(f))

The morphological gradient is defined as the difference between a dilation and an erosion by the structuring element B:

ρB(f)=δB(f)-εB(f) = dilation(f)-erosion(f)

The dilation is responsible for the external gradient and the erosion is responsible for the internal gradient. It is equivalent to the norm of the gradient : ||∇f||.

Pandore script (bash)

Results

: - =
Grayscale image. Dilation. Erosion. Gradient image.
: - =
Color image. Dilation. Erosion image. Gradient image.

III.C.2. Half Gradient (ρ-(f), ρ+(f))

The thickness of a step-edge detected by a morphological gradient ρ(f) equals two pixels, one pixel on each side of the edge. A zero-thickness can be achieved with inter-pixel approaches, or by defining the edge as the interface between two adjacent regions. Half-gradients can be used to detect either the internal or the external boundary of an edge.

The internal gradient enhances the internal boundaries of objects brighter than their background and external boundaries of objects darker than their background.

ρ-B(f)=f-εB(f)

The external gradient enhances the internal boundaries of objects darker than their background and external boundaries of objects brighter than their background.

ρ+B(f)=δB(f)-f

Pandore script (bash)

Results

- =
Binary image. Erosion. Internal gradient (ρ-).
- =
Dilation. Binary image. External gradient (ρ+).

III.C.3. Directional gradient (ρL(f))

Directional gradient is defined by using linear structural element. It outputs the highest values for the linear structures on the image that have the same direction than the structuring element:

ρL(f) = δL(f)-εL(f)

Pandore script (bash)

plineardilation 0 0 1 images/tangramgray.pan i1.pan
plinearerosion 0 0 1 images/tangramgray.pan i2.pan
pdif i1.pan i2.pan grad.pan

Results

: - =
Grayscale image. Horizontal dilation. Horizontal erosion. Horizontal gradient.

III.C.4. Thick gradient

If the size of the structuring element is greater than 1, the morphological gradient is referred as thick gradient. Thick gradient are suitable when the transitions between objects are smooth.

Pandore script (bash)

Results

: - =
Grayscale image. Dilation of size 11. Erosion of size 11. Resulted gradient image.

III.C.5. Multiscale gradient

The multiscale gradient avoids the problems of the thick gradient that yields thick edges and merges two edges that are at a distance lower than the structuring element size.

The thickness of the gradient of size n can be reduced by using an erosion of size n-1. The separation of two edges can be done by using a white top-hat. As a result, the multiscale gradient is:

ρ*nB= ε(n-1)B(WTHnBnB))

It is then possible to compute an edge map with various scales and structuring elements as the union of the various multiscale gradients:

ρ* = ⋃nB*nB)

Pandore script (bash)

Results

: ⋃..⋃ =
Grayscale image. Gradient of size 3. Gradient of size 11. Resulted multiscale gradient.

III.C.6. Morphological Laplacian

The morphological Laplacian is defined as the arithmetic difference between the internal and the external gradient. The object boundaries are located at the zero-crossing of the Laplacian image.

Pandore script (bash)

pdilation se hs in.pan i1.pan
psub i1.pan in.pan c.pan

perosion se hs in.pan b.pan
psub in.pan b.pan d.pan

psub c.pan d.pan out.pan

III.D. Extremum

III.D.1. H-Maxima (HMAX)

H-maxima transformation suppresses any domes with height smaller or equal than a threshold level h and decreases the height of the other domes by h. It is defined as the reconstruction by dilation of f subtracted by a height h.

HMAXh(f) = Rδf(f-h)

Pandore script (bash)

paddcst -30 images/esophagusgray.pan tmp.pan
pdilationreconstruction 8 tmp.pan images/esophagusgray.pan hmaxima.pan

Results

Input image. H-maxima of height 30. H-maxima of height 50.
Profile of line 94. Profile of line 94. Profile of line 94.

III.D.2. H-Minima (HMIN)

H-minima transformation removes any trough with depth smaller or equal than h and increases the height of the other troughs by h. It is defined as the reconstruction by erosion of f increased by a height h.

HMINh(f) = Rεf(f+h)

Pandore script (bash)

paddcst 30 images/esophagusgray.pan tmp.pan
perosionreconstruction 8 tmp.pan images/esophagusgray.pan hminima.pan

Results

Input image. H-minima of height 30. H-minima of height 50.
Profile of line 94. Profile of line 94. Profile of line 94.

III.D.3. Regional Maxima (RMAX)

The regional maxima are all pixels that are higher than any pixel in its neighborhood. They can be computed from the residue of the h-maxima of height 1.

RMAX(f) = f - HMAX1(f)

Pandore Script (bash)

# smoothing
pmeanfiltering 1 images/esophagusgray.pan in.pan

# RMAX
paddcst -1 in.pan tmp1.pan
pdilationreconstruction 8 tmp1.pan in.pan tmp2.pan
pdif in.pan tmp2.pan tmp3.pan
pbinarization 1 1 tmp3.pan out.pan

Results

Input image f. RMAX(f). Localization of the markers.

III.D.4. Regional Minima (RMIN)

The regional minima are all pixels that are lower than any pixel in its neighborhood. They can be computed from the residue of the h-minima of height 1.

RMIN(f) = HMIN1(f) - f

Pandore Script (bash)

# smoothing
pmeanfiltering 1 images/esophagusgray.pan in.pan

# RMIN
paddcst +1 in.pan tmp1.pan
perosionreconstruction 8 tmp1.pan in.pan tmp2.pan
pdif tmp2.pan in.pan tmp3.pan
pbinarization 1 1 tmp3.pan out.pan

Results

Input image f. RMIN(f). Localization of the markers.

III.D.5. Extended Regional Maxima (EMAX)

The extended maxima EMAX are defined as the regional maxima of the corresponding h-maxima transformation:

EMAXh(f) = RMAX( HMAXh(f) )

Pandore Script (bash)

# smoothing
pmeanfiltering 1 images/esophagusgray.pan in.pan

# HMAX with h=30
paddcst -30 in.pan tmp.pan
pdilationreconstruction 8 tmp.pan in.pan hmaxima.pan

# RMAX (HMAX)
paddcst -1 hmaxima.pan tmp1.pan
pdilationreconstruction 8 tmp1.pan hmaxima.pan tmp2.pan
pdif hmaxima.pan tmp2.pan tmp3.pan
pbinarization 1 1 tmp3.pan emax.pan

Results

Input image f. EMAX(f). Localization of the markers.

III.D.6. Extended Regional Minima (EMIN)

The extended minima EMIN are defined as the regional minima of the corresponding h-minima transformation:

EMINh(f) = RMIN( HMINh(f) )

Pandore Script (bash)

# smoothing
pmeanfiltering 1 images/esophagusgray.pan in.pan

# HMIN with h=30
paddcst 30 in.pan tmp.pan
perosionreconstruction 8 tmp.pan in.pan hminima.pan

# RMIN (HMIN)
paddcst +1 hminima.pan tmp1.pan
perosionreconstruction 8 tmp1.pan hminima.pan tmp2.pan
pdif tmp2.pan hminima.pan tmp3.pan
pbinarization 1 1 tmp3.pan emin.pan

Results

Input image f. EMIN(f). Localization of the markers.

IV. Image Processing

IV.A. Filtering

IV.A.1. Midrange Filter - Dynamic Threshold (DYT)

The average of the erosion and the dilation of an image is analogous to image smoothing.

DYT(f)=1/2[erosion(f)+dilation(f)]

Effects

Pandore script (bash)

=
f. DYT(f).

IV.A.3. Pseudomedian Filter - Texture Thesholding (TEF)

The average of the opening and the closing of an image is analogous to image smoothing which mimics the response to the median filter.

TET(f)=1/2[opening(f)+closing(f)]

Pandore script (bash)

=
f. TET(f).

IV.A.4. Linear Combination of Close-Open and Open-Close

IV.A.4. Alternating sequential filter

Filtering an image containing dark and bright noise can be achieved by a sequence of close-open filters:

A solution to is to alternate closings and openings beginning with a small structuring element and then proceeding with the ever-increasing structuring element until a given size is reached.

ASFrec(closing_n(Opening_n(closingn_1(opening_n-1(closingn_2(... (closing1(opening_1(f)))))))) where n is the size of the filter.

Pandore script (bash)

cp in.pan out.pan
i=1
while [ $i -le $n ]
do
#geodesic opening
perosion $se $i out.pan i1.pan
pdilationreconstruction 8 i1.pan out.pan i2.pan

#geodesic closing
pdilation $se $i i2.pan i3.pan
pdilationreconstruction 8 i3.pan i2.pan out.pan
i=`expr $i + 1`
done

IV.B. Image Enhancement

IV.B.1. Contrast Enhancement

A simple neighborhood-based morphological contrast operator by adding the white top-hat to the original image to enhance bright objects, and subtracting the black top-hat from the resulting image to enhance dark objects. All the pixels falling outside the dynamic range of the original image [ymin, tmax] are clipped.

Κth = f + WTH(f) - BTH(f) = f + f - γB - ΦB + f = 3.f - γB - ΦB

Pandore Script (bash)

perosion 2 2 esophagusgray.pan i1.pan
pdilation 2 2 i1.pan i2.pan
psub esophagusgray.pan i2.pan wth.pan

pdilation 2 2 esophagusgray.pan i3.pan
perosion 2 2 i3.pan i4.pan
psub i4.pan esophagusgray.pan bth.pan

pim2sl esophagusgray.pan i5.pan
padd i5.pan wth.pan i6.pan
psub i6.pan bth.pan enhanced.pan

Results

The major enhancement can be observed inside the cells.

Input image f. White Top-Hat (inversed). Black Top-Hat (inversed). Output image: f+WTH(f)-BTH(f).

IV.B.2. Correction of Uneven Illumination

IV.C. Edge Detection

IV.C.1. Edge

Distinguishing smooth "ramp" edges from ripple "texture edges" i.e: non ramp edges are texture or noise:

IV.D. Segmentation

IV.D.1. Markers Extraction

Marker extraction is one the crucial step in watershed segmentation. A marker is a region that must be placed inside an object to be extracted.

  1. Regional Minima (Maxima)

    The markers are all pixels that are lower (or higher) than any pixel in their neighborhood. This is direct application of the operation RMIN (or RMAX).

    Pandore Script (bash)

    paddcst 1 images/esophagusgray.pan tmp1.pan
    perosionreconstruction 8 tmp1.pan images/esophagusgray.pan tmp2.pan
    pdif tmp2.pan images/esophagusgray.pan tmp3.pan
    pbinarization 1 1 tmp3.pan out.pan
    
  2. Regional Extrema of Closing

    The regional extrema operation (RMIN) is preceded by a closing by a disk of radius 3 in order to reduce the number of regional minima.

    Pandore Script (bash)

    pdilation 2 3 images/esophagusgray.pan tmp1.pan
    perosion 2 3 tmp1.pan tmp2.pan
    
    paddcst 1 tmp2.pan tmp3.pan
    perosionreconstruction 8 tmp3.pan tmp2.pan tmp4.pan
    pdif tmp4.pan tmp2.pan tmp5.pan
    pbinarization 1 1 tmp5.pan out.pan
    
  3. Regional Extrema of Reconstructive Opening

    The regional extrema operation (RMIN) is preceded by a reconstruction from opening by a disk of radius 3.

    Pandore Script (bash)

    pdilation 2 3 images/esophagusgray.pan tmp1.pan
    perosionreconstruction 8 tmp1.pan images/esophagusgray.pan tmp2.pan
    
    paddcst 1 tmp2.pan tmp3.pan
    perosionreconstruction 8 tmp3.pan tmp2.pan tmp4.pan
    pdif tmp4.pan tmp2.pan tmp5.pan
    pbinarization 1 1 tmp5.pan out.pan
    
  4. Regional Extrema of Area Opening

    The regional extrema operation (RMIN) is preceeded by an area opening by a disk of radius 3.

    Pandore Script (bash)

    pareaclosing _ 100 
    paddcst 1 tmp2.pan tmp3.pan
    perosionreconstruction 8 tmp3.pan tmp2.pan tmp4.pan
    pdif tmp4.pan tmp2.pan tmp5.pan
    pbinarization 1 1 tmp5.pan out.pan
    
  5. Regional Extrema of H-minima

    The regional extrema operation (RMIN) is preceeded by a H-minima detection.

    Pandore Script (bash)

    paddcst 1 tmp2.pan tmp3.pan
    perosionreconstruction 8 tmp3.pan tmp2.pan tmp4.pan
    pdif tmp4.pan tmp2.pan tmp5.pan
    pbinarization 1 1 tmp5.pan out.pan
    

Results

Input image. Regional minima. Regional minima of closing by a disk of radius 3.
Regional minima of reconstructive closing by a disk of radius 3. Regional minima of area closing (size = 50). Regional minima of H-Minima (h=10).

IV.D.2. Maxima/Minima Imposition

To force the watershed to pass into certain points or lines, they must be introduced as maxima in the source image.

Pandore Script (bash)

pbinarization 0 0 germes.pan i1.pan
padcst 1 in.pan i2.pan
pmin i1.pan i2.pan i3.pan
perosionreconstruction 8 i1.an i3.pan swamping.pan

IV.D.3. Skiz (Skeleton by influence zones)

Generalized Voronoï diagram: create an image by detection of the lines that are equidistant between two or more connected components.

Pandore script (bash)

pbinarization 100 1e30 images/tangramgray.pan i1.pan
pdistance i1.pan i2.pan
plabeling 8 i1.pan i3.pan
pwatershed i3.pan i2.pan i4.pan
pboundary 8 i4.pan skiz.pan

Results

A gray image. The skiz. Superimposition of the skiz.

IV.D.4. Hit or Miss (Tout ou rien)

Hit or miss is used to find location of one shape among a set of shapes. The shape is defined by two structuring elements: im_se1 is a structuring element that specifies the object part, and im_se2 specified the background part. The transformation can be summarised by the question: "does im_se1 fits the object part while im_se2 fits the object background?."

[UHMT(f)](x) = [erosionse1(f)](x) - [dilationse2(f)](x); if [erosionse1(f)](x) > [dilationse2(f)](x)
               0 otherwise

Pandore Script (bash)

Detect straight lines in the gradient image.

cat > se1.txt << EOF
255 0 3
255 1 3
255 2 3
255 3 3
255 4 3
EOF
cat > se2.txt<<EOF
255 2 0
255 2 1
255 2 5
255 2 6
EOF
ptxt2pan 0 5 7 0 se1.txt se1.pan
ptxt2pan 0 5 7 0 se2.txt se2.pan
pgradient 1 images/tangramgray.pan tmp1.pan tmp2.pan
phitormiss se1.pan se2.pan tmp1.pan tmp2.pan
pbinarization 1 1e30 tmp3.pan hitormiss.pan

Results

A gray image. The object structuring element (x3). The background structuring element (x3). Superimposition of the skiz.

III.D.5. Ultimate eroded (Érodés ultimes)

An ultimate eroded is the last connected component that remains after successive erosion of a region. The ultimate eroded set is the union of all connected components disparing at each erosion step. This is also the maxima of the distance image.

IV.D.5. Mosaic Image

This operation produces an image where each basin of g is valued. This valuation leads to a simplified image f' made of tiles of constant gray values.

IV.E. Image Analysis

IV.E.1. Filling Holes

The holes in a binary image are supposed to be a set of background pixels that are not connected to the image border. Hence, filling the holes of a binary image consists in removing all background pixels which are not connected to the image border. This is done by using a reconstruction by erosion where the marker image is a white image except along its border where the values of the original image is used.

This can be extended to grayscale images. In this case, the holes are supposed to be the regional minima that are not connected to the image border.

Pandore script (bash)

psetcst 255 images/tangrambin.pan i1.pan
pcopyborder 1 1 1 1 1 1 images/tangrambin.pan i1.pan markers.pan
perosionreconstruction 4 markers.pan images/tangrambin.pan fillholebin.pan

Results

A binary image. The marker image (a white image with a black border). The reconstruction by erosion.

IV.E.2. Detection or Removal of Objects Connected to the Image Border

Assuming objects are sets of white pixels and background is set of black pixels, objects connected to the image border are extracted using reconstruction by dilation of the input image into a mask image equals to a black image except along its border where the value of the input image are considered. A simple subtraction with the input image removes the object connected to the image border.

The detection and removal of objects connected to the image border can be extended to grayscale images. This can be used to remove regions connected to the image border that are equals or brighter than the connected border pixels.

Pandore script (bash)

psetcst 0 images/tangrambin.pan i1.pan
pcopyborder 1 1 1 1 1 1 images/tangrambin.pan i1.pan markers.pan
pdilationreconstruction 8 markers.pan images/tangrambin.pan borderobjectbin1.pan
pdif images/eosophagusbin.pan borderobjectbin1.pan borderobjectbin2.pan

Results

A binary image. The reconstruction by dilation. Result of the suppression.

IV.E.3. Separation of Convex Objects

IV.E.5. Granulometry

V. Variations

V.A. Rotational Morphological Processing

Rotational Morphological Procesing (RMP) operated morphological operations by considering several rotations of the image with respect to the structuring that is fixed in one direction. It assumes that the full 180° angles are equally divided into N directions, the function fi denotes the rotation of the original image f by the degree θi = 180 i/N. The image is rotated clockwise on the centre of the image frame. The image operated by the RMP are followed by rotation at θi degrees in the counter-clockwise direction. The processed images are finally compiled together by combining pixel values according +to certain rules; for exemple the max, min values of the pixel in each rotated images.

V.B. Fuzzy Rotational Morphological Processing

Grayscale structuring elements can be used to perform fuzzy morphological processing. The structuring element Bis not only a mask, but a matrix of the weight assigned to each pixel in the structuring element. The idea is to rate the contribution to each point of the mask by: value/255. During the set of operations, the value of a pixel f(x,y) masked by the structuring element value B(i,j) is: f(x,y)*B(i,j)/255.

This is not implemented in the current Pandore library.

References


The Pantheon project
Image Team GREYC Laboratory
UMR CNRS 6072 - ENSICAEN - University of Caen, France
This page was last modified on 24 June 2016