You are looking at historical revision 20675 of this page. It may differ significantly from its current revision.

Leptonica

In progress.

An interface to the leptonica library of routines for image analysis and processing.

Memory Management

Most of the library's operations are based around manipulating images, which are stored in a structure known as a pix. You should manually manage the references to the images. If you want a copy of an existing pix, use pix-clone; this updates the reference count for an image. Use pix-destroy when you are finished with a reference to a pix; this decrements the reference count, and finally deletes the image when the count is 0.

Implemented Procedures

Creating and managing images

[procedure] (pix-clone pix)

Return a reference to given pix.

[procedure] (pix-copy pix-d pix-s)

Makes a copy of pix-s: if pix-d is #f then returns a pointer to a copy of pix-s, else makes pix-d a copy of pix-s.

[procedure] (pix-create width height depth)

Returns a pointer to a new pix, an image of given width and height in pixels, and colour depth.

[procedure] (pix-destroy pix)

Reduces reference count to pix, and destroys picture if count is 0.

[procedure] (pix-read filename)

Returns a pointer to a new pix created by reading image from filename. Returns #f if there is an error.

[procedure] (pix-write filename pix image-type)

Writes pix to an image file called filename. The image-type is taken from the list of constants, below.

Image attributes

[procedure] (pix-get-width pix)

Returns the width in pixels of given pix.

[procedure] (pix-set-width pix integer)

Sets the width in pixels of given pix. Returns 0 if ok, or 1 if error.

[procedure] (pix-get-height pix)

Returns the height in pixels of given pix.

[procedure] (pix-set-height pix integer)

Sets the height in pixels of given pix. Returns 0 if ok, or 1 if error.

[procedure] (pix-get-depth pix)

Returns the colour depth of given pix.

[procedure] (pix-set-depth pix integer)

Sets colour depth of given pix. Returns 0 if ok, or 1 if error.

[procedure] (pix-set-dimensions pix width height depth)

Sets all three properties of given pix. Returns 0 if ok, or 1 if error.

[procedure] (pix-get-x-res pix)

Returns the x resolution of given pix.

[procedure] (pix-set-x-res pix integer)

Sets the x resolution of given pix. Returns 0 if ok, or 1 if error.

[procedure] (pix-get-y-res pix)

Returns the y resolution of given pix.

[procedure] (pix-set-y-res pix integer)

Sets the y resolution of given pix. Returns 0 if ok, or 1 if error.

[procedure] (pix-set-resolution pix x-res y-res)

Sets the x and y resolution of given pix. Returns 0 if ok, or 1 if error.

[procedure] (pix-scale-resolution pix x-scale y-scale)

Rescales the image in the x and y directions. Returns 0 if ok, or 1 if error.

[procedure] (pix-get-input-format pix)

Returns the input format of pix.

[procedure] (pix-set-input-format pix integer)

Sets the input format of pix.

Manipulating images

[procedure] (pix-add-gray pix-d pix-1 pix-2)

Returns pointer to image which is pixel sum of pix-1 and pix-2. Unless #f, pix-d may specify the destination image, and pix-d may be equal to pix-1 for an in-place change.

[procedure] (pix-close-gray pix h-size v-size)

h-size and v-size must be odd values: they denote the size of gray block to find. Returns a pointer to a new pix, based on the given pix, removing parts that do not fit a h-size x v-size block.

[procedure] (pix-combine-masked pix-d pix-s pix-m)

Modifies pix-d in place. Each pixel in pix-d corresponding to a set pixel in the mask pix-m is set to that pixel's value from pix-s. pix-d and pix-s must be equivalent in pixel depth. The three images are aligned to the top-left corner, stopping when outside the intersection of three images. Returns 0 if OK or 1 if error.

[procedure] (pix-dilate-gray pix h-size v-size)

h-size and v-size must be odd values. Returns a pointer to a new pix, based on the given pix.

[procedure] (pix-erode-gray pix h-size v-size)

h-size and v-size must be odd values. Returns a pointer to a new pix, based on the given pix.

[procedure] (pix-find-skew pix)

Returns two values: the angle (in radians) and confidence level of skew in the given pix.

[procedure] (pix-invert pix-d pix-s)

Inverts the image pix-s. If pix-d is #f, then a pointer to a new pix is returned; otherwise, pix-d holds the inverted image.

[procedure] (pix-open-gray pix h-size v-size)

h-size and v-size must be odd values. Returns a pointer to a new pix, based on the given pix

[procedure] (pix-rotate-am-gray pix angle filler)

Returns a pointer to a new 8bpp pix created by rotating the given 8 bpp pix through the given angle; filler specifies the gray value to be brought in to fill blanks, 0 for black, 255 for white.

[procedure] (pix-threshold-to-binary pix threshold

Returns a pointer to a new pix created from the given pix. The given pix should be a 4 or 8 bpp colour image; the given threshold value is used to convert the image to binary.

[procedure] (pix-threshold-to-value pix-d pix-s threshold set-value)

If pix-d is #f, returns a pointer to a new pix. Else, pix-d must be equal to pix-s and thresholding is done in place. If set-value > threshold, then all pixels with a value >= threshold are set to set-value; else, if set-value < threshold, then all pixels with value <= threshold are set to set-value.

[procedure] (rotate pix angle rotation-type in-colour width height)

Returns a pointer to a new pix created by rotating given pix.

[procedure] (scale pix scale-x scale-y)

Returns a pointer to a new pix created by rescaling given pix along x and y dimensions.

Constants

image-type
IFF-UNKNOWN, IFF-BMP, IFF-JFIF-JPEG, IFF-PNG, IFF-TIFF, IFF-TIFF-PACKBITS, IFF-TIFF-RLE, IFF-TIFF-G3, IFF-TIFF-G4, IFF-TIFF-LZW, IFF-TIFF-ZIP, IFF-PNM, IFF-PS, IFF-GIF, IFF-JP2, IFF-DEFAULT, IFF-SPIX.
in-colour
L-BRING-IN-WHITE, L-BRING-IN-BLACK.
rotation-type
L-ROTATE-AREA-MAP, L-ROTATE-SHEAR, L-ROTATE-SAMPLING.

Examples

See the examples folder in the repository.

Author

Peter Lane

License

GPL version 3.0.

Requirements

You will need libraries for handling images: libjpeg, libpng, libtiff are currently assumed in the setup file.

Also, you must download and compile the source code for the leptonica library.

Note: this egg has only been tested under Linux.

Version History