Leptonica is an open source library containing software that is broadly useful for image processing and image analysis applications. The official github repository for Leptonica is: danbloomberg/leptonica. See leptonica.org for more documentation and recent releases.

Overview

Leptonica Library

Build Status Build status Build status
Coverity Scan Build Status Code Quality: Cpp Total Alerts

www.leptonica.org

The library supports many operations that are useful on

  • Document images
  • Natural images

Fundamental image processing and image analysis operations

  • Rasterop (aka bitblt)
  • Affine transforms (scaling, translation, rotation, shear) on images of arbitrary pixel depth
  • Projective and bilinear transforms
  • Binary and grayscale morphology, rank order filters, and convolution
  • Seedfill and connected components
  • Image transformations with changes in pixel depth, both at the same scale and with scale change
  • Pixelwise masking, blending, enhancement, arithmetic ops, etc.

Ancillary utilities

  • I/O for standard image formats (jpg, png, tiff, webp, jp2, bmp, pnm, gif, ps, pdf)
  • Utilities to handle arrays of image-related data types (e.g., pixa, boxa, pta)
  • Utilities for stacks, generic arrays, queues, heaps, lists; number and string arrays; etc.

Examples of some applications enabled and implemented

  • Octcube-based color quantization (w/ and w/out dithering)
  • Modified median cut color quantization (w/ and w/out dithering)
  • Skew determination of text images
  • Adaptive normalization and binarization
  • Segmentation of page images with mixed text and images
  • Location of baselines and local skew determination
  • jbig2 unsupervised classifier
  • Border representations of 1 bpp images and raster conversion for SVG
  • Postscript generation (levels 1, 2 and 3) of images for device-independent output
  • PDF generation (G4, DCT, FLATE) of images for device-independent output
  • Connectivity-preserving thinning and thickening of 1 bpp images
  • Image warping (captcha, stereoscopic)
  • Image dewarping based on content (textlines)
  • Watershed transform
  • Greedy splitting of components into rectangles
  • Location of largest fg or bg rectangles in 1 bpp images
  • Search for least-cost paths on binary and grayscale images
  • Barcode reader for 1D barcodes (very early version as of 1.55)

Implementation characteristics

  • Efficient: image data is packed binary (into 32-bit words); operations on 32-bit data whenever possible
  • Simple: small number of data structures; simplest implementations provided that are efficient
  • Consistent: data allocated on the heap with simple ownership rules; function names usually begin with primary data structure (e.g., pix); simple code patterns throughout
  • Robust: all ptr args checked; extensive use of accessors; exit not permitted
  • Tested: thorough regression tests provided for most basic functions; valgrind tested
  • ANSI C: automatically generated prototype header file
  • Portable: endian-independent; builds in Linux, macOS, MinGW, Cygwin, Windows
  • Nearly thread-safe: ref counting on some structs
  • Documentation: large number of in-line comments; doxygen; web pages for further background
  • Examples: many programs provided to test and show usage of approx. 2600 functions in the library

Open Source Projects that use Leptonica

  • tesseract (optical character recognition)
  • OpenCV (computer vision library)
  • jbig2enc (encodes multipage binary image documents with jbig2 compression)

Major contributors to Leptonica

  • Tom Powers: Tom has supported Leptonica on Windows for many years. He has made many contributions to code quality and documentation, including the beautiful "unofficial documentation" on the web site. Without his effort, Leptonica would not run today on Windows.
  • David Bryan: David has worked for years to support Leptonica on multiple platforms. He designed many nice features in Leptonica, such as the severity-based error messaging system, and has identified and fixed countless bugs. And he has built and tested each distribution many times on cross-compilers.
  • James Le Cuirot: James has written and supported the autotools scripts on Leptonica distributions for many years, and has helped test every distribution since 1.67.
  • Jeff Breidenbach: Jeff has built every Debian distribution for Leptonica. He has also made many improvements to formatted image I/O, including tiff, png and pdf. He is a continuous advocate for simplification.
  • Egor Pugin: Egor is co-maintainer of Leptonica on GitHub. He ported everything, including all the old distributions, from Google Code when it shut down. He set Leptonica up for appveyor and travis testing, and has implemented the sw project, which simplifies building executables on Windows.
  • Jürgen Buchmüller: Jürgen wrote text converters to modify Leptonica source code so that it generates documentation using doxygen. He also wrote tiff wrappers for memory I/O.
  • Stefan Weil: Stefan has worked from the beginning to clean up the Leptonica GitHub distribution, including removing errors in the source code. He also suggested and implemented the use of Coverity Scan.
  • Zdenko Podobny: Zdenko has worked, mostly behind the scenes as a primary maintainer of tesseract, to help with leptonica builds on all platforms, and coordinate with its use in tesseract.
