Leptonica 1.68
C Image Processing Library

graymorph.c File Reference

Top-level grayscale morphological operations. More...

#include <stdio.h>
#include <stdlib.h>
#include "allheaders.h"

Go to the source code of this file.

Functions

static PIXpixErodeGray3h (PIX *pixs)
static PIXpixErodeGray3v (PIX *pixs)
static PIXpixDilateGray3h (PIX *pixs)
static PIXpixDilateGray3v (PIX *pixs)
PIXpixErodeGray (PIX *pixs, l_int32 hsize, l_int32 vsize)
PIXpixDilateGray (PIX *pixs, l_int32 hsize, l_int32 vsize)
PIXpixOpenGray (PIX *pixs, l_int32 hsize, l_int32 vsize)
PIXpixCloseGray (PIX *pixs, l_int32 hsize, l_int32 vsize)
PIXpixErodeGray3 (PIX *pixs, l_int32 hsize, l_int32 vsize)
PIXpixDilateGray3 (PIX *pixs, l_int32 hsize, l_int32 vsize)
PIXpixOpenGray3 (PIX *pixs, l_int32 hsize, l_int32 vsize)
PIXpixCloseGray3 (PIX *pixs, l_int32 hsize, l_int32 vsize)

Detailed Description

Top-level grayscale morphological operations.

    Top-level binary morphological operations (van Herk / Gil-Werman)
          PIX     *pixErodeGray()
          PIX     *pixDilateGray()
          PIX     *pixOpenGray()
          PIX     *pixCloseGray()

    Special operations for 1x3, 3x1 and 3x3 Sels  (direct)
          PIX     *pixErodeGray3()
          PIX     *pixDilateGray3()
          PIX     *pixOpenGray3()
          PIX     *pixCloseGray3()


    Method: Algorithm by van Herk and Gil and Werman, 1992

    Measured speed of the vH/G-W implementation is about 1 output
    pixel per 120 PIII clock cycles, for a horizontal or vertical
    erosion or dilation.  The computation time doubles for opening
    or closing, or for a square SE, as expected, and is independent
    of the size of the SE.

    A faster implementation can be made directly for brick Sels
    of maximum size 3.  We unroll the computation for sets of 8 bytes.
    It needs to be called explicitly; the general functions do not
    default for the size 3 brick Sels.

Definition in file graymorph.c.


Function Documentation

static PIX * pixErodeGray3h ( PIX pixs) [static]

pixErodeGray3h()

Input: pixs (8 bpp, not cmapped) Return: pixd, or null on error

Notes: (1) Special case for horizontal 3x1 brick Sel; also used as the first step for the 3x3 brick Sel.

Definition at line 602 of file graymorph.c.

References ERROR_PTR, GET_DATA_BYTE, L_MIN, NULL, pixCreateTemplateNoInit(), pixGetData(), pixGetDepth(), pixGetDimensions(), pixGetWpl(), pixSetBorderVal(), PROCNAME, and SET_DATA_BYTE.

Referenced by pixCloseGray3(), pixErodeGray3(), and pixOpenGray3().

static PIX * pixErodeGray3v ( PIX pixs) [static]

pixErodeGray3v()

Input: pixs (8 bpp, not cmapped) Return: pixd, or null on error

Notes: (1) Special case for vertical 1x3 brick Sel; also used as the second step for the 3x3 brick Sel. (2) Surprisingly, this is faster than setting up the lineptrs array and accessing into it; e.g., val4 = GET_DATA_BYTE(lines8[i + 3], j);

Definition at line 668 of file graymorph.c.

References ERROR_PTR, GET_DATA_BYTE, L_MIN, NULL, pixCreateTemplateNoInit(), pixGetData(), pixGetDepth(), pixGetDimensions(), pixGetWpl(), PROCNAME, and SET_DATA_BYTE.

Referenced by pixCloseGray3(), pixErodeGray3(), and pixOpenGray3().

static PIX * pixDilateGray3h ( PIX pixs) [static]

pixDilateGray3h()

Input: pixs (8 bpp, not cmapped) Return: pixd, or null on error

Notes: (1) Special case for horizontal 3x1 brick Sel; also used as the first step for the 3x3 brick Sel.

Definition at line 783 of file graymorph.c.

