Mahotas: Computer Vision Library
Project description
Mahotas
Python Computer Vision Library
Mahotas is a library of fast computer vision algorithms (all implemented in C++ for speed) operating over numpy arrays.
Python versions 2.7, 3.4+, are supported.
Notable algorithms:
- watershed
- convex points calculations.
- hit & miss, thinning.
- Zernike & Haralick, LBP, and TAS features.
- Speeded-Up Robust Features (SURF), a form of local features.
- thresholding.
- convolution.
- Sobel edge detection.
- spline interpolation
- SLIC super pixels.
Mahotas currently has over 100 functions for image processing and computer vision and it keeps growing.
The release schedule is roughly one release a month and each release brings new functionality and improved performance. The interface is very stable, though, and code written using a version of mahotas from years back will work just fine in the current version, except it will be faster (some interfaces are deprecated and will be removed after a few years, but in the meanwhile, you only get a warning). In a few unfortunate cases, there was a bug in the old code and your results will change for the better.
Please cite the mahotas paper (see details below under Citation) if you use it in a publication.
Examples
This is a simple example (using an example file that is shipped with mahotas) of calling watershed using above threshold regions as a seed (we use Otsu to define threshold).
# import using ``mh`` abbreviation which is common:
import mahotas as mh
# Load one of the demo images
im = mh.demos.load('nuclear')
# Automatically compute a threshold
T_otsu = mh.thresholding.otsu(im)
# Label the thresholded image (thresholding is done with numpy operations
seeds,nr_regions = mh.label(im > T_otsu)
# Call seeded watershed to expand the threshold
labeled = mh.cwatershed(im.max() - im, seeds)
Here is a very simple example of using mahotas.distance
(which
computes a distance map):
import pylab as p
import numpy as np
import mahotas as mh
f = np.ones((256,256), bool)
f[200:,240:] = False
f[128:144,32:48] = False
# f is basically True with the exception of two islands: one in the lower-right
# corner, another, middle-left
dmap = mh.distance(f)
p.imshow(dmap)
p.show()
(This is under mahotas/demos/distance.py.)
How to invoke thresholding functions:
import mahotas as mh
import numpy as np
from pylab import imshow, gray, show, subplot
from os import path
# Load photo of mahotas' author in greyscale
photo = mh.demos.load('luispedro', as_grey=True)
# Convert to integer values (using numpy operations)
photo = photo.astype(np.uint8)
# Compute Otsu threshold
T_otsu = mh.otsu(photo)
thresholded_otsu = (photo > T_otsu)
# Compute Riddler-Calvard threshold
T_rc = mh.rc(photo)
thresholded_rc = (photo > T_rc)
# Now call pylab functions to display the image
gray()
subplot(2,1,1)
imshow(thresholded_otsu)
subplot(2,1,2)
imshow(thresholded_rc)
show()
As you can see, we rely on numpy/matplotlib for many operations.
Install
If you are using conda, you can install mahotas from conda-forge using the following commands:
conda config --add channels conda-forge
conda install mahotas
Compilation from source
You will need python (naturally), numpy, and a C++ compiler. Then you should be able to use:
pip install mahotas
You can test your installation by running:
python -c "import mahotas as mh; mh.test()"
If you run into issues, the manual has more extensive documentation on mahotas installation, including how to find pre-built for several platforms.
Citation
If you use mahotas on a published publication, please cite:
Luis Pedro Coelho Mahotas: Open source software for scriptable computer vision in Journal of Open Research Software, vol 1, 2013. [DOI]
In Bibtex format:
@article{mahotas, author = {Luis Pedro Coelho}, title = {Mahotas: Open source software for scriptable computer vision}, journal = {Journal of Open Research Software}, year = {2013}, doi = {http://dx.doi.org/10.5334/jors.ac}, month = {July}, volume = {1} }
You can access this information using the mahotas.citation()
function.
Development
Development happens on github (http://github.com/luispedro/mahotas).
You can set the DEBUG
environment variable before compilation to get a
debug version:
export DEBUG=1
python setup.py test
You can set it to the value 2
to get extra checks:
export DEBUG=2
python setup.py test
Be careful not to use this in production unless you are chasing a bug. Debug level 2 is very slow as it adds many runtime checks.
The Makefile
that is shipped with the source of mahotas can be useful
too. make debug
will create a debug build. make fast
will create a
non-debug build (you need to make clean
in between). make test
will
run the test suite.
Links & Contacts
Documentation: https://mahotas.readthedocs.io/
Issue Tracker: github mahotas issues
Mailing List: Use the pythonvision mailing list for questions, bug submissions, etc. Or ask on stackoverflow (tag mahotas)
Main Author & Maintainer: Luis Pedro Coelho (follow on twitter or github).
Mahotas also includes code by Zachary Pincus [from scikits.image], Peter J. Verveer [from scipy.ndimage], and Davis King [from dlib], Christoph Gohlke, as well as others.
Presentation about mahotas for bioimage informatics
For more general discussion of computer vision in Python, the pythonvision mailing list is a much better venue and generates a public discussion log for others in the future. You can use it for mahotas or general computer vision in Python questions.
Recent Changes
Version 1.4.12 (Oct 14 2021)
- Update to newer NumPy
- Build wheels for Python 3.9 & 3.10
Version 1.4.11 (Aug 16 2020)
- Convert tests to pytest
- Fix testing for PyPy
Version 1.4.10 (Jun 11 2020)
- Build wheels automatically (PR #114 by nathanhillyer)
Version 1.4.9 (Nov 12 2019)
- Fix FreeImage detection (issue #108)
Version 1.4.8 (Oct 11 2019)
- Fix co-occurrence matrix computation (patch by @databaaz)
Version 1.4.7 (Jul 10 2019)
- Fix compilation on Windows
Version 1.4.6 (Jul 10 2019)
- Make watershed work for >2³¹ voxels (issue #102)
- Remove milk from demos
- Improve performance by avoid unnecessary array copies in
cwatershed()
,majority_filter()
, and color conversions - Fix bug in interpolation
Version 1.4.5 (Oct 20 2018)
- Upgrade code to newer NumPy API (issue #95)
Version 1.4.4 (Nov 5 2017)
- Fix bug in Bernsen thresholding (issue #84)
Version 1.4.3 (Oct 3 2016)
- Fix distribution (add missing
README.md
file)
Version 1.4.2 (Oct 2 2016)
- Fix
resize\_to
return exactly the requested size - Fix hard crash when computing texture on arrays with negative values (issue #72)
- Added
distance
argument to haralick features (pull request #76, by Guillaume Lemaitre)
Version 1.4.1 (Dec 20 2015)
- Add
filter\_labeled
function - Fix tests on 32 bit platforms and older versions of numpy
Version 1.4.0 (July 8 2015)
- Added
mahotas-features.py
script - Add short argument to citation() function
- Add max_iter argument to thin() function
- Fixed labeled.bbox when there is no background (issue #61, reported by Daniel Haehn)
- bbox now allows dimensions greater than 2 (including when using the
as_slice
andborder
arguments) - Extended croptobbox for dimensions greater than 2
- Added use_x_minus_y_variance option to haralick features
- Add function
lbp_names
Version 1.3.0 (April 28 2015)
- Improve memory handling in freeimage.write_multipage
- Fix moments parameter swap
- Add labeled.bbox function
- Add return_mean and return_mean_ptp arguments to haralick function
- Add difference of Gaussians filter (by Jianyu Wang)
- Add Laplacian filter (by Jianyu Wang)
- Fix crash in median_filter when mismatched arguments are passed
- Fix gaussian_filter1d for ndim > 2
Version 1.2.4 (December 23 2014)
- Add PIL based IO
Version 1.2.3 (November 8 2014)
- Export mean_filter at top level
- Fix to Zernike moments computation (reported by Sergey Demurin)
- Fix compilation in platforms without npy_float128 (patch by Gabi Davar)
Version 1.2.2 (October 19 2014)
- Add minlength argument to labeled_sum
- Generalize regmax/regmin to work with floating point images
- Allow floating point inputs to
cwatershed()
- Correctly check for float16 & float128 inputs
- Make sobel into a pure function (i.e., do not normalize its input)
- Fix sobel filtering
Version 1.2.1 (July 21 2014)
- Explicitly set numpy.include_dirs() in setup.py [patch by Andrew Stromnov]
Version 1.2 (July 17 2014)
- Export locmax|locmin at the mahotas namespace level
- Break away ellipse_axes from eccentricity code as it can be useful on its own
- Add
find()
function - Add
mean_filter()
function - Fix
cwatershed()
overflow possibility - Make labeled functions more flexible in accepting more types
- Fix crash in
close_holes()
with nD images (for n > 2) - Remove matplotlibwrap
- Use standard setuptools for building (instead of numpy.distutils)
- Add
overlay()
function
Version 1.1.1 (July 4 2014)
- Fix crash in close_holes() with nD images (for n > 2)
1.1.0 (February 12 2014)
- Better error checking
- Fix interpolation of integer images using order 1
- Add resize_to & resize_rgb_to
- Add coveralls coverage
- Fix SLIC superpixels connectivity
- Add remove_regions_where function
- Fix hard crash in convolution
- Fix axis handling in convolve1d
- Add normalization to moments calculation
See the ChangeLog for older version.
License
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Hashes for mahotas-1.4.12-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a161536df39e34e09ee8e59ea5ce41d01c05536eb00b8f750f8a18db7213010b |
|
MD5 | 1a44ab2917025d3920fc4008ea6e42a8 |
|
BLAKE2b-256 | c1486ef575210017c62ed011462d7c00745fca744746f9fb8e7e48a23a795b6f |
Hashes for mahotas-1.4.12-cp310-cp310-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7ead121722f8e0d96e80e24ac96f124cd8e283ad54b3c59990e478f6008e7876 |
|
MD5 | bda2cc8fe865dcbebc073db09c989da9 |
|
BLAKE2b-256 | 5b26dd93d08b474991786c4eb96597b0415fac05d811c696321029f2a6995cc1 |
Hashes for mahotas-1.4.12-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d3d5b1bd84397129c71d902e034459624e27e9a01d1f77a588c1ba58c42bc2fe |
|
MD5 | 42306844fa5fc4ec7d1722b65b3132c7 |
|
BLAKE2b-256 | de7839f2cae7781d45903851baa593a622b07d62b4c0a36b7858a53e2f569ee2 |
Hashes for mahotas-1.4.12-cp39-cp39-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 97dca64d5b3af6b99923d5825820ba89e427c883392b20f4bd0a053705d1867f |
|
MD5 | 54f7ae9d035c770d6bf4278e6e927b74 |
|
BLAKE2b-256 | 10bf1cffb56cf4ec25f842a6837cfac299b8f8bf9eb97ac667a9f1a4aa70be5b |
Hashes for mahotas-1.4.12-cp39-cp39-manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a2b8f544fe0f39f7e930a641fc618f387e519d3840a9d0a990b1da418b16cdb4 |
|
MD5 | e20980139fb95623a97b09235e0ae101 |
|
BLAKE2b-256 | 65027b3724a3e9fa29df0248f418a2c4964a0d2eceea7a01ee6f2c3f18a9a796 |
Hashes for mahotas-1.4.12-cp39-cp39-macosx_10_14_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bc06f2f332ce4f85be215b77948a1125a4473a38cadf82e9e6477f067f98a9c5 |
|
MD5 | 600538f599cfd9de642d8932e3740bc7 |
|
BLAKE2b-256 | 6fb49285e2b2474037253a56d559061b3fc421fd6c9a46def28d51375b93e149 |
Hashes for mahotas-1.4.12-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c522edcc8cba7b54bded3ebb366b460593449c9977f62dccd90e36b90b81d38c |
|
MD5 | e67500c9d8eea03c42b01618eb4a60f9 |
|
BLAKE2b-256 | 2eb099e329171a11ad3c505c6dac1ed10fd90b4b2bab0a5addbe6e6b519befae |
Hashes for mahotas-1.4.12-cp38-cp38-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 84ce648063e979a86c484c40dabb27488d3866b85937603fb467ef7a19b3216c |
|
MD5 | c2d27904efbc7c469c5016d259579edd |
|
BLAKE2b-256 | 971ef0af3e4980842add0884391ab72dce3db72dada1bb93339f54850ad13823 |
Hashes for mahotas-1.4.12-cp38-cp38-manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e0a8d8c718c6526d389766a8321422300c26217763309ab6297a28fd09c5afcd |
|
MD5 | 0607abb2704125d21092c2929562dbdc |
|
BLAKE2b-256 | 4347976618eac531b4b3e716b75c3317ba04aa3ec9cc48c8bc7c916509b6f0fe |
Hashes for mahotas-1.4.12-cp38-cp38-macosx_10_14_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 04db7b823cc7a9487f9b092b9417ae390215165089630809453787d93e87f5c3 |
|
MD5 | 6dc26783e5c3b76de0e3ad68387cc62f |
|
BLAKE2b-256 | 245d759ea02102ebc73576ee91298866f4544debbb524e46762071ea60e10536 |
Hashes for mahotas-1.4.12-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | aead8b7e77e8a163140c48b0b55551862244f17a8320efbc9d7261dff1c49c26 |
|
MD5 | b1e42f2d7016dfa75b783da4adac9804 |
|
BLAKE2b-256 | d0fb045bdbe8f52b77dc135b15494231bd214b72c8dcf463064ae069d46d16b5 |
Hashes for mahotas-1.4.12-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 73d99c4bbb49019c4f0d1616338577556614de438a8ddcf3b2f8a4b9bfd875ce |
|
MD5 | 41a863c37e439f9a8d24fcde882da473 |
|
BLAKE2b-256 | ca5b2663d8849fe56c8d0aa1a18818aad811ed9e708c8064b7ce902d7f54a770 |
Hashes for mahotas-1.4.12-cp37-cp37m-manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1d1b30647182a9d9c1c251567bc737dfcc90882fe19d876c5e2f99a2a9ea8b37 |
|
MD5 | eed8b913779a504368e9842f11bf0c80 |
|
BLAKE2b-256 | e55072114315546080d064501e6b05f93f05f1924d040dc69c2e579ea5eed28e |
Hashes for mahotas-1.4.12-cp37-cp37m-macosx_10_14_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 800521f757c022d2c07933186670983505106e345486245d8e6d20ae3283a437 |
|
MD5 | 6fb9141fa617695e5b90d1f5191555ae |
|
BLAKE2b-256 | ce34fabaeee60ef8e35af18752a6a188a44a3cf368c7b3ce53cac76996aec773 |
Hashes for mahotas-1.4.12-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 155b0add78da5524dfb87960374dc34231f010cebeeb2cc846be5a14135486da |
|
MD5 | 61ba425fda96212c0efd5ee564fed2f3 |
|
BLAKE2b-256 | 3bae1f1896183bee221d34efb445eb8de36104d80a99dbd59b5aef97c851bb21 |
Hashes for mahotas-1.4.12-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cd978e108ac78a87a5048fcb6a617f4b1d78f89f584c17dfa1497a500a064ad0 |
|
MD5 | 6c68c69ba1a0c4daa08ea52ead4d6899 |
|
BLAKE2b-256 | 9576ecebd274459d3f3119ee08b3cb0dce534a9c918934eace2f4844a6128b50 |
Hashes for mahotas-1.4.12-cp36-cp36m-manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 48da2b1299e700f498e7712bde8b98ac2cbf3ae181bb396431d98714e0900f68 |
|
MD5 | f61853ccb92e0db1cefcda0f7d5dcf54 |
|
BLAKE2b-256 | 5c7e0e9b6ad9bab9fb721c9c06797d7829bcc84940b5d71d7f788d82fb9ac17f |
Hashes for mahotas-1.4.12-cp36-cp36m-macosx_10_14_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 198e84f838218ed1ce9eca3d7ead935acf25d7257e35b088d11a52e44a41a2fc |
|
MD5 | 7dfe332778ef5857684f5c195b5e05d5 |
|
BLAKE2b-256 | 8737c7112232f4a3f34b1c52c4f3fbb755c2c094e4769f00afbba9b1c1f0f778 |