Leptonica  1.82.0
Image processing and image analysis suite
edge.c File Reference
#include "allheaders.h"

Go to the source code of this file.

Functions

PIXpixSobelEdgeFilter (PIX *pixs, l_int32 orientflag)
 
PIXpixTwoSidedEdgeFilter (PIX *pixs, l_int32 orientflag)
 
l_ok pixMeasureEdgeSmoothness (PIX *pixs, l_int32 side, l_int32 minjump, l_int32 minreversal, l_float32 *pjpl, l_float32 *pjspl, l_float32 *prpl, const char *debugfile)
 
NUMApixGetEdgeProfile (PIX *pixs, l_int32 side, const char *debugfile)
 
l_ok pixGetLastOffPixelInRun (PIX *pixs, l_int32 x, l_int32 y, l_int32 direction, l_int32 *ploc)
 
l_int32 pixGetLastOnPixelInRun (PIX *pixs, l_int32 x, l_int32 y, l_int32 direction, l_int32 *ploc)
 

Detailed Description

     Sobel edge detecting filter
         PIX      *pixSobelEdgeFilter()
     Two-sided edge gradient filter
         PIX      *pixTwoSidedEdgeFilter()
     Measurement of edge smoothness
         l_int32   pixMeasureEdgeSmoothness()
         NUMA     *pixGetEdgeProfile()
         l_int32   pixGetLastOffPixelInRun()
         l_int32   pixGetLastOnPixelInRun()
 The Sobel edge detector uses these two simple gradient filters.
      1    2    1             1    0   -1
      0    0    0             2    0   -2
     -1   -2   -1             1    0   -1
     (horizontal)             (vertical)
 To use both the vertical and horizontal filters, set the orientation
 flag to L_ALL_EDGES; this sums the abs. value of their outputs,
 clipped to 255.
 See comments below for displaying the resulting image with
 the edges dark, both for 8 bpp and 1 bpp.

Definition in file edge.c.

Function Documentation

◆ pixGetEdgeProfile()

NUMA* pixGetEdgeProfile ( PIX pixs,
l_int32  side,
const char *  debugfile 
)

pixGetEdgeProfile()

Parameters
[in]pixs1 bpp
[in]sideL_FROM_LEFT, L_FROM_RIGHT, L_FROM_TOP, L_FROM_BOT
[in]debugfile[optional] displays constructed edge; use NULL for no output
Returns
na of fg edge pixel locations, or NULL on error

Definition at line 389 of file edge.c.

References L_Dewarp::h, L_Dewarp::pixs, and L_Dewarp::w.

◆ pixMeasureEdgeSmoothness()

l_ok pixMeasureEdgeSmoothness ( PIX pixs,
l_int32  side,
l_int32  minjump,
l_int32  minreversal,
l_float32 *  pjpl,
l_float32 *  pjspl,
l_float32 *  prpl,
const char *  debugfile 
)

pixMeasureEdgeSmoothness()

Parameters
[in]pixs1 bpp
[in]sideL_FROM_LEFT, L_FROM_RIGHT, L_FROM_TOP, L_FROM_BOT
[in]minjumpminimum jump to be counted; >= 1
[in]minreversalminimum reversal size for new peak or valley
[out]pjpl[optional] jumps/length: number of jumps, normalized to length of component side
[out]pjspl[optional] jumpsum/length: sum of all sufficiently large jumps, normalized to length of component side
[out]prpl[optional] reversals/length: number of peak-to-valley or valley-to-peak reversals, normalized to length of component side
[in]debugfile[optional] displays constructed edge; use NULL for no output
Returns
0 if OK, 1 on error
Notes:
     (1) This computes three measures of smoothness of the edge of a
         connected component:
           * jumps/length: (jpl) the number of jumps of size >= minjump,
             normalized to the length of the side
           * jump sum/length: (jspl) the sum of all jump lengths of
             size >= minjump, normalized to the length of the side
           * reversals/length: (rpl) the number of peak <--> valley
             reversals, using minreverse as a minimum deviation of
             the peak or valley from its preceding extremum,
             normalized to the length of the side
     (2) The input pix should be a single connected component, but
         this is not required.

Definition at line 312 of file edge.c.

References L_Dewarp::pixs.

◆ pixSobelEdgeFilter()

PIX* pixSobelEdgeFilter ( PIX pixs,
l_int32  orientflag 
)

pixSobelEdgeFilter()

Parameters
[in]pixs8 bpp; no colormap
[in]orientflagL_HORIZONTAL_EDGES, L_VERTICAL_EDGES, L_ALL_EDGES
Returns
pixd 8 bpp, edges are brighter, or NULL on error
Notes:
     (1) Invert pixd to see larger gradients as darker (grayscale).
     (2) To generate a binary image of the edges, threshold
         the result using pixThresholdToBinary().  If the high
         edge values are to be fg (1), invert after running
         pixThresholdToBinary().
     (3) Label the pixels as follows:
             1    4    7
             2    5    8
             3    6    9
         Read the data incrementally across the image and unroll
         the loop.
     (4) This runs at about 45 Mpix/sec on a 3 GHz processor.

Definition at line 94 of file edge.c.

References L_Dewarp::h, L_ALL_EDGES, L_HORIZONTAL_EDGES, L_VERTICAL_EDGES, pixAddMirroredBorder(), pixCreateTemplate(), pixGetData(), pixGetDimensions(), L_Dewarp::pixs, and L_Dewarp::w.

◆ pixTwoSidedEdgeFilter()

PIX* pixTwoSidedEdgeFilter ( PIX pixs,
l_int32  orientflag 
)

pixTwoSidedEdgeFilter()

Parameters
[in]pixs8 bpp; no colormap
[in]orientflagL_HORIZONTAL_EDGES, L_VERTICAL_EDGES
Returns
pixd 8 bpp, edges are brighter, or NULL on error
Notes:
     (1) For detecting vertical edges, this considers the
         difference of the central pixel from those on the left
         and right.  For situations where the gradient is the same
         sign on both sides, this computes and stores the minimum
         (absolute value of the) difference.  The reason for
         checking the sign is that we are looking for pixels within
         a transition.  By contrast, for single pixel noise, the pixel
         value is either larger than or smaller than its neighbors,
         so the gradient would change direction on each side.  Horizontal
         edges are handled similarly, looking for vertical gradients.
     (2) To generate a binary image of the edges, threshold
         the result using pixThresholdToBinary().  If the high
         edge values are to be fg (1), invert after running
         pixThresholdToBinary().
     (3) This runs at about 60 Mpix/sec on a 3 GHz processor.
         It is about 30% faster than Sobel, and the results are
         similar.

Definition at line 202 of file edge.c.

References L_Dewarp::h, L_HORIZONTAL_EDGES, L_VERTICAL_EDGES, pixCreateTemplate(), pixGetData(), pixGetDimensions(), L_Dewarp::pixs, and L_Dewarp::w.