References ERROR_PTR, GET_DATA_BYTE, L_MAX, NULL, pixCreateTemplateNoInit(), pixGetData(), pixGetDepth(), pixGetDimensions(), pixGetWpl(), pixSetBorderVal(), PROCNAME, and SET_DATA_BYTE.

Referenced by pixCloseGray3(), pixDilateGray3(), and pixOpenGray3().

static PIX * pixDilateGray3v ( PIX pixs) [static]

pixDilateGray3v()

Input: pixs (8 bpp, not cmapped) Return: pixd, or null on error

Notes: (1) Special case for vertical 1x3 brick Sel; also used as the second step for the 3x3 brick Sel.

Definition at line 846 of file graymorph.c.

References ERROR_PTR, GET_DATA_BYTE, L_MAX, NULL, pixCreateTemplateNoInit(), pixGetData(), pixGetDepth(), pixGetDimensions(), pixGetWpl(), PROCNAME, and SET_DATA_BYTE.

Referenced by pixCloseGray3(), pixDilateGray3(), and pixOpenGray3().

PIX* pixErodeGray ( PIX pixs,
l_int32  hsize,
l_int32  vsize 
)

pixErodeGray()

Input: pixs hsize (of Sel; must be odd; origin implicitly in center) vsize (ditto) Return: pixd

Notes: (1) Sel is a brick with all elements being hits (2) If hsize = vsize = 1, just returns a copy.

Definition at line 73 of file graymorph.c.

References CALLOC, erodeGrayLow(), ERROR_PTR, FREE, L_HORIZ, L_MAX, L_VERT, L_WARNING, maxsize, NULL, PIX_SET, pixAddBorderGeneral(), pixClone(), pixCopy(), pixCreateTemplate(), pixDestroy(), pixGetData(), pixGetDepth(), pixGetDimensions(), pixGetWpl(), pixRemoveBorderGeneral(), pixSetOrClearBorder(), and PROCNAME.

Referenced by main(), pixColorMorph(), pixGrayMorphSequence(), pixLocalExtrema(), pixRankFilterGray(), and pixSelectedLocalExtrema().

PIX* pixDilateGray ( PIX pixs,
l_int32  hsize,
l_int32  vsize 
)

pixDilateGray()

Input: pixs hsize (of Sel; must be odd; origin implicitly in center) vsize (ditto) Return: pixd

Notes: (1) Sel is a brick with all elements being hits (2) If hsize = vsize = 1, just returns a copy.

Definition at line 182 of file graymorph.c.

References CALLOC, dilateGrayLow(), ERROR_PTR, FREE, L_HORIZ, L_MAX, L_VERT, L_WARNING, maxsize, NULL, PIX_CLR, pixAddBorderGeneral(), pixClone(), pixCopy(), pixCreateTemplate(), pixDestroy(), pixGetData(), pixGetDepth(), pixGetDimensions(), pixGetWpl(), pixRemoveBorderGeneral(), pixSetOrClearBorder(), and PROCNAME.

Referenced by main(), pixColorMorph(), pixGrayMorphSequence(), pixMorphGradient(), pixRankFilterGray(), and pixSelectedLocalExtrema().

PIX* pixOpenGray ( PIX pixs,
l_int32  hsize,
l_int32  vsize 
)

pixOpenGray()

Input: pixs hsize (of Sel; must be odd; origin implicitly in center) vsize (ditto) Return: pixd

Notes: (1) Sel is a brick with all elements being hits (2) If hsize = vsize = 1, just returns a copy.

Definition at line 291 of file graymorph.c.

References CALLOC, dilateGrayLow(), erodeGrayLow(), ERROR_PTR, FREE, L_HORIZ, L_MAX, L_VERT, L_WARNING, maxsize, NULL, PIX_CLR, PIX_SET, pixAddBorderGeneral(), pixCopy(), pixCreateTemplate(), pixDestroy(), pixGetData(), pixGetDepth(), pixGetDimensions(), pixGetWpl(), pixRemoveBorderGeneral(), pixSetOrClearBorder(), and PROCNAME.

Referenced by main(), pixColorMorph(), pixGrayMorphSequence(), and pixTophat().

PIX* pixCloseGray ( PIX pixs,
l_int32  hsize,
l_int32  vsize 
)

pixCloseGray()

Input: pixs hsize (of Sel; must be odd; origin implicitly in center) vsize (ditto) Return: pixd

