1. Products
  2.   Image
  3.   C++
  4.   Leptonica  

Leptonica  

 
 

C API for Advanced Image Processing

Open Source C library enables developers to perform advanced image processing operations like image scaling, translation, rotation, shear inside their own apps.

Leptonica is an open source C image processing and image analysis library that is very useful for working with document images as well as natural images. The library is very stable and has included support for numerous image formats such as JPEG, PNG, TIFF, WebP, JP2, BMP, PNM, PS, GIF, and PDF.  You can easily perform reading and writing operations on the provided list of image formats. The library mostly used object-oriented approach and a set of design principles that make the code safe, portable, and transparent.

The library provides support for several important operations and a set of tools for image processing as well as image analysis. The library support operations like image scaling, translation, rotation, shear, Image transformations with changes in pixel depth, binary and gray-scale morphology, Pixelwise masking, blending, enhancement, arithmetic ops, and many more. It also supports several important utilities like for handling arrays of image-related data types such as pixa, boxa, pta and other.

It has also provided functions for reading and writing files having several images and writing files with special TIFF tags embedded in the header. It also allows developers to write PostScript files in a variety of formats such as transformation to PDF, raster images, and converting a PostScript file to a set of compressed images.

Previous Next

Getting Started with Leptonica

The easiest way to install Leptonica is by using via GitHub. Please use the following command for a smooth installation

Install Leptonica via GitHub.

git clone --depth=1 https://github.com/mrdoob/three.js.git 

Reading and writing images

The open source library Leptonica gives software developers the capability to read and write images inside their own applications. It has provided several important methods for reading and writing images such as low-level and high-level functions for reading and writing image data, functions for reading and writing files with multiple images, files with TIFF tags embedded in the header, reading JPEG files, reading and writing PostScript files and several other functions. There are some specific encoders also supported by the library.

Read Images via Leptonica Library

// Open input image with leptonica library
Pix *image = pixRead("/usr/src/tesseract-3.02/phototest.tif");
api->SetImage(image);
// Get OCR result
char *outText;
outText = api->GetUTF8Text();

Image Scaling via C Library

The open source library Leptonica has provided complete support for scaling images inside their own C application with ease.  There are numerous scaling functions provided by Leptonica, such as upscaling using linear interpolation, downscaling by using subsampling, or by area mapping, sampling, 2x, and 4x linear interpolation upscaling, integer subsampling of RGB to gray or binary, and many more. Apart from that very fast scaling on binary images is also offered, and is useful for image analysis of the scanned binary text.

Better Image Rotation via C Library

The open source library Leptonica has provided support for rotating images inside their own C applications. There are numerous ways for achieving the image rotation operation, such as rotation by shear, rotation by area mapping, special rotations by 90, 180 or 270 degrees, rotation by either 2 or 3 shear, and many more.

180 Degree Image Rotation via C Library

extra = w & 31;
if (extra)
    shift = 32 - extra;
else
    shift = 0;
if (shift)
    rasteropHipLow(datas, w, h, d, wpls, 0, h, shift);

databpl = (w + 7) / 8;
bpl = 4 * wpls;
for (i = 0; i < h; i++) {
    lines = datas + (h - 1 - i) * wpls;
    lined = datad + i * wpld;
    for (j = 0; j < databpl; j++) {
        if (val = GET_DATA_BYTE(lines, bpl - 1 - j))
            SET_DATA_BYTE(lined, j, tab[val]);
    }
}

if (shift)
    rasteropHipLow(datas, w, h, d, wpls, 0, h, -shift);
 English