# mmregmin
Regional Minimum (with generalized dynamics).

## Synopsis

y = mmregmin( f, Bc = None, option = "binary" )

Implemented in Python.

### Input

f | Image Gray-scale (uint8 or uint16) image.
Bc | Structuring Element (connectivity). Default: `None` (3x3 elementary cross)
option | String Choose one of: BINARY: output a binary image; VALUE: output a grayscale image with points at the regional minimum with the pixel values of the input image; DYNAMICS: output a grayscale image with points at the regional minimum with its dynamics; AREA-DYN: int32 image with the area-dynamics; VOLUME-DYN: int32 image with the volume-dynamics. Default: `"binary"`

### Output

y | Image Gray-scale (uint8 or uint16) or binary image.

## Description

mmregmin creates a binary image `f` by computing the regional minima of `f`, according to the connectivity defined by the structuring element `Bc`. A regional minimum is a flat zone not surrounded by flat zones of lower gray values. A flat zone is a maximal connected component of a gray-scale image with same pixel values. There are three output options: binary image; valued image; and generalized dynamics. The dynamics of a regional minima is the minimum height a pixel has to climb in a walk to reach another regional minima with a higher dynamics. The area-dyn is the minimum area a catchment basin has to raise to reach another regional minima with higher area-dynamics. The volume-dyn is the minimum volume a catchment basin has to raise to reach another regional minima with a higher volume dynamics.
The dynamics concept was first introduced in Grimaud:92 and it is the basic notion for the hierarchical or multiscale watershed transform.

## Examples

Numerical example:

    >>> a = uint8([
        [10,  10,  10,  10,  10,  10,  10],
        [10,   9,   6,  18,   6,   5,  10],
        [10,   9,   6,  18,   6,   5,  10],
        [10,   9,   9,  15,   4,   9,  10],
        [10,   9,   9,  15,  12,  10,  10],
        [10,  10,  10,  10,  10,  10,  10]])

    >>> print mmregmin(a)

    [[0 0 0 0 0 0 0]
     [0 0 1 0 0 1 0]
     [0 0 1 0 0 1 0]
     [0 0 0 0 1 0 0]
     [0 0 0 0 0 0 0]
     [0 0 0 0 0 0 0]]

    >>> print mmregmin(a,mmsecross(),'value')

    [[0 0 0 0 0 0 0]
     [0 0 6 0 0 5 0]
     [0 0 6 0 0 5 0]
     [0 0 0 0 4 0 0]
     [0 0 0 0 0 0 0]
     [0 0 0 0 0 0 0]]

    >>> print mmregmin(a,mmsecross(),'dynamics')

    [[ 0  0  0  0  0  0  0]
     [ 0  0  4  0  0  1  0]
     [ 0  0  4  0  0  1  0]
     [ 0  0  0  0 14  0  0]
     [ 0  0  0  0  0  0  0]
     [ 0  0  0  0  0  0  0]]

Image example, filtering the regional minima:
Typically, the regional minima is very numerous in a real image. To filter the regional minima, one can use the mmhmin, mmclose, mmareaclose, or other functions that simplifies basins.

    >>> f1=mmreadgray('bloodcells.tif')

    >>> m1=mmregmin(f1,mmsebox())

    >>> mmshow(f1,m1)

    >>> f2=mmhmin(f1,70)

    >>> mmshow(f2)

    >>> m2=mmregmin(f2,mmsebox())

    >>> mmshow(f2,m2)

f1,m1 | f2 |

f2,m2 |

Multiscale watershed
To build a pyramid of nested segmentations, use the marker for the watershed only the minima above a given dynamic. Two levels of this pyramid are build below, one with dynamic above 20 and the other, above 40.

    >>> f=mmreadgray('cameraman.tif')

    >>> g=mmgradm(f)

    >>> mh=mmregmin(g,mmsecross(),'dynamics')

    >>> ws1=mmcwatershed(g, mmbinary(mh, 20))

    >>> ws2=mmcwatershed(g, mmbinary(mh, 40))

    >>> mmshow(ws1)

    >>> mmshow(ws2)

ws1 | ws2 |

## Equation

## Source Code

    def mmregmin(f, Bc=None, option="binary"):
        if Bc is None: Bc = mmsecross()
        fplus = mmaddm(f,1)
        g = mmsubm(mmsuprec(fplus,f,Bc),f)
        y = mmunion(mmthreshad(g,1),mmthreshad(f,0,0))
        return y

## See also

mmfreedom | Control automatic data type conversion.
mmregmax | Regional Maximum.
mmsebox | Create a box structuring element.
mmsecross | Diamond structuring element and elementary 3x3 cross.
mmhmin | Remove basins with contrast less than h.
mmareaclose | Area closing

[`mmregmax`] [Up] [`mmsuprec`] |
Copyright (c) 2003, Roberto A. Lotufo, UNICAMP-University of Campinas; Rubens C. Machado, CenPRA-Renato Archer Research Center.