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.

What is Leptonica?

Leptonica is a robust, open source C image processing and image analysis library renowned for its stability and versatility with both document images and natural images. Built with an object-oriented approach, it adheres to design principles that ensure the code is safe, portable, and transparent. The library seamlessly handles reading and writing operations across a wide array of image formats, including JPEG, PNG, TIFF, WebP, GIF, PDF, and BMP. Its comprehensive toolkit is indispensable for developers needing reliable foundational operations.

This powerful library excels in delivering a broad spectrum of important operations for both image processing and deeper image analysis. Core functionalities include essential tasks like image scaling, translation, rotation, and shear, along with advanced pixel depth changes, binary and gray-scale morphology, and pixelwise masking. It also supports image transformations, blending, enhancement, and arithmetic ops. Furthermore, Leptonica provides vital utilities for managing specialized data structures such as pixa, boxa, and pta, and offers extended file support for multi-image files, special TIFF tags, and generating PostScript files that can be transformed into PDF or 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.

How to 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.

How to Perform 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