Skip to main content

Command-line application to binarize images

Project description

img2bw

img2bw is a simple command-line application to binarize images.

Installation

Open the terminal, go to the folder of this package and type:

pip install img2bw

Tested on Python3.7

Usage

To binarize a single image, type:

img2bw image.jpg --method otsu

To binarize all the images in a directory, type:

img2bw input_dir/ --output output_dir/

If no method is specified, otsu will be used.

You can try all the methods using --method try-all

Thresholding algorithms

  • Global thresholding:

    • otsu: Otsu, Nobuyuki. "A threshold selection method from gray-level histograms." IEEE transactions on systems, man, and cybernetics 9.1 (1979): 62-66.
    • p-tile: Parker, J. R. (2010). Algorithms for image processing and computer vision. John Wiley & Sons. (p-tile)
    • two-peaks: Parker, J. R. (2010). Algorithms for image processing and computer vision. John Wiley & Sons. (Two peaks)
    • min-error: Kittler, J. and J. Illingworth. ‘‘On Threshold Selection Using Clustering Criteria,’’ IEEE Transactions on Systems, Man, and Cybernetics 15, no. 5 (1985): 652–655.
    • multiotsu: Liao, P-S., Chen, T-S. and Chung, P-C., "A fast algorithm for multilevel thresholding", Journal of Information Science and Engineering 17 (5): 713-727, 2001.
    • isodata: Ridler, TW & Calvard, S (1978), "Picture thresholding using an iterative selection method" IEEE Transactions on Systems, Man and Cybernetics 8: 630-632, :DOI:10.1109/TSMC.1978.4310039
    • minimum: C. A. Glasbey, "An analysis of histogram-based thresholding algorithms," CVGIP: Graphical Models and Image Processing, vol. 55, pp. 532-537, 1993.
    • triangle: Zack, G. W., Rogers, W. E. and Latt, S. A., 1977, Automatic Measurement of Sister Chromatid Exchange Frequency, Journal of Histochemistry and Cytochemistry 25 (7), pp. 741-753 :DOI:10.1177/25.7.70454
    • yen: Yen J.C., Chang F.J., and Chang S. (1995) "A New Criterion for Automatic Multilevel Thresholding" IEEE Trans. on Image Processing, 4(3): 370-378. :DOI:10.1109/83.366472
    • mean: C. A. Glasbey, "An analysis of histogram-based thresholding algorithms," CVGIP: Graphical Models and Image Processing,vol. 55, pp. 532-537, 1993. :DOI:10.1006/cgip.1993.1040
  • Entropy thresholding:

    • pun: Pun, T. "A New Method for Grey-Level Picture Thresholding Using the Entropy of the Histogram,"" Signal Processing 2, no. 3 (1980): 223–237.
    • kapur: Kapur, J. N., P. K. Sahoo, and A. K. C.Wong. "A New Method for Gray-Level Picture Thresholding Using the Entropy of the Histogram,"" Computer Vision, Graphics, and Image Processing 29, no. 3 (1985): 273–285.
    • johannsen: Johannsen, G., and J. Bille "A Threshold Selection Method Using Information Measures,"" Proceedings of the Sixth International Conference on Pattern Recognition, Munich, Germany (1982): 140–143.
    • li: Li C.H. and Lee C.K. (1993) "Minimum Cross Entropy Thresholding" Pattern Recognition, 26(4): 617-625 :DOI:10.1016/0031-3203(93)90115-D
  • Local thresholding:

    • bradley-roth: Bradley, D., & Roth, G. (2007). Adaptive thresholding using the integral image. Journal of Graphics Tools, 12(2), 13-21.
    • bernsen: Bernsen, J (1986), "Dynamic Thresholding of Grey-Level Images", Proc. of the 8th Int. Conf. on Pattern Recognition
    • contrast: Parker, J. R. (2010). Algorithms for image processing and computer vision. John Wiley & Sons. (Contrast thresholding)
    • feng: Meng-Ling Feng and Yap-Peng Tan, "Contrast adaptive thresholding of low quality document images”, IEICE Electron. Express, Vol. 1, No. 16, pp.501-506, (2004).
    • local: Parker, J. R. (2010). Algorithms for image processing and computer vision. John Wiley & Sons. (Local mean thresholding)
    • niblack: Niblack, W.: "An introduction to digital image processing" (Prentice- Hall, Englewood Cliffs, NJ, 1986), pp. 115–116
    • sauvola: Sauvola, J., Seppanen, T., Haapakoski, S., and Pietikainen, M.: "Adaptive document thresholding". Proc. 4th Int. Conf. on Document Analysis and Recognition, Ulm Germany, 1997, pp. 147–152.
    • wolf: C. Wolf, J-M. Jolion, "Extraction and Recognition of Artificial Text in Multimedia Documents", Pattern Analysis and Applications, 6(4):309-326, (2003).
    • nick: Khurshid, K., Siddiqi, I., Faure, C., & Vincent, N. (2009, January). Comparison of Niblack inspired Binarization methods for ancient documents. In IS&T/SPIE Electronic Imaging (pp. 72470U-72470U). International Society for Optics and Photonics.
    • singh: Singh, O. I., Sinam, T., James, O., & Singh, T. R. (2012). Local contrast and mean based thresholding technique in image binarization. International Journal of Computer Applications, 51, 5-10.

