Leptonica 1.54
Файл src/edge.c
#include <stdio.h>
#include <stdlib.h>
#include "allheaders.h"

Функции

PIXpixSobelEdgeFilter (PIX *pixs, l_int32 orientflag)
PIXpixTwoSidedEdgeFilter (PIX *pixs, l_int32 orientflag)
l_int32 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_int32 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)

Функции

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

pixGetEdgeProfile()

Input: pixs (1 bpp) side (L_FROM_LEFT, L_FROM_RIGHT, L_FROM_TOP, L_FROM_BOTTOM) debugfile (<optional> displays constructed edge; use NULL for no output) Return: na (of fg edge pixel locations), or null on error

l_int32 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 
)
l_int32 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()

Input: pixs (1 bpp) side (L_FROM_LEFT, L_FROM_RIGHT, L_FROM_TOP, L_FROM_BOTTOM) minjump (minimum jump to be counted; >= 1) minreversal (minimum reversal size for new peak or valley) &jpl (<optional return>=""> jumps/length: number of jumps, normalized to length of component side) &jspl (<optional return>=""> jumpsum/length: sum of all sufficiently large jumps, normalized to length of component side) &rpl (<optional return>=""> reversals/length: number of peak-to-valley or valley-to-peak reversals, normalized to length of component side) debugfile (<optional> displays constructed edge; use NULL for no output) Return: 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 >= , normalized to the length of the side * jump sum/length: (jspl) the sum of all jump lengths of size >= , normalized to the length of the side * reversals/length: (rpl) the number of peak <--> valley reversals, using as a minimum deviation of the peak or valley from its preceeding extremum, normalized to the length of the side (2) The input pix should be a single connected component, but this is not required.

PIX* pixSobelEdgeFilter ( PIX pixs,
l_int32  orientflag 
)

pixSobelEdgeFilter()

Input: pixs (8 bpp; no colormap) orientflag (L_HORIZONTAL_EDGES, L_VERTICAL_EDGES, L_ALL_EDGES) Return: 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.

PIX* pixTwoSidedEdgeFilter ( PIX pixs,
l_int32  orientflag 
)

pixTwoSidedEdgeFilter()

Input: pixs (8 bpp; no colormap) orientflag (L_HORIZONTAL_EDGES, L_VERTICAL_EDGES) Return: 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.