or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

collections.mdconnected-components.mdcore-images.mdgeometry.mdimage-io.mdimage-processing.mdindex.mdmorphology.mdtext-recognition.mdutilities.md
tile.json

tessl/maven-org-bytedeco--leptonica-platform

JavaCPP bindings for Leptonica image processing library with cross-platform support

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
mavenpkg:maven/org.bytedeco/leptonica-platform@1.85.x

To install, run

npx @tessl/cli install tessl/maven-org-bytedeco--leptonica-platform@1.85.0

index.mddocs/

JavaCPP Leptonica

JavaCPP Leptonica provides comprehensive Java bindings for the Leptonica image processing library, enabling industrial-strength image processing capabilities in Java applications. The library supports morphological operations, image enhancement, analysis, format conversion, OCR support, and document processing across multiple platforms with automatic memory management.

Package Information

  • Package Name: leptonica-platform
  • Package Type: maven
  • Language: Java
  • Installation:
    <dependency>
      <groupId>org.bytedeco</groupId>
      <artifactId>leptonica-platform</artifactId>
      <version>1.85.0-1.5.12</version>
    </dependency>

Core Imports

import org.bytedeco.javacpp.Loader;
import org.bytedeco.leptonica.*;
import static org.bytedeco.leptonica.global.leptonica.*;

For comprehensive development:

// Core image structures
import org.bytedeco.leptonica.PIX;
import org.bytedeco.leptonica.PIXA;
import org.bytedeco.leptonica.PIXAA;
import org.bytedeco.leptonica.FPIX;
import org.bytedeco.leptonica.DPIX;

// Geometric structures
import org.bytedeco.leptonica.BOX;
import org.bytedeco.leptonica.BOXA;
import org.bytedeco.leptonica.PTA;
import org.bytedeco.leptonica.PTAA;

// Morphological and recognition
import org.bytedeco.leptonica.SEL;
import org.bytedeco.leptonica.SELA;
import org.bytedeco.leptonica.L_RECOG;
import org.bytedeco.leptonica.L_DEWARP;
import org.bytedeco.leptonica.L_DEWARPA;

// Connected components and contours
import org.bytedeco.leptonica.CCBORD;
import org.bytedeco.leptonica.CCBORDA;

// Utility structures
import org.bytedeco.leptonica.NUMA;
import org.bytedeco.leptonica.SARRAY;
import org.bytedeco.leptonica.L_STACK;
import org.bytedeco.leptonica.PIXCMAP;

// All static functions
import static org.bytedeco.leptonica.global.leptonica.*;

For minimal imports:

import org.bytedeco.leptonica.PIX;
import org.bytedeco.leptonica.BOX;
import static org.bytedeco.leptonica.global.leptonica.pixRead;
import static org.bytedeco.leptonica.global.leptonica.pixWrite;

Basic Usage

import org.bytedeco.leptonica.*;
import static org.bytedeco.leptonica.global.leptonica.*;

// Initialize the library
Loader.load(org.bytedeco.leptonica.global.leptonica.class);

// Read an image
PIX pixSource = pixRead("input.png");

// Create a processed copy using morphological operations  
SEL sel = selCreateBrick(5, 5, 2, 2);
PIX pixProcessed = pixDilate(null, pixSource, sel);

// Get image dimensions
int width = pixGetWidth(pixSource);
int height = pixGetHeight(pixSource);
int depth = pixGetDepth(pixSource);

// Write result
pixWrite("output.png", pixProcessed, IFF_PNG);

// Memory is automatically managed - no manual cleanup needed

Architecture

JavaCPP Leptonica is built around several key components:

  • Core Image Types: PIX, FPIX, DPIX classes with automatic memory management via Abstract base classes
  • Collections: Comprehensive array types (PIXA, PIXAA, BOXA, PTA, etc.) for organizing related data
  • Global Functions: 2000+ native functions accessible through static imports covering all image processing operations
  • Geometric Structures: BOX, PTA classes for defining regions and coordinate sets
  • Specialized Processing: Dedicated classes for morphology, recognition, document processing, and more
  • Cross-Platform Support: Native binaries for Linux, macOS, Windows, and Android with automatic platform detection

