[Leptonica Home Page]

High Level Outline of Source Code

Contributed by Will Brockman

Update: Jan 3, 2017

Basic Pix functions
Basic Pix array functions
Low-level pixel access
Basic Box, Boxa and Boxaa functions
Colormap utilities and related operations
Float-valued images
Image scaling
Other geometric image transforms
Basic image operations: rasterop, arithmetic, convolution and correlation
Image operations with filling: seedfill and watershed
Image quantization and depth conversion in general
Image morphology
Auto-gen'd Destination Word Accumulation (DWA) morphology code
Specialized image filters
Connected components in binary images
Formatted I/O
Line graphics and special output
Specialized document image processing
Fundamental data structures for computation
Miscellaneous utilities
Maze: an example of BF search
Header files: struct, enum and const definitions
Compile configuration: selection of runtime and external libraries

Basic Pix functions

compare.c: Pix equality, binary Pix correlation, image differences
pix1.c: Implements Pix (image) class - the fundamental one for this library
pix2.c: Pixel poking of image, pad and border pixels
pix3.c: Masking and logical ops, counting, mirrored tiling
pix4.c: Histograms, row/column statistics, fg/bg estimation
pix5.c: 1 bpp image property measurements, pixel averages and intensity reversals, rectangle extraction

Basic Pix array functions

pixalloc.c: Custom memory allocation for Pix memory
pixabasic.c: Implements Pixa (array of Pix) and Pixaa (2d array of Pix) class
pixafunc1.c: Binary Pixa (array of Pix) filtering, sorting, clipping. See conncomp.c
pixafunc2.c: Render a Pixa or Pixaa in a Pix
pixcomp.c: Compressing and serializing arrays of compressed strings of images
pixtiling.c: Split an image into tiles and perform operations independently on each tile

Low-level pixel access

arrayaccess.c: Function access to pixels in 32-bit arrays
arrayaccess.h: Macro access to pixels in 32-bit arrays
runlength.c: Run-length-encoding, horizontal and vertical run membership

Basic Box, Boxa and Boxaa functions

boxbasic.c: Implementation of Box, Boxa (Box array), and Boxaa classes
boxfunc1.c: Box intersection, union, containment; Boxa union, extent, permutation
boxfunc2.c: Boxa/Box transforms; Boxa/Boxaa sorting; Boxaa utilities
boxfunc3.c: Mask <==> Boxa; painting into and drawing Boxa; boxa covering of mask components
boxfunc4.c: Boxa selection, permutation, Pta <==> Boxa; sequence fitting and smoothing

Colormap utilities and related operations

blend.c: Blend (optionally with a mask), multiplying by color, rendering with alpha
colormap.c: Implements PixColormap; colormap conversions, serialization, transforms
paintcmap.c: Paint onto colormap images - regions, masks
coloring.c: coloring gray, snapping to target color, linearly mapping colors, fractional shift towards black or white

Float-valued images

fpix1.c: Implements FPix and DPix classes (float and double images)
fpix2.c: FPix operations: interconversion FPix <==> Pix; min/max; borders; rasterop; integer scaling (interpolation); arithmetic

Image scaling

binexpand.c: Integer upscaling of 1 bpp images by replicated expansion
binreduce.c: Power of 2 integer reduction of 1 bpp images by sampling and rank value
scale.c: Image up- and down-scaling, by linear interpolation, area mapping, and sampling; scaling from binary to gray; mipmap scaling; upscaling with thresholding; downscaling with min, max and rank value
-- scalelow.c: Low-level implementation of scaling functions

Other geometric image transforms

affine.c: 3-pt affine transforms on images and coordinates, with sampling and interpolation; gauss-jordan solver
affinecompose.c: Composable affine coordinate transforms
bilinear.c: 4-pt bilinear transforms on images and coordinates, with sampling and interpolation
projective.c: 4-pt projective transforms on images and coordinates, with sampling and interpolation
rotate.c: Top-level image rotation by interpolation and sampling
rotateam.c: Interpolated image rotation
-- rotateamlow.c: Low-level helpers for interpolated rotation
rotateorth.c: Orthogonal image rotation and flips
rotateshear.c: Image rotation by shear
shear.c: Image shear about arbitrary lines and special points

