# mmasfrec
Reconstructive Alternating Sequential Filtering

## Synopsis

y = mmasfrec( f, SEQ = "OC", b = None, bc = None, n = 1 )

Implemented in Python.

### Input

f | Image Gray-scale (uint8 or uint16) or binary image.
SEQ | String Values: "OC" or "CO". Default: `"OC"`
b | Structuring Element Default: `None` (3x3 elementary cross)
bc | Structuring Element Default: `None` (3x3 elementary cross)
n | Double Non-negative integer. (number of iterations). Default: `1`

### Output

y | Image Same type of `f`

## Description

`mmasf` creates the image `y` by filtering the image `f` by `n` iterations of the close by reconstruction and open by reconstruction alternating sequential filter characterized by the structuring element `b`. The structure element `bc` is used in the reconstruction. The sequence of opening and closing is controlled by the parameter `SEQ`. 'OC' performs opening after closing, and 'CO' performs closing after opening.

## Examples

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

    >>> g=mmasfrec(f,'oc',mmsecross(),mmsecross(),3)

    >>> mmshow(f)

    >>> mmshow(g)

f | g |

## Equation

Case oc, reconstructive close-open filter:
Case co, reconstructive open-close filter:

## Source Code

    def mmasfrec(f, SEQ="OC", b=None, bc=None, n=1):
        from string import upper
        if b is None: b = mmsecross()
        if bc is None: bc = mmsecross()
        SEQ = upper(SEQ)
        y = f
        if SEQ == 'OC':
            for i in range(1,n+1):
                nb = mmsesum(b,i)
                y = mmcloserec(y,nb,bc)
                y = mmopenrec(y,nb,bc)
        elif SEQ == 'CO':
            for i in range(1,n+1):
                nb = mmsesum(b,i)
                y = mmopenrec(y,nb,bc)
                y = mmcloserec(y,nb,bc)
        else:
            assert 0,'Only accepts OC or CO for SEQ parameter'
        return y

## See also

mmasf | Alternating Sequential Filtering
mmsebox | Create a box structuring element.
mmsecross | Diamond structuring element and elementary 3x3 cross.
mmopenrec | Opening by reconstruction.
mmcloserec | Closing by reconstruction.
mmfreedom | Control automatic data type conversion.

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