Capabilities

Core Image Structures

Primary image containers and their management, supporting multiple bit depths and color models with automatic memory cleanup.

class PIX extends AbstractPIX {
    static PIX create(int width, int height, int depth);
    static PIX createTemplate(PIX pixs);
    PIX clone();
    
    // Dimensions and properties
    int w(); // width in pixels
    int h(); // height in pixels  
    int d(); // depth in bits per pixel
    int spp(); // samples per pixel
    
    // Data access
    IntPointer data();
    PIXCMAP colormap();
    BytePointer text();
}

class FPIX extends AbstractFPIX {
    // 32-bit float image operations
}

class DPIX extends AbstractDPIX {
    // 64-bit double image operations
}

Core Image Structures

Image I/O and Format Handling

Complete image reading, writing, and format conversion capabilities supporting all major image formats.

// Reading images
PIX pixRead(String filename);
PIX pixReadStream(InputStream fp, int hint);
PIX pixReadMem(BytePointer data, long size);

// Writing images  
int pixWrite(String filename, PIX pix, int format);
int pixWriteStream(OutputStream fp, PIX pix, int format);
BytePointer pixWriteMem(PIX pix, long[] psize, int format);

// Format constants
static final int IFF_PNG = 1;
static final int IFF_JPEG = 2; 
static final int IFF_TIFF = 3;

Image I/O Operations

Image Processing and Transformations

Core image processing operations including scaling, rotation, morphological operations, and filtering.

// Scaling and geometric transforms
PIX pixScale(PIX pixs, float scalex, float scaley);
PIX pixRotate(PIX pixs, float angle, int type, int incolor, int width, int height);
PIX pixAffine(PIX pixs, FloatPointer vc, int incolor);

// Morphological operations
PIX pixDilate(PIX pixd, PIX pixs, SEL sel);
PIX pixErode(PIX pixd, PIX pixs, SEL sel);
PIX pixOpen(PIX pixd, PIX pixs, SEL sel);
PIX pixClose(PIX pixd, PIX pixs, SEL sel);

// Color space conversion
PIX pixConvertRGBToGray(PIX pixs, float rwt, float gwt, float bwt);
PIX pixConvertGrayToColormap(PIX pixs);

// Image blending and compositing
PIX pixBlend(PIX pixs1, PIX pixs2, int x, int y, float fract);
PIX pixBlendColor(PIX pixd, PIX pixs1, PIX pixs2, int x, int y, float fract, int transparent, int transpix);

// Convolution and filtering  
PIX pixConvolve(PIX pixs, L_KERNEL kel, int outdepth, int normflag);
PIX pixSobelEdgeFilter(PIX pixs, int orientflag);
PIX pixUnsharpMasking(PIX pixs, int halfwidth, float fract);

// Convolution kernel type
class L_KERNEL extends Pointer {
    int sy();           // kernel height
    int sx();           // kernel width
    int cy();           // y origin coordinate  
    int cx();           // x origin coordinate
}

Image Processing

Geometric Structures and Analysis

Rectangle and point operations for defining regions, measuring features, and spatial analysis.

class BOX extends Pointer {
    int x(); // left coordinate
    int y(); // top coordinate  
    int w(); // width
    int h(); // height
}

class BOXA extends Pointer {
    // Array of BOX rectangles
}

class PTA extends Pointer {
    // Array of 2D points
}

// Box operations
BOX boxCreate(int x, int y, int w, int h);
int boxGetGeometry(BOX box, IntPointer px, IntPointer py, IntPointer pw, IntPointer ph);
BOX boxIntersection(BOX box1, BOX box2);

Geometric Operations