Basic image operations: rasterop, arithmetic, convolution and correlation

correlscore.c: Correlation between pairs of binary images
convolve.c: Grayscale, color, float, double convolution; windowed mean, block sum and rank filters; census transform
kernel.c: Basic operations on image kernels for convolution; special kernels
pixacc.c: Simple interface for grayscale image arithmetic
pixarith.c: Grayscale image arithmetic
rank.c: Rank order filters (generalization of min/median/max filters)
rop.c: General rasterops. "pixRasterop() is your friend; it is worth memorizing!"
-- ropiplow.c: Low-level implementation of in-place rasterops
-- roplow.c: Low-level general rasterop implementation

Image operations with filling: seedfill and watershed

seedfill.c: Binary and gray seedfill; distance functions; voronoi-like seed spreading; local extrema
-- seedfilllow.c: Low-level implementation of binary and gray seedfill
watershed.c: Find watershed basins from specified seeds in grayscale image

Image quantization and depth conversion in general

adaptmap.c: local adaptive grayscale quantization; mostly gray-to-gray in preparation
binarize.c: Special binarization methods, locally adaptive: Otsu and Sauvola
colorcontent.c: Measure and map the color content (divergence from gray) of an image
colorquant1.c: Octcube color quantization
colorquant2.c: Modified median cut color quantization (Heckbert)
colorseg.c: Unsupervised color segmentation; selection and display of color content in HSV
grayquant.c: Standard, simple, general grayscale quantization
-- grayquantlow.c: Low-level implementation for some grayscale quantiziation functions
pixconv.c: Convert between images of different types without scaling

Image morphology

colormorph.c: Color morphological operations (apply grayscale separately to each component)
fhmtauto.c: Code generator, writes dwa code for user-supplied hit-miss transform Sels
fmorphauto.c: Code generator, writes dwa code for erosion, dilation, opening and closing, for user-supplied Sels
graymorph.c: Fast implementation of grayscale morphological operations
morph.c: Binary morphological operations (dilate, erode, hit-miss, open, close)
morphapp.c: Composite morph ops: component-wise, union/isect, tophat, gradient, granulometry
morphdwa.c: Binary morphological (dwa) operations
morphseq.c: Interpreter for morphological operations, including binary expansion and reduction
sel1.c: Implements Sel (morph structuring element) and Sela (array of sel)
sel2.c: Contains definitions of simple structuring elements
selgen.c: Generate hit-miss Sels for doing a loose match to a small bitmap

Auto-gen'd Destination Word Accumulation (DWA) morphology code

fhmtgen.1.c: DWA morphology with auto-generated hit-miss sels (high-level)
fhmtgenlow.1.c: Low-level Sel implementation for fhmtgen.1.c
fmorphgen.1.c: DWA morphology with auto-generated brick sels (high-level)
fmorphgenlow.1.c: Low-level Sel implementation for fmorphgen.1.c
dwacomb.2.c: DWA morphology with auto-generated comb Sels for composite operations on brick Sels
dwacomblow.2.c: Low-level Sel implementation for dwacomb.2.c

Specialized image filters

bilateral.c: Nonlinear filter with kernel as product of spatial (gaussian) and intensity differences, to preserve edges
edge.c: Sobel and related edge filters
enhance.c: Image enhancements: gamma TRC mapping; contrast enhancement, histogram eq; unsharp-masking; hue and saturation modifications (in HSV color space); multiplicative transforms

Connected components in binary images