More options

To view all the available options, type img2bw --help in the terminal:

usage: img2bw [-h] [-o OUTPUT] [-e {jpg,jpeg,jfif,png,tiff,bmp,pnm}]
              [-m {otsu,isodata,li,local,mean,minimum,multiotsu,niblack,sauvola,triangle,yen,try-all}]
              [-b BLOCK_SIZE] [-c NUM_CLASSES]
              input

positional arguments:
  input                 Input file or directory

optional arguments:
  -h, --help            show this help message and exit
  -o OUTPUT, --output OUTPUT
                        Output file or directory
  -e {jpg,jpeg,jfif,png,tiff,bmp,pnm}, --output-ext {jpg,jpeg,jfif,png,tiff,bmp,pnm}
                        Output file extension
  -m {otsu,isodata,li,local,mean,minimum,multiotsu,niblack,sauvola,triangle,yen,try-all}, --method {otsu,isodata,li,local,mean,minimum,multiotsu,niblack,sauvola,triangle,yen,try-all}
                        Method used to perform the binarization
  -b BLOCK_SIZE, --block-size BLOCK_SIZE
                        Odd size of pixel neighborhood which is used to
                        calculate the threshold value (local threshold)
  -c NUM_CLASSES, --num-classes NUM_CLASSES
                        Number of classes to be thresholded (multiotsu)

Additional information

This package is simply wrapper to easily apply multiple threshold algorithms to an image (or the images in a directory). I didn't code the algorithms so I send a big thank you to all the authors of libraries that made this wrapper possible:

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

img2bw-0.2.0.tar.gz (7.3 kB view details)

Uploaded Source

Built Distribution

img2bw-0.2.0-py3-none-any.whl (8.6 kB view details)

Uploaded Python 3

File details

Details for the file img2bw-0.2.0.tar.gz.

File metadata

  • Download URL: img2bw-0.2.0.tar.gz
  • Upload date:
  • Size: 7.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.4

File hashes

Hashes for img2bw-0.2.0.tar.gz
Algorithm Hash digest
SHA256 89ddf9cd204ba6e2862d31b6a8222c2025c9d4b62f3a4a26e2bdb22c477d9082
MD5 71c8974ba4bb87f5a44342f9bdf4ef8e
BLAKE2b-256 34be5a201e953b35b03210bc321fcc39eedf7af16167f46d30366ff4cb6a5ede

See more details on using hashes here.

File details

Details for the file img2bw-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: img2bw-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 8.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.4

File hashes

Hashes for img2bw-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2d72993be81837995b86e38310c87c27618e6191f2c576feabd1a503d87709fc
MD5 c31481427c47e20c88e44933f362f7c7
BLAKE2b-256 91e0f383a0b5d1794a465c6659eeeb34e884e798300340c489e80c90817b76cf

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page