Comments
  • Handle $TMPDIR when located under /tmp

    Handle $TMPDIR when located under /tmp

    When adding the remainder of the cdir string to give the full value of pathout in genPathname(), the current code hardcodes a $TMPDIR string length of 4 characters (src/utils.c, lines 3004-5).

    The result of this hardcoding is that the function will re-append any additional characters in the $TMPDIR string beyond "/tmp" into the pathout string when determining its full contents.

    This causes failures when trying to open and write to files in $TMPDIR on Debian (and possibly other Linux distributions) that do not use plain /tmp as $TMPDIR for an unprivileged user. On Debian, a regular user's $TMPDIR is /tmp/username, not /tmp.

    This commit aims to ensure that the full $TMPDIR string length is used and that only nested path entries below $TMPDIR (and not "/tmp") are appended when determining pathout.

    Diagnosed using strace after failures running tesseract-ocr and gscan2pdf. No failures were observed when running as the superuser; strace confirmed the issue was broken pathnames and not r/w privileges.

    opened by knowledgejunkie 44
  • webpio_reg test failure on big endian (ppc64, s390x)

    webpio_reg test failure on big endian (ppc64, s390x)

    Hi, Noticed this when attempting to update the Fedora package to 1.75.2 (https://koji.fedoraproject.org/koji/taskinfo?taskID=24954012)

    FAIL: webpio_reg
    ================
    ################   webpio_reg   ###############
    leptonica-1.75.2
    libgif 5.1.4 : libjpeg 6b (libjpeg-turbo 1.5.3) : libpng 1.6.34 : libtiff 4.0.9 : zlib 1.2.11 : libwebp 0.6.1
    Time to read jpg:   0.000
    Time to write webp:   0.005
    Time to read webp:   0.000
    Time to read jpg:   0.000
    Time to write webp:   0.000
    Time to read webp:   0.000
    Time to read jpg:   0.000
    Time to write webp:   0.069
    Time to read webp:   0.010
    Time to read jpg:   0.009
    Time to write webp:   0.515
    Time to read webp:   0.049
    qual = 50, psnr =  43.501
    qual = 75, psnr =  46.071
    qual = 90, psnr =  52.379
    qual = 100, psnr =  57.460
    Lossless write:   0.871 sec
    lossless; psnr should be 1000: psnr =  23.222
    Failure in webpio_reg: value comparison for index 12
    difference = 976.777893 but allowed delta = 0.100000
    Time:   3.986 sec
    ################################################
    
    opened by manisandro 37
  • error LNK2019: unresolved external symbol on all function call defined in 'allheaders.h'

    error LNK2019: unresolved external symbol on all function call defined in 'allheaders.h'

    What steps will reproduce the problem?
    1. Download and use the static libraries and include file
    2. VS 2012 on Windows 8 Pro 64-Bit
    3.
    
    What is the expected output? What do you see instead?
    I expect the application to compile but am getting LNK2019 errors on all 
    functions defined in allheaders.h
    
    What version of the product are you using? On what operating system?
    Windows 8 Pro; Visual studios 2012; Leptonica 
    
    Please provide any additional information below.
    
    

    Original issue reported on code.google.com by [email protected] on 11 Jul 2013 at 5:27

    Priority-Medium Type-Defect auto-migrated 
    opened by GoogleCodeExporter 27
  • Leptonica for OCR image preprocessing

    Leptonica for OCR image preprocessing

    Hello,

    I need to preprocess scanned images in order to improve the following OCR quality. I already able to remove horizontal and vertical lines with Leptonica(Java lept4j) library.

    I just wondering if there is a scripts written with Leptonica library in order to do the image preprocessing - for example, cleaning scanning artifacts, noise, etc. Thanks!

    opened by Artgit 23
  • Unable to build Leptonica 1.78.0

    Unable to build Leptonica 1.78.0

    First error is a link error: alpha_dec.obj module machine type 'x86' conflicts with target machine type 'x64' in cppan-d-b-d project. Then 10 more errors saying: missing type specifier in tiff.h in the leptonica project

    opened by SteveKlinko 22
  •  undefined macros and syntax error with configure.ac

    undefined macros and syntax error with configure.ac

    @chewi

    I've installed the latest version of automake (etc). Now, when running my autobuild file, I am getting errors:

    libtoolize: putting auxiliary files in AC_CONFIG_AUX_DIR, 'config'. libtoolize: copying file 'config/ltmain.sh' libtoolize: putting macros in AC_CONFIG_MACRO_DIRS, 'm4'. libtoolize: copying file 'm4/libtool.m4' libtoolize: copying file 'm4/ltoptions.m4' libtoolize: copying file 'm4/ltsugar.m4' libtoolize: copying file 'm4/ltversion.m4' libtoolize: copying file 'm4/lt~obsolete.m4' configure.ac:38: error: possibly undefined macro: AS_IF If this token and others are legitimate, please use m4_pattern_allow. See the Autoconf documentation. configure.ac:44: error: possibly undefined macro: AC_DEFINE configure.ac:46: error: possibly undefined macro: AC_CHECK_LIB configure.ac:47: error: possibly undefined macro: AC_CHECK_HEADER configure.ac:50: error: possibly undefined macro: AC_SUBST configure.ac:52: error: possibly undefined macro: AC_MSG_ERROR configure.ac:178: error: possibly undefined macro: AC_CHECK_HEADERS configure.ac:179: error: possibly undefined macro: AC_DEFINE_UNQUOTED configure.ac:8: installing 'config/compile' configure.ac:10: installing 'config/missing' prog/Makefile.am: installing 'config/depcomp'

    Has something been deprecated?

    I could suppress the error messages using m4_pattern_allow([AS_IF]) etc., but could not fix the problem, because when running ./configure, I get this error, and no Makefile is made:

    ./configure: line 13070: syntax error near unexpected token ZLIB,' ./configure: line 13070: PKG_CHECK_MODULES(ZLIB, zlib,'

    opened by DanBloomberg 21
  • Handle temporary directories on iOS

    Handle temporary directories on iOS

    On iOS, you can't write to /tmp; each application has its own temporary directory. So we rely on the system to tell us where this directory is located.

    opened by bvirlet 20
  • Doxygen: add a quick hack converter + Doxyfile

    Doxygen: add a quick hack converter + Doxyfile

    The converter relies on the rather constant formatting of the current function's block comments and tries to turn them into proper doxygen format.

    The "/*!" doxygen comment introducer and the "\file" tag are inserted when the first line with exact format " * <basename>" is found, e.g. " * adaptmap.c".

    The included Doxyfile is a first example for a configuration.

    This PR fixes minor deviances in comment format:

    • Add missing doxygen comment introducers "/*!".
    • Some function's comments had "Return" without a colon ("Return:")
    • Many function's comments used @name to reference parameters, while doxygen expects %name for references (@ is a command introducer equal to \).
    • Add a new attribute <inout> for parameters in *Destroy() functions and unify the format of the comment.
    • Move "Input:" and "Return:" to column 8 where they were in another column
    • Replace "Note:" with "Notes:" where appropriate to make conv2doxy correctly detect the detailed description in function's block comments.
    • Move "Notes:" to column 4 where it was in another column.
    • Replace sub-paragraph " - " with " ~ " to avoid doxygen interpreting the text thereafter as a list entry; i.e. keep pre-formatted indentation.
    • Replace "null on error" with "NULL on error" in \return comments
    • Replace "Input: stream" with "Input: fp (file stream)" where appropriate.

    The idea after merging this pull request is:

    • the source tree could or should be tagged with something like Before transition to doxygen comment style.
    • conv2doxy.c should be compiled and the binary be run once on every src/*.c file with e.g. ls src/*.c|xargs ./conv2doxy
    • now do something like git add src/*.c, git commit -m "After transition to doxygen comment style" and git push.
    • finally doxygen can be run and the resulting doc/html be published at some server.
    • the output doxygen.log can be used to identify more parameter name mismatches etc.
    • whenever new functions are added or existing documentation is fixed or improved, run doxygen again and upload the result. I for example used rsync -avH --del doc/html [email protected]:~/public_html/misc.
    • the original, backup files can be removed with rm src/*.c~

    This closes #126

    opened by pullmoll 20
  • Info in dewarpaSetValidModels: no model successfully built

    Info in dewarpaSetValidModels: no model successfully built

    Greetings,

    I am currently attempting to use Leptonica to dewarp scanned phone book images (e.g., see below).

    RI_1975_1_copy

    I wrote a program using the example program prog/dewarp1.c as a template where a model can't successfully be built.

    Info in dewarpGetTextlineCenters: finding text line centers
    Warning in dewarpRemoveShortLines: lines are relatively short
    Warning in dewarpBuildPageModel: linecount 3 < min req'd number of lines (10) for model
    Info in dewarpaSetValidModels: page 0: no model successfully built
    Info in dewarpaApplyInit: no valid dew model for page 0
    Error in dewarpaApplyDisparity: no model available
    Info in pixWriteStreamJpeg: converting from 1 to 8 bpp
    Error in fopenReadStream: file not found
    Error in pixRead: image file not found: /tmp/lept/dewmod/0060.png
    Error in pixWrite: pix not defined
    Error in fopenReadStream: file not found
    Error in pixRead: image file not found: /tmp/lept/dewmod/0070.png
    Error in pixWrite: pix not defined
    Error in fopenReadStream: file not found
    Error in pixRead: image file not found: /tmp/lept/dewapply/002.png
    Error in pixWrite: pix not defined
    Error in fopenReadStream: file not found
    Error in pixRead: image file not found: /tmp/lept/dewapply/003.png
    Error in pixWrite: pix not defined
    
    concatenating ... done
    pdf file made: /tmp/lept/model/dewarptest1.pdf
    

    Here is a summary of the changes:

    • The input image pixs contains the image above
    • Excluded converting from RGB to Gray using pixConvertRGBToGray since the image is already in grayscale
    • Set the number of dewarp pages from 2 to 1 in dewarpaCreate
    • Since the page I'm processing doesn't have a page number, I set the page number from 35 to 0 in dewarpCreate and dewarpaApplyDisparity
    • Removed normalizing another image

    Here is the full program and image to be processed.

    Any help would be greatly appreciated!

    opened by mattsliv 19
  • problem using leptonica on mac OSX 10.4 for tesseract

    problem using leptonica on mac OSX 10.4 for tesseract

    What steps will reproduce the problem?
    1. .Installed leptonlib-1.67
    2.Compiled tesseract 3.00 and installed
    3. Ran teserract
    
    What is the expected output? What do you see instead?
    Expected tesseract to produce the OCR result.  Got the following errors
    Tesseract Open Source OCR Engine with Leptonica
    Error in findTiffCompression: function not present
    Error in tiffGetCount: function not present
    Error reading file ./namefile
    
    What version of the product are you using? On what operating system?
    leptonica 1.67 on mac OSX 10.4; tesseract 3.00
    
    Please provide any additional information below.
    
    you can find additional information here:
    
    http://code.google.com/p/tesseract-ocr/issues/detail?id=340#c0
    
    

    Original issue reported on code.google.com by [email protected] on 4 Jan 2011 at 12:39

    Priority-Medium Type-Defect auto-migrated 
    opened by GoogleCodeExporter 18
  • gif Problem (used version is giflib 4.1.6).

    gif Problem (used version is giflib 4.1.6).

    What steps will reproduce the problem?
    1. it can read gif files but when exit the program halts itself.
    2. just occurs this fault with gif files.
    
    What is the expected output? What do you see instead?
    gif files in other vision libraries like openCV can be read/write
    correctly/ without any fault. giflib4.1.6 is used in openCV and there is no
    problem.
    
    
    What version of the product are you using? On what operating system?
    Windows Vista Home Premium.
    
    Please provide any additional information below.
    Leptonica v1.65
    
    

    Original issue reported on code.google.com by [email protected] on 9 May 2010 at 2:48

    Priority-Medium Type-Defect auto-migrated 
    opened by GoogleCodeExporter 18
  • pixWriteMemJpeg

    pixWriteMemJpeg

    The function pixWriteMemJpeg uses open_memstream on systems where this available. On other system, the function writes to a temporary file and then reads that in.

    libjpeg natively provides a 'memory' destination and 'memory' source. The libjpeg.txt file in the libjpeg source code provides details of this.

    For compression, it provides jpeg_mem_dest which takes two arguments .. unsigned char ** outbuffer and unsigned long * outsize

    The 2nd argument's data type is different from the one provided in pixWriteMemJpeg which is size_t.

    I tried out the compression routine and it works fine .. I copied the existing pixWriteStreamJpeg function, modified the arguments to receive the pdata and psize; and replaced the jpeg_stdio_dest with jpeg_mem_dest.

    If you could let me know how you would like this to be implemented, I could do that and submit it.

    Thanks K

    opened by bkimman 1
  • How big of a skew angle can Leptonica detect?

    How big of a skew angle can Leptonica detect?

    Good day,

    I am looking for a non-AI solution that can detect skew angle of a scanned PDF text document. I have found some solutions that can detect a skew angle from -45 to 45 degrees, but they don't work reliably.

    So, I am curious how big of a skew angle can Leptonica detect?

    opened by Andrija-Markovic 5
  • can you support generate ninja in leptonica?

    can you support generate ninja in leptonica?

    Can you support Generate Ninja in your project because I want to raise a pull request and I build my project through this way, It would be great if you could reply.

    question 
    opened by caiqi1126 1
  • I want to perform several operations on images. What interfaces do I need to use? Thank you very much!

    I want to perform several operations on images. What interfaces do I need to use? Thank you very much!

    I want to perform several operations on images. What interfaces do I need to use? Thank you very much!

    1. Fills the rectangular area specified by the image with color

    2. Overlap one graph to another somewhere

    3. The image is horizontally and vertically mirrored

    opened by jueqing1015 3
  • Leptonica has any ECCN(Export Control Certification Number)

    Leptonica has any ECCN(Export Control Certification Number)

    Thank you for your support. Kindly share the below information. Doe Leptonica has any ECCN(Export Control Certification Number) OR it does not require any ECCN as it is a open source? Quick reply will be helpful for us as we are planning to use it in our produce and release it. Thanks in advance.

    question 
    opened by shq251 1
  • pixAutoPhotoinvert - the sequel

    pixAutoPhotoinvert - the sequel

    175789293-f39ddfdb-6f3e-4598-8d16-80a1f4a88b36

    results with defaults 0,NULL,NULL in

    Plaatje achteraf

    The KVK on top left should be left as it was, or at least the bottom half of the V should be one way or the other to be covered by MRC. The text print - wis - clear on the top right should invert.

    The applied algorithm might not be sufficiënt. If so DjVu has an expired patented algorithm for foreground/background separation: https://patents.google.com/patent/US6901169

    However it performs less when there's noise in the scan that looks like holes in the mask: https://github.com/jwilk/didjvu/issues/21

    But in this example, straightly converted from an electronic PDF form, there should be no issue at all.

    opened by rmast 2
Releases(1.82.0)
Owner
Dan Bloomberg
Dan Bloomberg
Like feh, but better, faster, more image formats, simpler, more lightweight, animation support, and better UI

Like feh, but better, faster, more image formats, simpler, more lightweight, animation support, and better UI

martin 11 Oct 23, 2022
A toolkit for making real world machine learning and data analysis applications in C++

dlib C++ library Dlib is a modern C++ toolkit containing machine learning algorithms and tools for creating complex software in C++ to solve real worl

Davis E. King 11.5k Nov 29, 2022
Reading, writing, and processing images in a wide variety of file formats, using a format-agnostic API, aimed at VFX applications.

README for OpenImageIO Introduction The primary target audience for OIIO is VFX studios and developers of tools such as renderers, compositors, viewer

OpenImageIO 1.6k Nov 22, 2022
C++ image processing and machine learning library with using of SIMD: SSE, SSE2, SSE3, SSSE3, SSE4.1, SSE4.2, AVX, AVX2, AVX-512, VMX(Altivec) and VSX(Power7), NEON for ARM.

Introduction The Simd Library is a free open source image processing and machine learning library, designed for C and C++ programmers. It provides man

Ihar Yermalayeu 1.7k Nov 23, 2022
a generic C++ library for image analysis

VIGRA Computer Vision Library Copyright 1998-2013 by Ullrich Koethe This file is part of the VIGRA computer vision library. You may use,

Ullrich Koethe 377 Nov 29, 2022
Video++, a C++14 high performance video and image processing library.

Video++ Video++ is a video and image processing library taking advantage of the C++14 standard to ease the writing of fast video and image processing

Matthieu Garrigues 689 Oct 14, 2022
ppl.cv is a high-performance image processing library of openPPL supporting x86 and cuda platforms.

ppl.cv is a high-performance image processing library of openPPL supporting x86 and cuda platforms.

null 364 Nov 23, 2022
A fast image processing library with low memory needs.

libvips : an image processing library Introduction libvips is a demand-driven, horizontally threaded image processing library. Compared to similar lib

libvips 26 Nov 10, 2022
GLSL Image Processing System

GIPS: The GLSL Image Processing System An image processing application that applies filters written in the OpenGL Shading Language (GLSL). This means

Martin Fiedler 57 Nov 29, 2022
Intel® Open Image Denoise library

Intel Open Image Denoise is an open source library of high-performance, high-quality denoising filters for images rendered with ray tracing

Intel® Open Image Denoise 1.3k Nov 26, 2022
This is a demonstration repository for The Pitt Challenge project about medical image compression.

Image Compression for Portable Medical Records This is a demonstration repository for The Pitt Challenge project about medical image compression. Back

null 3 Oct 24, 2021
ImTricks is a collection of useful functions for expanding / improving the functionality of the ImGui.

ImTricks ImTricks is a collection of useful functions for expanding / improving the functionality of the ImGui. At the moment it has in itself: Functi

Alexander Pers0na2 22 Jun 13, 2022
PoC black/white image sequence to dumpy gif image sequence converter

PoC black/white image sequence to dumpy gif image sequence converter

null 68 Nov 10, 2022
The “Quite OK Image” format for fast, lossless image compression

The “Quite OK Image” format for fast, lossless image compression

Dominic Szablewski 5.9k Nov 30, 2022
An open source library for face detection in images. The face detection speed can reach 1000FPS.

libfacedetection This is an open source library for CNN-based face detection in images. The CNN model has been converted to static variables in C sour

Shiqi Yu 11.3k Nov 28, 2022
This library provides a cross-platform image loading library in C11 for projects based on our foundation library

Image Library - Public Domain This library provides a cross-platform image loading library in C11 for projects based on our foundation library.

Mattias Jansson 1 Jan 29, 2022
Arduino PNG image decoder library

An 'embedded-friendly' (aka Arduino) PNG image decoding library

Larry Bank 99 Nov 26, 2022
libvot - A C++11 multi-thread library for image retrieval

libvot is a fast implementation of vocabulary tree, which is an algorithm widely used in image retrieval and computer vision. It usually comprises three components to build a image retrieval system using vocabulary tree: build a k-means tree using sift descriptors from images, register images into the database, query images against the database. I

Tianwei Shen 171 Nov 15, 2022
An 'embedded-friendly' (aka Arduino) JPEG image encoding library

Starting in the late 80's I wrote my own imaging codecs for the existing standards (CCITT G3/G4 was the first). I soon added GIF, JPEG and not long after that, the PNG specification was ratified. All of this code was "clean room" - written just from the specification. I used my imaging library in many projects and products over the years and recently decided that some of my codecs could get a new lease on life as open source, embedded-friendly libraries for microcontrollers.

Larry Bank 36 Oct 16, 2022