conncomp.c: Connected component counting and extraction (Heckbert's seedfill algorithm)
ccbord.c: Border representation of connected components: display and svg serialization
ccthin.c: Connected-component-preserving thinning

Formatted I/O

readfile.c: Pix from memory and disk; detecting format
writefile.c: Pix to memory and disk; selecting format
bmpio.c: Read/write bmp format, from/to file and memory
gifio.c: Read/write gif format from/to file and memory
jp2kheader.c: Reads header and resolution for jp2k encoded images
jp2kio.c: Reading for jp2k encoded images
jp2kheader.c: Header reading for jp2k encoded images
jpegio.c: Read/write jpeg format from/to file and memory
pdfio1.c: High-level pdf image wrappers from/to file and memory
pdfio2.c: Lower-level pdf image wrappers from/to file and memory
pngio.c: Read/write png format from/to file and memory
pnmio.c: Read/write pnm format from/to file and memory
psio1.c: High level PostScript device driver for wrapping sets of images in PostScript
psio2.c: Lower-level PostScript device driver for wrapping images
spixio.c: Fast serialization and deserialization to/from file tiffio.c: Read/write tiff format from/to file and memory
webpio.c: Read/write webp format from/to file and memory

Line graphics and special output

gplot.c: Basic gnuplot-based plotting; serialization of plots
graphics.c: Rendering shapes from lines (using Pta representation)

Specialized document image processing

bardecode.c: Decode barcodes after sequence of widths is found
baseline.c: Find text baselines; determine and remove local skew
bmf.c: Generation of bitmap fonts
bootnumgen1.c: Generation of digit character templates for recog
bootnumgen2.c: Generation of digit character templates for recog
bootnumgen3.c: Generation of digit character templates for recog
classapp.c: Unsupervised classification of connected components and words; image comparison using word bounding boxes
dewarp1.c: Dewarp camera-based image using textlines: basic ops and serialization
dewarp2.c: Dewarp: build the page disparity model
dewarp3.c: Dewarp: applying (and stripping) the page disparity model
dewarp4.c: Dewarp: dewarp a single page; operations on dewarpa
finditalic.c: Identifies italic words
flipdetect.c: Page orientation detection (on roman text)
fliphmtgen.c: Hit-miss transforms for flipdetect.c
jbclass.c: data extraction from a set of pages for jbig2 compression: classification and location of connected components (characters or words)
partition.c: Bruel algorithm for extracting large whitespace boxes from a binary image
pageseg.c: Top-level page segmentation, halftone region extraction, textline extraction; white or black rectangles
pixlabel.c: Pixel labelling operations on connected components and with spatially-dependent color coding
readbarcode.c: "Early beta" code for locating and identifying line widths in 1d barcodes
recogbasic.c: Book adaptive recognizer (BAR): basic ops and serialization
recogtrain.c: BAR: training of recognizer
recogident.c: BAR: use of recognizer for classification
recogdid.c: BAR: document image decoding method for separating and identifying touching characters
skew.c: Find and remove text page skew
strokes.c: measure stroke width; regularize strokes to have a given width
textops.c: Simple utility to put text on images
warper.c: Simple captcha generator based on random warping; stereoscopic warping; stereo from image pairs

Fundamental data structures for computation

bytearray.c: Implements operations on an array of bytes (L_Bytea)
dnabasic.c: Basic operations for array of doubles, plus hashset and hashmap (L_Dna, L_Dnaa, L_dnaHash)
heap.c: Implements heap of generic pointers to structs that are keyed by a float, used for priority queue
list.c: Implements doubly-linked list of generic pointers
map.c: Implements sets and sorted maps, using red-black trees
numabasic.c: Basic operations for float/int arrays (Numa, Numaa)
numafunc1.c: Arithmetic, data extraction, interpolation, sorting on numas
numafunc2.c: Shift, scale, convolve, histograms, rank statistics, splitting distributions, extrema finding, threshold crossing, frequency analysis
ptra.c: Implements 1d and 2d arrays of generic pointers (Ptra, Ptraa)
pts.c: Implements 1d and 2d arrays of points (Pta, Ptaa)
queue.c: Implements queue of generic pointers
rbtree.c: Implements a red-black tree of 64 bit quantities or ptrs
sarray1.c: Impements an array of C strings, and useful utilities, including serialization
sarray2.c: Impements sorting, set and hash map operations on strings
stack.c: Implements a stack of generic pointers

Miscellaneous utilities

bbuffer.c: Implements ByteBuffer, a byte queue; used for zlib comp/decomp in memory
encoding.c: Implementation of base64 and ascii85 encoding
libversions.c: Generates string of lib version numbers available for use
parseprotos.c: Parse output of cpp to generate ANSII C function prototypes from a file of C functions
stringcode.c: Utility for storing and extracting serializable leptonica objects (such as pixa, recog, ...)
utils1.c: Severity (error, warning,info) functions; byte swapping, 64-bit hashes, primes, gray code, timing ops
utils2.c: Safe string ops; file <==> memory ops; cross-platform ops, file name ops
zlibmem.c: Compresses and decompresses a byte array from one memory buffer to another

Maze: an example of breadth-first (BF) search

maze.c: A game with a pedagogical slant: generate and search binary and grayscale mazes
sudoku.c: Solves sudoku puzzels and generates new ones

Include files: struct and enum definitions

allheaders.h: ANSII C headers for all functions in the library, automatically generated by xtractprotos
alltypes.h: Included within allheaders.h, it includes all the leptonica header files
array.h: Structs for basic number and string arrays (Numa, Numaa, L_Dna, L_Dnaa, Sarray, L_Bytea)
arrayaccess.h: Macros for fast data access into arrays
bbuffer.h: Struct for expandable byte buffer (ByteBuffer)
bilateral.h: Struct for bilateral filtering (L_Bilateral)
bmf.h: Struct for bitmap fonts (L_Bmf)
bmfdata.h: Data for bitmap fonts, including compilable bitmaps
bmp.h: Structs for bmp file format (uncompressed) (BMP_FileHeader, BMP_InfoHeader)
ccbord.h: Structs for representation of 1 bpp component outlines (CCBord, CCBorda)
dewarp.h: Struct for rectifying camera-based image using textlines (L_Dewarp, L_Dewarpa)
gplot.h: Struct and parameters for generating gnuplot files (GPlot)
heap.h: Struct for representing generic expandable priority queue (L_Heap)
imageio.h: Enums for supported image file formats
jbclass.h: Structs for unsupervised classification of 1 bpp components from a set of pages; used for jbig2 compression (JbClasser, JbData)
list.h: Struct for generic double-linked list; macros for list traversal
morph.h: Structs for image morphology (Sel, Sela) and convolution (Kernel), with enum flags
pix.h: Basic file defining image and image-related structs (Pix, PixColormap, RGBA_Quad, Pixa, Pixaa, Box, Boxa, Boxaa, Pta, Ptaa, Pixacc, PixTiling, FPix, DPix, PixComp, PixaComp), along with enums for many operations
ptra.h: Structs for generic expandable arrays (L_Ptra, L_Ptraa)
queue.h: Struct for generic expandable queue (L_Queue)
rbtree.h: Struct for rbtree and associated typedefs
readbarcode.h: Enums and consts for reading 1d barcodes
recog.h: Structs for book-adaptive recognition (L_Recoga, L_Recog, L_Rcha, L_Rch, L_Rdid)
regutils.h: Struct for regression tests (L_RegParams)
stack.h: Struct for generic expandable stack (L_Stack)
stringcode.h: Struct for accumulating generated code for storing and extracting serializable leptonica objects
sudoku.h: Struct for sudoku generator and solver (L_Sudoku)
watershed.h: Struct for generating watershed information from a grayscale image (L_Wshed)

Compile configuration: selection of runtime and external libraries

environ.h: Multiplatform support; specifies external libraries to be used; messages output to stderr (error, warning, info); typedefs for basic types; endian type; output redirection from files to memory

Creative Commons License
Leptonica by Dan Bloomberg is licensed under a Creative Commons Attribution 3.0 United States License.