Notes: (1) Sel is a brick with all elements being hits (2) If hsize = vsize = 1, just returns a copy.

Definition at line 417 of file graymorph.c.

References CALLOC, dilateGrayLow(), erodeGrayLow(), ERROR_PTR, FREE, L_HORIZ, L_MAX, L_VERT, L_WARNING, maxsize, NULL, PIX_CLR, PIX_SET, pixAddBorderGeneral(), pixCopy(), pixCreateTemplate(), pixDestroy(), pixGetData(), pixGetDepth(), pixGetDimensions(), pixGetWpl(), pixRemoveBorderGeneral(), pixSetOrClearBorder(), and PROCNAME.

Referenced by main(), pixColorMorph(), pixGetBackgroundGrayMapMorph(), pixGetBackgroundRGBMapMorph(), pixGrayMorphSequence(), and pixTophat().

PIX* pixErodeGray3 ( PIX pixs,
l_int32  hsize,
l_int32  vsize 
)

pixErodeGray3()

Input: pixs (8 bpp, not cmapped) hsize (1 or 3) vsize (1 or 3) Return: pixd, or null on error

Notes: (1) Special case for 1x3, 3x1 or 3x3 brick sel (all hits) (2) If hsize = vsize = 1, just returns a copy. (3) It would be nice not to add a border, but it is required if we want the same results as from the general case. We add 4 bytes on the left to speed up the copying, and 8 bytes at the right and bottom to allow unrolling of the computation of 8 pixels.

Definition at line 551 of file graymorph.c.

References ERROR_PTR, NULL, pixAddBorderGeneral(), pixCopy(), pixDestroy(), pixErodeGray3h(), pixErodeGray3v(), pixGetColormap(), pixGetDepth(), pixRemoveBorderGeneral(), and PROCNAME.

Referenced by main().

PIX* pixDilateGray3 ( PIX pixs,
l_int32  hsize,
l_int32  vsize 
)

pixDilateGray3()

Input: pixs (8 bpp, not cmapped) hsize (1 or 3) vsize (1 or 3) Return: pixd, or null on error

Notes: (1) Special case for 1x3, 3x1 or 3x3 brick sel (all hits) (2) If hsize = vsize = 1, just returns a copy.

Definition at line 732 of file graymorph.c.

References ERROR_PTR, NULL, pixAddBorderGeneral(), pixCopy(), pixDestroy(), pixDilateGray3h(), pixDilateGray3v(), pixGetColormap(), pixGetDepth(), pixRemoveBorderGeneral(), and PROCNAME.

Referenced by main().

PIX* pixOpenGray3 ( PIX pixs,
l_int32  hsize,
l_int32  vsize 
)

pixOpenGray3()

Input: pixs (8 bpp, not cmapped) hsize (1 or 3) vsize (1 or 3) Return: pixd, or null on error

Notes: (1) Special case for 1x3, 3x1 or 3x3 brick sel (all hits) (2) If hsize = vsize = 1, just returns a copy. (3) It would be nice not to add a border, but it is required to get the same results as for the general case.

Definition at line 912 of file graymorph.c.

References ERROR_PTR, NULL, pixAddBorderGeneral(), pixCopy(), pixDestroy(), pixDilateGray3h(), pixDilateGray3v(), pixErodeGray3h(), pixErodeGray3v(), pixGetColormap(), pixGetDepth(), pixRemoveBorderGeneral(), pixSetBorderVal(), and PROCNAME.

Referenced by main().

PIX* pixCloseGray3 ( PIX pixs,
l_int32  hsize,
l_int32  vsize 
)

pixCloseGray3()

Input: pixs (8 bpp, not cmapped) hsize (1 or 3) vsize (1 or 3) Return: pixd, or null on error

Notes: (1) Special case for 1x3, 3x1 or 3x3 brick sel (all hits) (2) If hsize = vsize = 1, just returns a copy.

Definition at line 978 of file graymorph.c.

References ERROR_PTR, NULL, pixAddBorderGeneral(), pixCopy(), pixDestroy(), pixDilateGray3h(), pixDilateGray3v(), pixErodeGray3h(), pixErodeGray3v(), pixGetColormap(), pixGetDepth(), pixRemoveBorderGeneral(), pixSetBorderVal(), and PROCNAME.

Referenced by main().

 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines