CtrlK
BlogDocsLog inGet started
Tessl Logo

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

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

Pending
Overview
Eval results
Files

collections.mddocs/

Image Collections

Container classes for organizing and manipulating groups of images, rectangles, and associated metadata with efficient array-based operations.

Capabilities

PIXA - Image Arrays

Manage collections of PIX images with optional associated bounding boxes for multi-image processing workflows.

/**
 * Array of PIX images with optional associated boxes
 */
class PIXA extends Pointer {
    int n(); // number of images in array
    int nalloc(); // allocated array size
}

/**
 * Create image array
 * @param n - Initial capacity
 * @return PIXA array or null on failure
 */
PIXA pixaCreate(int n);

/**
 * Add image to array
 * @param pixa - Target array
 * @param pix - Image to add
 * @param copyflag - L_INSERT, L_COPY, or L_CLONE
 * @return 0 on success, 1 on failure
 */
int pixaAddPix(PIXA pixa, PIX pix, int copyflag);

/**
 * Get image from array
 * @param pixa - Source array
 * @param index - Image index
 * @param accesstype - L_COPY or L_CLONE
 * @return PIX image or null on failure
 */
PIX pixaGetPix(PIXA pixa, int index, int accesstype);

/**
 * Get number of images
 * @param pixa - Source array
 * @return Number of images
 */
int pixaGetCount(PIXA pixa);

/**
 * Get associated bounding boxes
 * @param pixa - Source array
 * @param accesstype - L_COPY or L_CLONE
 * @return BOXA array of boxes or null
 */
BOXA pixaGetBoxa(PIXA pixa, int accesstype);

/**
 * Set bounding boxes for images
 * @param pixa - Target array
 * @param boxa - Array of bounding boxes
 * @param accesstype - L_INSERT, L_COPY, or L_CLONE
 * @return 0 on success, 1 on failure
 */
int pixaSetBoxa(PIXA pixa, BOXA boxa, int accesstype);

/**
 * Add image with associated box
 * @param pixa - Target array
 * @param pix - Image to add
 * @param box - Associated bounding box (can be null)
 * @param copyflag - L_INSERT, L_COPY, or L_CLONE
 * @return 0 on success, 1 on failure
 */
int pixaAddPixWithBox(PIXA pixa, PIX pix, BOX box, int copyflag);

/**
 * Sort images by various criteria
 * @param pixas - Source array
 * @param sorttype - L_SORT_BY_* constant
 * @param sortorder - L_SORT_INCREASING or L_SORT_DECREASING
 * @param pnaindex - Returns sort indices (can be null)
 * @return Sorted PIXA or null on failure
 */
PIXA pixaSort(PIXA pixas, int sorttype, int sortorder, NUMA naindex);

Usage Examples:

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

// Create image collection for processing results
PIXA results = pixaCreate(10);

// Add processed images
pixaAddPix(results, processedImage1, L_COPY);
pixaAddPix(results, processedImage2, L_COPY);
pixaAddPix(results, processedImage3, L_COPY);

// Add images with bounding boxes
BOX region1 = boxCreate(0, 0, 100, 100);
pixaAddPixWithBox(results, croppedImage, region1, L_COPY);

// Process each image in collection
int count = pixaGetCount(results);
for (int i = 0; i < count; i++) {
    PIX pix = pixaGetPix(results, i, L_CLONE);
    
    // Apply additional processing
    PIX enhanced = pixGaussianBlur(pix, 1.0f, 1.0f);
    
    // Replace in collection
    pixaReplacePix(results, i, enhanced, null);
}

// Sort by image area
PIXA sorted = pixaSort(results, L_SORT_BY_AREA, L_SORT_DECREASING, null);

PIXAA - 2D Image Arrays

Manage 2D arrays of image collections for hierarchical organization and batch processing.

/**
 * 2D array of PIXA image collections
 */
class PIXAA extends Pointer {
    int n(); // number of PIXA arrays
    int nalloc(); // allocated array size
}

/**
 * Create 2D image array
 * @param n - Initial capacity
 * @return PIXAA array or null on failure
 */
PIXAA pixaaCreate(int n);

/**
 * Add PIXA to 2D array
 * @param pixaa - Target 2D array
 * @param pixa - PIXA to add
 * @param copyflag - L_INSERT, L_COPY, or L_CLONE
 * @return 0 on success, 1 on failure
 */
int pixaaAddPixa(PIXAA pixaa, PIXA pixa, int copyflag);

/**
 * Get PIXA from 2D array
 * @param pixaa - Source 2D array
 * @param index - PIXA index
 * @param accesstype - L_COPY or L_CLONE
 * @return PIXA array or null on failure
 */
PIXA pixaaGetPixa(PIXAA pixaa, int index, int accesstype);

/**
 * Get specific image from 2D array
 * @param pixaa - Source 2D array
 * @param i - PIXA index
 * @param j - PIX index within PIXA
 * @param accesstype - L_COPY or L_CLONE
 * @return PIX image or null on failure
 */
PIX pixaaGetPix(PIXAA pixaa, int i, int j, int accesstype);

Usage Examples:

// Organize images by processing stage
PIXAA workflow = pixaaCreate(5);

// Stage 1: Original images
PIXA originals = pixaCreate(10);
pixaAddPix(originals, image1, L_COPY);
pixaAddPix(originals, image2, L_COPY);
pixaaAddPixa(workflow, originals, L_INSERT);

// Stage 2: Preprocessed images
PIXA preprocessed = pixaCreate(10);
// ... add preprocessed images ...
pixaaAddPixa(workflow, preprocessed, L_INSERT);

// Access specific image from workflow
PIX result = pixaaGetPix(workflow, 1, 0, L_CLONE); // Stage 1, Image 0

NUMA - Number Arrays

Manage arrays of numbers for statistical analysis, measurements, and numerical computations.

/**
 * Array of numbers for statistical operations
 */
class NUMA extends Pointer {
    int n(); // number of values
    int nalloc(); // allocated array size
    FloatPointer array(); // array data
}

/**
 * Create number array
 * @param n - Initial capacity
 * @return NUMA array or null on failure
 */
NUMA numaCreate(int n);

/**
 * Add number to array
 * @param na - Target array
 * @param val - Value to add
 * @return 0 on success, 1 on failure
 */
int numaAddNumber(NUMA na, float val);

/**
 * Get number from array
 * @param na - Source array
 * @param index - Value index
 * @param pval - Returns value
 * @return 0 on success, 1 on failure
 */
int numaGetFValue(NUMA na, int index, FloatPointer pval);

/**
 * Get array statistics
 * @param na - Source array
 * @param pmin - Returns minimum value (can be null)
 * @param pmax - Returns maximum value (can be null)
 * @param pmean - Returns mean value (can be null)
 * @param pvar - Returns variance (can be null)
 * @return 0 on success, 1 on failure
 */
int numaGetStatsValues(NUMA na, FloatPointer pmin, FloatPointer pmax, FloatPointer pmean, FloatPointer pvar);

/**
 * Sort number array
 * @param nas - Source array
 * @param sortorder - L_SORT_INCREASING or L_SORT_DECREASING
 * @param pnaindex - Returns sort indices (can be null)
 * @return Sorted NUMA or null on failure
 */
NUMA numaSort(NUMA nas, int sortorder, NUMA naindex);

Usage Examples:

// Collect measurement data
NUMA measurements = numaCreate(100);

// Add measurements from image analysis
numaAddNumber(measurements, 156.7f);
numaAddNumber(measurements, 142.3f);
numaAddNumber(measurements, 198.1f);

// Get statistics
FloatPointer min = new FloatPointer(1);
FloatPointer max = new FloatPointer(1);
FloatPointer mean = new FloatPointer(1);
FloatPointer variance = new FloatPointer(1);

numaGetStatsValues(measurements, min, max, mean, variance);
System.out.println("Measurements: min=" + min.get() + ", max=" + max.get() + 
                  ", mean=" + mean.get() + ", var=" + variance.get());

// Sort for analysis
NUMA sorted = numaSort(measurements, L_SORT_INCREASING, null);

SARRAY - String Arrays

Manage collections of strings for text processing, filenames, and metadata.

/**
 * Array of strings
 */
class SARRAY extends Pointer {
    int n(); // number of strings
    int nalloc(); // allocated array size
}

/**
 * Create string array
 * @param n - Initial capacity
 * @return SARRAY array or null on failure
 */
SARRAY sarrayCreate(int n);

/**
 * Add string to array
 * @param sa - Target array
 * @param string - String to add
 * @param copyflag - L_INSERT or L_COPY
 * @return 0 on success, 1 on failure
 */
int sarrayAddString(SARRAY sa, String string, int copyflag);

/**
 * Get string from array
 * @param sa - Source array
 * @param index - String index
 * @param copyflag - L_COPY or L_NOCOPY
 * @return String or null on failure
 */
String sarrayGetString(SARRAY sa, int index, int copyflag);

/**
 * Get number of strings
 * @param sa - Source array
 * @return Number of strings
 */
int sarrayGetCount(SARRAY sa);

/**
 * Sort string array
 * @param sas - Source array
 * @param sortorder - L_SORT_INCREASING or L_SORT_DECREASING
 * @return Sorted SARRAY or null on failure
 */
SARRAY sarraySort(SARRAY sas, int sortorder);

Usage Examples:

// Collect image filenames
SARRAY filenames = sarrayCreate(50);

sarrayAddString(filenames, "image001.jpg", L_COPY);
sarrayAddString(filenames, "image002.jpg", L_COPY);
sarrayAddString(filenames, "processed_001.png", L_COPY);

// Process each file
int count = sarrayGetCount(filenames);
for (int i = 0; i < count; i++) {
    String filename = sarrayGetString(filenames, i, L_NOCOPY);
    PIX pix = pixRead(filename);
    // Process image...
}

// Sort alphabetically
SARRAY sorted = sarraySort(filenames, L_SORT_INCREASING);

Collection Operations

Batch Processing

/**
 * Apply function to all images in PIXA
 * @param pixas - Source image array
 * @param func - Processing function
 * @param param - Function parameter
 * @return Processed PIXA or null on failure
 */
PIXA pixaApplyFunction(PIXA pixas, PIXFunction func, Pointer param);

/**
 * Join multiple PIXA arrays
 * @param pixa1 - First array
 * @param pixa2 - Second array
 * @return Combined PIXA or null on failure
 */
PIXA pixaJoin(PIXA pixa1, PIXA pixa2);

/**
 * Select subset of images
 * @param pixas - Source array
 * @param start - Start index
 * @param end - End index
 * @return Subset PIXA or null on failure
 */
PIXA pixaSelectRange(PIXA pixas, int start, int end);

Usage Examples:

// Apply gaussian blur to all images
PIXA blurred = pixaApplyFunction(originalImages, pixGaussianBlur, new FloatPointer(2.0f));

// Combine processing results
PIXA combined = pixaJoin(results1, results2);

// Select images for further processing
PIXA subset = pixaSelectRange(allImages, 10, 20);

Memory Management

All collection classes use reference counting and automatic cleanup:

// Collections automatically manage contained objects
PIXA images = pixaCreate(10);
pixaAddPix(images, pix, L_COPY); // Image is copied and managed

// Access creates new references
PIX retrieved = pixaGetPix(images, 0, L_CLONE); // Increases reference count

// Memory freed when all references released
// No manual cleanup required with JavaCPP

Install with Tessl CLI

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

docs

collections.md

connected-components.md

core-images.md

geometry.md

image-io.md

image-processing.md

index.md

morphology.md

text-recognition.md

utilities.md

tile.json