Morphological Operations and Structuring Elements

Advanced morphological processing with custom structuring elements for shape analysis and feature extraction.

class SEL extends Pointer {
    // Structuring element for morphological operations
}

// Structuring element creation
SEL selCreateBrick(int h, int w, int cy, int cx);
SEL selCreateFromString(String text, int h, int w, String name);

// Advanced morphological operations
PIX pixMorphGradient(PIX pixs, SEL sel, int op);
PIX pixTophat(PIX pixs, SEL sel, int op);
PIX pixHMT(PIX pixd, PIX pixs, SEL sel);

Morphological Operations

Text Recognition and Document Processing

OCR capabilities, document analysis, and text extraction with specialized structures for character recognition.

class L_RECOG extends Pointer {
    // Character recognition engine
}

class L_DEWARP extends Pointer {
    // Document dewarp correction
}

class L_DEWARPA extends Pointer {  
    // Multi-page dewarp processing
}

// Recognition functions
L_RECOG recogCreateFromRecog(L_RECOG recs, int scalew, int scaleh, int linew, int threshold, int maxyshift);
int recogTrainLabeled(L_RECOG recog, PIX pixs, BOX box, String text, int debug);

Text Recognition

Image Collections and Data Structures

Container classes for organizing and manipulating groups of images and associated metadata.

class PIXA extends Pointer {
    // Array of PIX images with optional boxes
    int n(); // number of images
}

class PIXAA extends Pointer {
    // 2D array of PIXA structures  
}

// Collection operations
PIXA pixaCreate(int n);
int pixaAddPix(PIXA pixa, PIX pix, int copyflag);
PIX pixaGetPix(PIXA pixa, int index, int accesstype);
BOXA pixaGetBoxa(PIXA pixa, int accesstype);

Image Collections

Connected Components and Contour Analysis

Comprehensive connected component analysis, contour processing, and border representations for object detection and shape analysis.

class CCBORD extends Pointer {
    PIX pix();           // minimally-clipped bitmap of component
    BOXA boxa();         // boxes for primary component and holes
    PTA start();         // initial border pixel locations
    PTAA local();        // chain code for border (relative coords)
    PTAA global();       // global pixel locations of border
}

class CCBORDA extends Pointer {
    int n();             // number of ccbords
    CCBORD getCcbord(int index);
}

// Connected component functions
CCBORD ccbordCreate(PIX pixs, int connectivity);
PIX pixConnComp(PIX pixs, PIXA ppixa, int connectivity);
int pixCountConnComp(PIX pixs, int connectivity, IntPointer pcount);
PTA ptaGetBoundaryPixels(PIX pixs, int type);

Connected Components

Utilities and Data Structures

Supporting data structures including arrays, stacks, queues, and utility functions for comprehensive image processing workflows.

class NUMA extends Pointer {
    // Numeric array for statistics
}

class SARRAY extends Pointer {
    // String array
}

class L_STACK extends Pointer {
    // Stack data structure
}

// Utility functions
int pixCountPixels(PIX pix, IntPointer pcount, IntPointer tab8);
float pixGetAverageMasked(PIX pixs, PIX pixm, int x, int y, int w, int h, int factor, float[] pval);

Utility Structures

Error Handling

Most functions return status codes where 0 indicates success and non-zero indicates failure. For PIX creation functions, null return values indicate failure.

PIX pix = pixRead("image.jpg");
if (pix == null) {
    System.err.println("Failed to read image");
    return;
}

int result = pixWrite("output.png", pix, IFF_PNG);
if (result != 0) {
    System.err.println("Failed to write image");
}

Memory Management

JavaCPP provides automatic memory management through:

  • Abstract base classes with automatic cleanup registration
  • Factory methods that handle deallocator registration
  • Manual cleanup available via destroy() methods
  • Reference counting for shared objects

The library handles native memory automatically, eliminating the need for manual memory management in most cases.