# mmareaopen
Area opening

## Synopsis

y = mmareaopen( f, a, Bc = None )

Implemented in Python.

### Input

f | Image Gray-scale (uint8 or uint16) or binary image.
a | Double non negative integer.
Bc | Structuring Element ( connectivity). Default: `None` (3x3 elementary cross)

### Output

y | Image Same type of `f`

## Description

mmareaopen removes any grain (i.e., connected component) with area less than `a` of a binary image `f`. The connectivity is given by the structuring element `Bc`. This operator is generalized to gray-scale images by applying the binary operator successively on slices of `f` taken from higher threshold levels to lower threshold levels.

## Examples

Numerical examples:

    >>> f=mmbinary(uint8([
     [1, 1, 0, 0, 0, 0, 1],
     [1, 0, 1, 1, 1, 0, 1],
     [0, 0, 0, 0, 1, 0, 0]]))

    >>> y=mmareaopen(f,4,mmsecross())

    >>> print y

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

    >>> f=uint8([
       [10,   11,   0,    0,   0,   0,  20],
       [10,    0,   5,    8,   9,   0,  15],
       [10,    0,   0,    0,  10,   0,   0]])

    >>> y=mmareaopen(f,4,mmsecross())

    >>> print y

    [[10 10  0  0  0  0  0]
     [10  0  5  5  5  0  0]
     [10  0  0  0  5  0  0]]

Binary image

    >>> a=mmreadgray('form-1.tif');

    >>> b=mmareaopen(a,500);

    >>> mmshow(a);

    >>> mmshow(b);

a | b |

Gray-scale image

    >>> a=mmreadgray('bloodcells.tif');

    >>> b=mmareaopen(a,500);

    >>> mmshow(a);

    >>> mmshow(b);

a | b |

## Equation

## Limitations

The structuring elements allowed are the elementary cross (4-connected) and the elementary box (8-connected).

## Source Code

    def mmareaopen(f, a, Bc=None):
        if Bc is None: Bc = mmsecross()
        if mmisbinary(f):
          fr = mmlabel(f,Bc)      # binary area open, use area measurement
          g = mmblob(fr,'area')
          y = mmthreshad(g,a)
        else:
          y = mmintersec(f,0)
          zero = mmbinary(y)
          k1 = mmstats(f,'min')
          k2 = mmstats(f,'max')
          for k in range(k1,k2+1):   # gray-scale, use thresholding decomposition
            fk = mmthreshad(f,k)
            fo = mmareaopen(fk,a,Bc)
            if mmisequal(fo,zero):
              break
            y = mmunion(y, mmgray(fo,mmdatatype(f),k))
        return y

## See also

mmfreedom | Control automatic data type conversion.
mmlabel | Label a binary image.
mmsebox | Create a box structuring element.
mmsecross | Diamond structuring element and elementary 3x3 cross.
mmareaclose | Area closing

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