Coder Social home page Coder Social logo

mahotas's Introduction

Mahotas

Python Computer Vision Library

Mahotas is a library of fast computer vision algorithms (all implemented in C++ for speed) operating over numpy arrays.

GH Actions Status Coverage Status License Downloads Install with Conda Install with Anaconda

Python versions 2.7, 3.4+, are supported.

Notable algorithms:

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 = {https://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 (https://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.15 (Mar 24 2024)

  • Update build system (thanks to @Czaki, see #147)

Version 1.4.14 (Mar 24 2024)

  • Fix code for C++17 (issue #146)

Version 1.4.13 (Jun 28 2022)

  • Fix freeimage testing (and make freeimage loading more robust, see #129)
  • Add GIL fixed (which triggered crashes in newer NumPy versions)

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)

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 and border 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

FOSSA Status

mahotas's People

Contributors

adamchainz avatar cgohlke avatar czaki avatar databaaz avatar fhs avatar fossabot avatar gitter-badger avatar glemaitre avatar hapemask avatar hsiaoyi0504 avatar jakirkham avatar jboy avatar langner avatar lstolcman avatar luispedro avatar meawoppl avatar michaelaye avatar mindw avatar nathanhillyer avatar odidev avatar sdsk avatar stefanv avatar stromnov avatar timgates42 avatar wang1211 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mahotas's Issues

[Inquery] Change distance in Haralick features

Hi,

I am currently working with Haralick features and wanted to have a discussion about that.
Sometimes, it could be handy to play with a distance parameter when computing the co-occurence instead of using the default value (1 px).

I was checking what could be the best way to modify the source and thought that it could be easier to discuss here. I see two possibilities:

  • Modifying the distance for the variable _2d_deltas and _3d_deltas with an initialisation. However, I do not have a clear idea of the consequences (I did not go into detail in the C file which allow to compute the GLCM)
  • Resample the input image. But again, I am not really sure of the consistency.

Cheers,

Guillaume Lemaitre

cwatershed output dtype should be the dtype of `markers`, not `surface`

Currently, the output dtype of cwatershed is the same as the dtype of the surface argument (I think this happens in the declaration of res_a in py_cwatershed), which creates a wraparound issue if e.g. there are more than 255 markers but surface is of dtype uint8 (which is actually the case in the examples given in the doc).
I think that a quick fix would be to just use the dtype of the markers argument instead.

TypeError: mahotas.otsu: This function only accepts integer types (passed array of type float32)

When running the example code

import numpy as np
import mahotas
import pylab

img = mahotas.imread('test.jpeg')
T_otsu = mahotas.thresholding.otsu(img)
seeds,_ = mahotas.label(img > T_otsu)
labeled = mahotas.cwatershed(img.max() - img, seeds)

pylab.imshow(labeled)

This error is returned

Traceback (most recent call last):
  File "ex.py", line 6, in <module>
    T_otsu = mahotas.thresholding.otsu(img)
  File "/mahotas-1.1.0-py2.7-macosx-10.9-intel.egg/mahotas/thresholding.py", line 95, in otsu
    _verify_is_integer_type(img, 'otsu')
  File "/mahotas-1.1.0-py2.7-macosx-10.9-intel.egg/mahotas/internal.py", line 140, in _verify_is_integer_type
    raise TypeError('mahotas.%s: This function only accepts integer types (passed array of type %s)' % (function_name, A.dtype))
TypeError: mahotas.otsu: This function only accepts integer types (passed array of type float32)

Any ideas?

Setting boundary effects for erosion and dilation

It appears the convention for regions beyond the boundary to be zero when working with erosion and dilation. However, I often like to chose a different constant, namely one on binary images, so as not to completely lose objects on the borders with common structuring elements. Is there some way to do this with mahotas? I didn't see anything obvious from the documentation, but it doesn't mean I didn't missing something.

Could regmax also work on float arrays?

All's in the title... regmax is currently generated using SAFE_SWITCH_ON_INTEGER_TYPES_OF and checks for integer-ness of the input; is there any specific reason why it doesn't handle float types?

By the way, the docstring of regmax doesn't mention this limitation.

Mahotas Installation

  1. Windows 8, Python 3.5.2, mingw

in the file cygwinccompiler.py in Python35-32\Lib\distutils change the function get_msvcr() with the below code

def get_msvcr():
    """Include the appropriate MSVC runtime library if Python was built
    with MSVC 7.0 or later.
    """
    msc_pos = sys.version.find('MSC v.')
    if msc_pos != -1:
        msc_ver = sys.version[msc_pos+6:msc_pos+10]
        if msc_ver == '1300':
            # MSVC 7.0
            return ['msvcr70']
        elif msc_ver == '1310':
            # MSVC 7.1
            return ['msvcr71']
        elif msc_ver == '1400':
            # VS2005 / MSVC 8.0
            return ['msvcr80']
        elif msc_ver == '1500':
            # VS2008 / MSVC 9.0
            return ['msvcr90']
        elif msc_ver == '1600':
            # VS2010 / MSVC 10.0
            return ['msvcr100']
        elif msc_ver == '1700':
            # Visual Studio 2012 / Visual C++ 11.0
            return ['msvcr110']
        elif msc_ver == '1800':
            # Visual Studio 2012 / Visual C++ 12.0
            return ['msvcr120']
        elif msc_ver == '1900':
            # Visual Studio 2015 / Visual C++ 14.0
            # "msvcr140.dll no longer exists" http://blogs.msdn.com/b/vcblog/archive/2014/06/03/visual-studio-14-ctp.aspx
            return ['vcruntime140']
        else:
            raise ValueError("Unknown MS Compiler version %s " % msc_ver)

and comment out all two occurrences of get_msvcr(): in that same file

        else:
            # Include the appropriate MSVC runtime library if Python was built
            # with MSVC 7.0 or later.
            #self.dll_libraries = get_msvcr()
            pass

and

        #self.dll_libraries = get_msvcr()

run

python setup.py install

Something wrong with distance()

There seems to be something wrong with the distance transform in mahotas. Consider:

import numpy
from scipy import ndimage
import mahotas
a = numpy.zeros((5,5))
ndimage.distance_transform_edt(a)
array([[ 0.,  0.,  0.,  0.,  0.],
       [ 0.,  0.,  0.,  0.,  0.],
       [ 0.,  0.,  0.,  0.,  0.],
       [ 0.,  0.,  0.,  0.,  0.],
       [ 0.,  0.,  0.,  0.,  0.]])
mahotas.distance(a.astype(numpy.int8))
array([[ 1.,  1.,  1.,  1.,  1.],
       [ 0.,  0.,  0.,  0.,  0.],
       [ 0.,  0.,  0.,  0.,  0.],
       [ 0.,  0.,  0.,  0.,  0.],
       [ 0.,  0.,  0.,  0.,  0.]])

freeimage may not release memory

I try to convert a huge file of raw video data into many multipage TIFF files by using the "freeimage.write_multipage()" function of the freeimage package from the Mahotas library (Python 2.7). Unfortunately, it seems that this "very easy to use" function doesn't release memory when running the script. So, my script works fine for small input raw files (less than 1 GB) but crashes with bigger files (a 3 GB input file crashes with Win XP pro 32 - ram 3.2 GB). My goal is to convert input files up to 1.5 TB. An extract of the script below:

python_script

When I run my script, the Windows Task manager shows an increase of the used ram, output file after output file until the crash which release all the used ram :
pb-memoire-creatiff

An extract of the reported error :
erreur_freeimage

Make mahotas work on Python 2.6 to 3.3 without 2to3

Looking at the output of 2to3, the mahotas code could be made compatible with Python 2.6 to 3.3 with few changes. Most changes are xrange->range. A few import, print and raise statements need to be updated.

This patch works for me on win-amd64, Python 2.6 to 3.3. I could work on a pull request later if there is interest.

diff --git a/mahotas/__init__.py b/mahotas/__init__.py
index 09a3b8f..1315571 100644
--- a/mahotas/__init__.py
+++ b/mahotas/__init__.py
@@ -5,6 +5,9 @@ Mahotas

 A package for computer vision in Python.
 '''
+
+from __future__ import print_function
+
 try:
     from .bbox import bbox, croptobbox
     from .center_of_mass import center_of_mass
@@ -25,14 +28,14 @@ try:

     from .tests import run as test

-    from mahotas_version import __version__
+    from .mahotas_version import __version__

-    import features
-    import morph
-    import segmentation
-except ImportError, e:
+    from . import features
+    from . import morph
+    from . import segmentation
+except ImportError as e:
     import sys
-    print >>sys.stderr, '''\
+    print('''\
 Could not import submodules (exact error was: %s).

 There are many reasons for this error the most common one is that you have
@@ -41,7 +44,7 @@ installed them (using `python setup.py install`) and then proceeded to test
 mahotas **without changing the current directory**.

 Try installing and then changing to another directory before importing mahotas.
-''' % e
+''' % e, file=sys.stderr)



diff --git a/mahotas/convolve.py b/mahotas/convolve.py
index 64c2826..4c08792 100644
--- a/mahotas/convolve.py
+++ b/mahotas/convolve.py
@@ -324,7 +324,7 @@ def gaussian_filter(array, sigma, order=0, mode='reflect', cval=0., out=None, ou
     sigmas = _normalize_sequence(array, sigma, 'gaussian_filter')
     output[...] = array[...]
     noutput = None
-    for axis in xrange(array.ndim):
+    for axis in range(array.ndim):
         sigma = sigmas[axis]
         order = orders[axis]
         noutput = gaussian_filter1d(output, sigma, axis, order, mode, cval, noutput)
@@ -342,7 +342,7 @@ def _wavelet_array(f, inline, func):


 def _wavelet_center_compute(oshape, border=0, dtype=None, cval=0.0):
-    for c in xrange(1, 16+border):
+    for c in range(1, 16+border):
         nshape = 2**(np.floor(np.log2(oshape))+c)
         delta = nshape - oshape
         delta //= 2
@@ -448,7 +448,7 @@ def haar(f, preserve_energy=True, inline=False):
         f /= 2.0
     return f

-_daubechies_codes = [('D%s' % ci) for ci in xrange(2,21,2)]
+_daubechies_codes = [('D%s' % ci) for ci in range(2,21,2)]
 def daubechies(f, code, inline=False):
     '''
     filtered = daubechies(f, code, inline=False)
diff --git a/mahotas/features/surf.py b/mahotas/features/surf.py
index c195a31..cf1b782 100644
--- a/mahotas/features/surf.py
+++ b/mahotas/features/surf.py
@@ -3,6 +3,7 @@
 #
 # License: MIT (see COPYING file)

+
 from __future__ import division
 import numpy as np
 from . import _surf
@@ -217,7 +218,9 @@ def show_surf(f, spoints, values=None, colors=None):
         x0 = int(x) - size//2
         x1 = x + size
         y1 = y + size
-        def rotate_around((p0,p1),(c0,c1), a):
+        def rotate_around(p, c, a):
+            (p0, p1) = p
+            (c0, c1) = c
             d0 = p0-c0
             d1 = p1 - c1
             d0,d1 = rotate(d0,d1,a)
diff --git a/mahotas/features/texture.py b/mahotas/features/texture.py
index 8f9ea11..448c06a 100644
--- a/mahotas/features/texture.py
+++ b/mahotas/features/texture.py
@@ -76,7 +76,7 @@ def haralick(f, ignore_zeros=False, preserve_haralick_bug=False, compute_14th_fe
     px_plus_y = np.empty(2*fm1, np.double)
     px_minus_y = np.empty(fm1, np.double)

-    for dir in xrange(nr_dirs):
+    for dir in range(nr_dirs):
         cooccurence(f, dir, cmat, symmetric=True)
         if ignore_zeros:
             cmat[0] = 0
@@ -222,7 +222,7 @@ def cooccurence(f, direction, output=None, symmetric=True):
     if len(f.shape) == 2:
         assert direction in (0,1,2,3), 'mahotas.texture.cooccurence: `direction` %s is not in range(4).' % direction
     elif len(f.shape) == 3:
-        assert direction in xrange(13), 'mahotas.texture.cooccurence: `direction` %s is not in range(13).' % direction
+        assert direction in range(13), 'mahotas.texture.cooccurence: `direction` %s is not in range(13).' % direction
     else:
         raise ValueError('mahotas.texture.cooccurence: cannot handle images of %s dimensions.' % len(f.shape))

diff --git a/mahotas/features/zernike.py b/mahotas/features/zernike.py
index 41825f4..9ce8888 100644
--- a/mahotas/features/zernike.py
+++ b/mahotas/features/zernike.py
@@ -83,11 +83,11 @@ def zernike_moments(im, radius, degree=8, cm=None):
     An.real = (Xn/Dn)
     An.imag = (Yn/Dn)

-    Ans = [An**p for p in xrange(2,degree+2)]
+    Ans = [An**p for p in range(2,degree+2)]
     Ans.insert(0, An) # An**1
     Ans.insert(0, np.ones_like(An)) # An**0
-    for n in xrange(degree+1):
-        for l in xrange(n+1):
+    for n in range(degree+1):
+        for l in range(n+1):
             if (n-l)%2 == 0:
                 z = _zernike.znl(Dn, Ans[l], frac_center, n, l)
                 zvalues.append(abs(z))
diff --git a/mahotas/io/__init__.py b/mahotas/io/__init__.py
index 3f0e640..ae2946a 100644
--- a/mahotas/io/__init__.py
+++ b/mahotas/io/__init__.py
@@ -33,7 +33,7 @@ try:
         from imread import imread, imsave
     except:
         from .freeimage import imread, imsave
-except OSError, e:
+except OSError as e:
     _error_message %= e
     imread = error_imread
     imsave = error_imsave
diff --git a/mahotas/labeled.py b/mahotas/labeled.py
index 6c66e7f..a45bc92 100644
--- a/mahotas/labeled.py
+++ b/mahotas/labeled.py
@@ -3,6 +3,7 @@
 # 
 # LICENSE: MIT

+
 from __future__ import division
 import numpy as np
 from .morph import get_structuring_elem
@@ -71,8 +72,8 @@ def remove_bordering(im, rsize=1, out=None, output=None):
         Subset of ``labeled``
     '''
     invalid = set()
-    index = [slice(None,None,None) for _ in xrange(im.ndim)]
-    for dim in xrange(im.ndim):
+    index = [slice(None,None,None) for _ in range(im.ndim)]
+    for dim in range(im.ndim):
         for bordering in (
                     slice(rsize),
                     slice(-rsize, None)
diff --git a/mahotas/morph.py b/mahotas/morph.py
index e9c73ce..4dff545 100644
--- a/mahotas/morph.py
+++ b/mahotas/morph.py
@@ -85,7 +85,7 @@ def get_structuring_elem(A,Bc):
     Bc = np.zeros((3,)*len(A.shape), dtype=A.dtype)
     centre = np.ones(len(A.shape))
     # This is pretty slow, but this should be a tiny array, so who cares
-    for i in xrange(Bc.size):
+    for i in range(Bc.size):
         pos = np.unravel_index(i, Bc.shape)
         pos -= centre
         if np.sum(np.abs(pos)) <= max1:
diff --git a/mahotas/polygon.py b/mahotas/polygon.py
index b44b6d5..4eef063 100644
--- a/mahotas/polygon.py
+++ b/mahotas/polygon.py
@@ -51,7 +51,7 @@ def line(p0, p1, canvas, color=1):
     error = dx/2.
     y = y0
     ystep = (+1 if y0 < y1 else -1)
-    for x in xrange(x0,x1+1):
+    for x in range(x0,x1+1):
         if steep:
             canvas[x,y] = color
         else:
@@ -83,7 +83,7 @@ def fill_polygon(polygon, canvas, color=1):
     min_y = min(y for y,x in polygon)
     max_y = max(y for y,x in polygon)
     polygon = [(float(y),float(x)) for y,x in polygon]
-    for y in xrange(min_y, max_y+1):
+    for y in range(min_y, max_y+1):
         nodes = []
         j = -1
         for i,p in enumerate(polygon):
diff --git a/mahotas/tests/test_euler.py b/mahotas/tests/test_euler.py
index d9e44bb..c77581e 100644
--- a/mahotas/tests/test_euler.py
+++ b/mahotas/tests/test_euler.py
@@ -3,9 +3,9 @@ from mahotas.euler import euler, _euler_lookup4, _euler_lookup8
 from nose.tools import raises

 def test_lookup():
-    Q1 = [np.array(q, np.bool) for q in [[0,0],[1,0]], [[0,0],[0,1]], [[0,1],[0,0]], [[1,0],[0,0]] ]
+    Q1 = [np.array(q, np.bool) for q in ([[0,0],[1,0]], [[0,0],[0,1]], [[0,1],[0,0]], [[1,0],[0,0]]) ]
     Q2 =  [(~q) for q in Q1]
-    Q3 = [np.array(q, np.bool) for q in [[0,1],[1,0]], [[1,0],[0,1]] ]
+    Q3 = [np.array(q, np.bool) for q in ([[0,1],[1,0]], [[1,0],[0,1]]) ]

     def _value(q, lookup):
         q = q.ravel()
diff --git a/mahotas/thresholding.py b/mahotas/thresholding.py
index ae26137..bd7c5de 100644
--- a/mahotas/thresholding.py
+++ b/mahotas/thresholding.py
@@ -75,7 +75,7 @@ def otsu(img, ignore_zeros=False):
     best = nB[0]*nO[0]*(mu_B-mu_O)*(mu_B-mu_O)
     bestT = 0

-    for T in xrange(1, Ng):
+    for T in range(1, Ng):
         if nB[T] == 0: continue
         if nO[T] == 0: break
         mu_B = (mu_B*nB[T-1] + T*hist[T]) / nB[T]

Maximum radius for Zernike moments

Could you be more specific about the radius I should use for the computing Zernike moments? The documentation describes this argument as the "maximum radius for the Zernike polynomials, in pixels."

Should it be the radius of the shape's minimum enclosing circle?

pydoc mahotas.regmax (locmax, etc.) gives the wrong signature.

Something weird is going on here:

$ pydoc mahotas.regmax | head -n4
Help on function regmax in mahotas:

mahotas.regmax = regmax(f, Bc=None, out=None, output=None)
    filtered = regmax(f, Bc={3x3 cross}, out={np.empty(f.shape, bool)})

At least one of the two lines is wrong...

OS X 10.7 dependencies and dynamic libs

A few discoveries from trying to get mahotas to compile on OS X 10.7:

  1. It would be great if the README.osx file were updated to tell users to install from source the FreeImage package
  2. the Makefile.osx contains PPC packages that can't be compiled on 10.7. If I pull out all references it is OK.
  3. the FreeImage dynamic library that is installed is called "dylib" or similar, but the numpy dynamic package loader requires a .so extension for mahotas.freeimage to work. By creating a symlink I could get it working.

Import Warning

I installed mahotas by cloning the GitHub repo and then running setup.py build and setup.py install for Python 2.6 on Ubuntu 11.04. When I go to import mahatos I get the following warning:

>>> import mahotas
/usr/local/lib/python2.6/dist-packages/mahotas-0.8.1-py2.6-linux-x86_64.egg/mahotas/moments.py:6: DeprecationWarning: Use

from mahotas.features import moments

  ''', DeprecationWarning)
'''

overlay() doesn't return expected result

Following this tutorial I tried the overlay() function on one of my images (DAPI stain):

import mahotas as mh
import numpy as np
from matplotlib import pyplot as plt  # also tried: import pylab as plt

filename = ''  # some image file
img = mh.imread(filename)

thresh = mh.otsu(img.astype(np.uint))
img_bin = img > thresh

img_over = mh.overlay(img, red=img_bin)

plt.imshow(img_over)
plt.show()

This results in a gray image without any coloring.

(img_over[:,:,0] == img_over[:,:,1]).all()

returns True

I'm using mahotas version 1.4 and matplotlib version 1.4.3 and python 2.7

Feature Request: Support for Numba.

This is just a feature request but could add very fast speed ups to mahotas given it is all numpy based. It isn't a drop in replacement but can add tons of speed ups to mahotas. For example running sum on my machine gives the output:

Result from python is 115.765683493 in 4.09197807312 (msec)
Result from compiled is 115.765683493 in 0.028133392334 (msec)
Speed up is 145.449152542

More info at:
https://github.com/numba/numba

pip install gives error -> Command "python setup.py egg_info" failed with error code 1

I did a fresh install on my computer and I'm getting setup for CV again. When I use pip to install, I am getting the error below. I am newer to python, so apologies if it is something obvious but help would be greatly appreciated!

pip install mahotas
Collecting mahotas
Using cached mahotas-1.4.2.tar.gz
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "", line 1, in
…/mahotas/setup.py", line 50, in
long_description = open('README.md').read()
IOError: [Errno 2] No such file or directory: 'README.md'

----------------------------------------

Command "python setup.py egg_info" failed with error code 1

mh.labeled.bbox strange behavior

I encounter the following strange behavior where mh.labeled.bbox is all zeros:

aaa = array([[[2256,  402,  402],
        [2256,  402,  402],
        [2256,  402,  402]],

       [[2256,  402,  402],
        [2256,  402,  402],
        [2256,  402,  402]],

       [[2256,  402,  402],
        [2256,  402,  402],
        [2256,  402,  402]]], dtype=uint32)

mh.labeled.bbox(aaa)
array([[0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0],
       ..., 
       [0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0]])

mh.labeled.bbox(aaa).shape
(2257, 6)

mh.bbox(aaa==2256) # but this works
array([0, 3, 0, 3, 0, 1])

Erode/DIlate invent pixel values

Hi,

I greatly appreciate your software! It is very well thought out and extremely useful.

Besides of that, I'm pretty sure I have found a bug in erode/dilate. I have attached the TEST.PNG plus the python test file below.

As I understand erosion/dilation, it is the min or max of the local neighbourhood. So it should not produce new pixel values which are not contained in the original image, right?

See attached python file with image. I also cross checked with the scpiy ndimage version, which does not produce the problem.

Regards,
Clemens Steckner
test

import mahotas
im= mahotas.imread('test.png')

find list of all values of pixels gt 0

def pixelvalues(imi):
im=imi.copy()
lst=[]
mn=im.min()
while True:
val= im.max()
assert (im==val).any()
if val == mn:
break
lst.append(val)
im[im==val] = mn
assert (im==mn).all()
lst.append(mn)
return [i for i in lst if i > 0]

show pixelvalues which have been 'invented' by mahotas

print set(pixelvalues(mahotas.erode(im))) - set(pixelvalues(im))
print set(pixelvalues(mahotas.dilate(im))) - set(pixelvalues(im))

erode invents pixel value 254

print (mahotas.erode(im) == 254).any(), (im==254).any()

dilate invents pixel value 103

print (mahotas.dilate(im) == 103).any(), (im==103).any()

haralick error using python3.4 munmap_chunk(): invalid pointer: 0x0000000001fb37f0

I'm getting the following error when I'm trying to extract haralick features from an envi image:

def calculate(self, image, region, training=False):


        # Read out subregion and convert it to a float and normalize

        print(region.astype('int'))

        img = image.read_subregion(*region.astype('int32'), use_memmap=False).astype(np.dtype('float'))/(2**16 - 1)


        # Calculate principle component analysis and reduce to the top 5 eigenvalues
        pc = PCA(img).reduce(num=5)

        # Transform original data based on PCA analysis and dimensional reduction
        pc_img = pc.transform(img)

        # Scale up to 64 grey levels and convert back to integer type
        pc_img = np.transpose((pc_img*64).astype(np.dtype('int8')))

        # Preallocate texture feature array
        texture = np.zeros((4, 13), dtype=np.float)

        # Calculate Haralick texture features and add them to the array
        for band in pc_img:
            texture += haralick(band)

The error message:
*** Error inpython': munmap_chunk(): invalid pointer: 0x00000000017a0930 *** Aborted (core dumped)`

My environment is:

Ubuntu 15.10 (64bit)
Python 3.4.3+
Cython-0.23.5-py3.4
mahotas-1.4.1-py3.4
numpy-1.11.0-py3.4

Improving _check_array_labeled

The error message of _check_array_labeled could be improved to indicate the missing property (being of intc type, or having the carray flag), as it is a bit cryptic right now. In fact, all functions in labeled could perhaps just use np.require instead of requiring the carray flag?

Hough transform feature request

I've used mahotas for detecting/labeling objects, and now need to add a Hough transform element to it. I'll probably use OpenCV for now, but to reduce dependencies I'd like to stick with only mahotas. I saw that Hough transforms were on the possible features list, and just wanted to make an issue to formally express interest in that.

Please close this issue if Hough transforms are no longer a planned feature, or if the issue queue isn't the right place to request this!

regmax memory leak

I ran regmax on a 600x600x600 bool array and once it started, the memory usage slowly increased passed the amount of physical memory that I have (32GB). I realized that I needed to specify a new structuring element for 3D, but even now regmax is using 10GB on a file that is smaller than 1GB. Any ideas as to why this is?

For the original problem, maybe you could just add

assert Bc.ndim == f.ndim

into your code

draw_polygon does not fill in a square as I would expect

If I call draw_polygon with a square, it leaves the top row unfilled. Here is a small example:

>>> offset_simplex = numpy.array([[0, 4], [4, 4], [4, 0], [0, 0]])
>>> canvas = numpy.zeros((5, 5))
>>> mahotas.polygon.fill_polygon(offset_simplex, canvas)
>>> print canvas
[[ 0.  0.  0.  0.  0.]
 [ 1.  1.  1.  1.  1.]
 [ 1.  1.  1.  1.  1.]
 [ 1.  1.  1.  1.  1.]
 [ 1.  1.  1.  1.  1.]]

I would expect the top row to be filled. Certainly one cannot fix this by setting the coordinates to -1, as then nothing gets drawn.

Thanks!

wavelet_center not padding enough

I'm not sure if the daubechies transforms are working correctly. I was under the impression that while there are issues for images of size not corresponding to a power of 2, the wavelet_center function serves to pad zeros to reach a power of 2. It is also my understanding that performing a transform / inversion with no operations in between should yield (near) perfect reconstruction of the image. I was not experiencing this apart from the example with luispedro image.

So I decided to run some tests by creating random images of size 1, ..., 512 and testing the transform/inversion for each daubechies type. I used a pixel-wise mean absolute difference for each image size and wavelet type to measure the reconstruction performance. In particular, I ran the following short bit of code:

import mahotas as mh
from pylab import *

stats = zeros((512,10))

for d in range(1,11):
    for n in range(1,513):
        R = rand(n,n)
        RC = mh.wavelet_center( R )
        RD = mh.daubechies( RC, 'D%d'%(d*2) )
        RI = mh.idaubechies( RD, 'D%d'%(d*2) )
        RR = mh.wavelet_decenter( RI, R.shape )
        stats[n-1,d-1] = mean( abs(R-RR) )
        del R, RD, RI, RC, RR

Plotting stats is telling:

wave-check-1

So what's going on here? I fiddled with the wavelet_center and determined that it "rounds" only to the next highest power of 2. So things like 509, 510, 511 go to 512.

Now so if I run something like (where R is a random 510 x 510 matrix):

mean(abs(mh.idaubechies( mh.daubechies( \  # pad it to 1024 x 1024
pad(R,257,'constant'), 'D20' ), 'D20' )[257:-257,257:-257] - R )
=> 2.2080071071141185e-08

whereas:

mean(abs(R - mh.wavelet_decenter(mh.idaubechies( \
mh.daubechies(mh.wavelet_center(R), 'D20'),'D20'),R.shape)))
=> 0.027407519375604338

So it looks like the wavelet_center function should pad relative to the current image size, not just round up. I'm not sure about odd size either.

For sanity, I ran the same earlier test with pywt wavelets library (which was MUCH slower being pure python). This yielded satisfactory reconstruction error across the boards (notice the scaling factor on the y-axis):

wave-check-pywt

mahotas.tests.test_interpolate.test_shift_ratio fails on win32-py2.7

FAIL: mahotas.tests.test_interpolate.test_shift_ratio
----------------------------------------------------------------------
Traceback (most recent call last):
  File "X:\Python27\lib\site-packages\nose\case.py", line 197, in runTest
    self.test(*self.arg)
  File "X:\Python27\lib\site-packages\mahotas\tests\test_interpolate.py", line 37, in test_shift_ratio
    assert np.abs(ratio - 1.) < .01
AssertionError

Strangely, this fails on win32-py2.7 only, not win32-py2.6, win-amd64-py2.7 or any other platform I tested, event though they use the same compiler and compiler settings.

A reduced example that fails is:

f = np.zeros((3,3))
f[1,1] = 128
output = interpolate.shift(f,(1,1))

On win32-py2.7 the output is

[[ -7.78937000e+05  -7.78937000e+05  -7.78937000e+05]
 [ -7.78937000e+05   0.00000000e+00  -7.99360578e-15]
 [ -7.78937000e+05  -8.88178420e-15   1.28000000e+02]]

(note the -7.78937000e+05 on the borders) while on other platforms output is close to the expected result:

 [[  1.48200610e-307   1.48200610e-307   1.48200610e-307]
 [  1.48200610e-307   0.00000000e+000  -7.99360578e-015]
 [  1.48200610e-307  -8.88178420e-015   1.28000000e+002]]

Novice mahotas user: unknown error

Hi,

I'm new to python and mahotas, I downloaded and installed the program. However, when running the samples in mahotas docs, I encountered errors, and tried to run the test and here is the results:

In [14]: mahotas.test()

...................................................................................-------------------------------------

RuntimeError Traceback (most recent call last)
C:\Pyx\lib\site-packages\mahotas_ctypes\callbacks.c in 'calling callback function'()

C:\Pyx\lib\site-packages\mahotas\io\freeimage.py in _error_handler(fif, message)
222 @_functype(None, ctypes.c_int, ctypes.c_char_p)
223 def _error_handler(fif, message):
--> 224 raise RuntimeError('mahotas.freeimage: FreeImage error: %s' % message)
225
226 _FI.FreeImage_SetOutputMessage(_error_handler)

RuntimeError: mahotas.freeimage: FreeImage error: FreeImage_Save: failed to open file /tmp/mahotas_test.png
E---------------------------------------------------------------------------
RuntimeError Traceback (most recent call last)
C:\Pyx\lib\site-packages\mahotas_ctypes\callbacks.c in 'calling callback function'()

C:\Pyx\lib\site-packages\mahotas\io\freeimage.py in _error_handler(fif, message)
222 @_functype(None, ctypes.c_int, ctypes.c_char_p)
223 def _error_handler(fif, message):
--> 224 raise RuntimeError('mahotas.freeimage: FreeImage error: %s' % message)
225
226 _FI.FreeImage_SetOutputMessage(_error_handler)

RuntimeError: mahotas.freeimage: FreeImage error: FreeImage_Save: failed to open file /tmp/mahotas_test.png
E.---------------------------------------------------------------------------
RuntimeError Traceback (most recent call last)
C:\Pyx\lib\site-packages\mahotas_ctypes\callbacks.c in 'calling callback function'()

C:\Pyx\lib\site-packages\mahotas\io\freeimage.py in _error_handler(fif, message)
222 @_functype(None, ctypes.c_int, ctypes.c_char_p)
223 def _error_handler(fif, message):
--> 224 raise RuntimeError('mahotas.freeimage: FreeImage error: %s' % message)
225
226 _FI.FreeImage_SetOutputMessage(_error_handler)

RuntimeError: mahotas.freeimage: FreeImage error: FreeImage_Save: failed to open file /tmp/mahotas_test.png
E..---------------------------------------------------------------------------
RuntimeError Traceback (most recent call last)
C:\Pyx\lib\site-packages\mahotas_ctypes\callbacks.c in 'calling callback function'()

C:\Pyx\lib\site-packages\mahotas\io\freeimage.py in _error_handler(fif, message)
222 @_functype(None, ctypes.c_int, ctypes.c_char_p)
223 def _error_handler(fif, message):
--> 224 raise RuntimeError('mahotas.freeimage: FreeImage error: %s' % message)
225
226 _FI.FreeImage_SetOutputMessage(_error_handler)

RuntimeError: mahotas.freeimage: FreeImage error: Failed to open /tmp/mahotas_test.fispool, No such file or directory
E---------------------------------------------------------------------------
RuntimeError Traceback (most recent call last)
C:\Pyx\lib\site-packages\mahotas_ctypes\callbacks.c in 'calling callback function'()

C:\Pyx\lib\site-packages\mahotas\io\freeimage.py in _error_handler(fif, message)
222 @_functype(None, ctypes.c_int, ctypes.c_char_p)
223 def _error_handler(fif, message):
--> 224 raise RuntimeError('mahotas.freeimage: FreeImage error: %s' % message)
225
226 _FI.FreeImage_SetOutputMessage(_error_handler)

RuntimeError: mahotas.freeimage: FreeImage error: FreeImage_Save: failed to open file /tmp/mahotas_test.png
E...................................................................F...................................................

...................................................................................E..........

ERROR: mahotas.tests.test_freeimage.test_freeimage

Traceback (most recent call last):
File "C:\Pyx\lib\site-packages\nose\case.py", line 197, in runTest
self.test(*self.arg)
File "C:\Pyx\lib\site-packages\mahotas\tests\test_freeimage.py", line 25, in test_freeimage
freeimage.imsave(_testimgname, img)
File "C:\Pyx\lib\site-packages\mahotas\io\freeimage.py", line 798, in imsave
write(img, filename)
File "C:\Pyx\lib\site-packages\mahotas\io\freeimage.py", line 597, in write
res = _FI.FreeImage_Save(ftype, bitmap, filename, flags)
WindowsError: exception: priviledged instruction

ERROR: mahotas.tests.test_freeimage.test_as_grey

Traceback (most recent call last):
File "C:\Pyx\lib\site-packages\nose\case.py", line 197, in runTest
self.test(*self.arg)
File "C:\Pyx\lib\site-packages\mahotas\tests\test_freeimage.py", line 34, in test_as_grey
freeimage.imsave(_testimgname, colour.astype(np.uint8))
File "C:\Pyx\lib\site-packages\mahotas\io\freeimage.py", line 798, in imsave
write(img, filename)
File "C:\Pyx\lib\site-packages\mahotas\io\freeimage.py", line 597, in write
res = _FI.FreeImage_Save(ftype, bitmap, filename, flags)
WindowsError: exception: priviledged instruction

ERROR: mahotas.tests.test_freeimage.test_save_load_rgba

Traceback (most recent call last):
File "C:\Pyx\lib\site-packages\nose\case.py", line 197, in runTest
self.test(*self.arg)
File "C:\Pyx\lib\site-packages\mahotas\tests\test_freeimage.py", line 51, in test_save_load_rgba
freeimage.imsave(_testimgname, img)
File "C:\Pyx\lib\site-packages\mahotas\io\freeimage.py", line 798, in imsave
write(img, filename)
File "C:\Pyx\lib\site-packages\mahotas\io\freeimage.py", line 597, in write
res = _FI.FreeImage_Save(ftype, bitmap, filename, flags)
WindowsError: exception: priviledged instruction

ERROR: mahotas.tests.test_freeimage.test_multi

Traceback (most recent call last):
File "C:\Pyx\lib\site-packages\nose\case.py", line 197, in runTest
self.test(*self.arg)
File "C:\Pyx\lib\site-packages\mahotas\tests\test_freeimage.py", line 83, in test_multi
freeimage.write_multipage(fs, _testtif)
File "C:\Pyx\lib\site-packages\mahotas\io\freeimage.py", line 630, in write_multipage
_FI.FreeImage_CloseMultiBitmap(multibitmap, flags)
WindowsError: exception: access violation reading 0x00000066

ERROR: mahotas.tests.test_freeimage.test_uint16

Traceback (most recent call last):
File "C:\Pyx\lib\site-packages\nose\case.py", line 197, in runTest
self.test(*self.arg)
File "C:\Pyx\lib\site-packages\mahotas\tests\test_freeimage.py", line 92, in test_uint16
freeimage.imsave(_testimgname, img)
File "C:\Pyx\lib\site-packages\mahotas\io\freeimage.py", line 798, in imsave
write(img, filename)
File "C:\Pyx\lib\site-packages\mahotas\io\freeimage.py", line 597, in write
res = _FI.FreeImage_Save(ftype, bitmap, filename, flags)
WindowsError: exception: priviledged instruction

ERROR: Failure: AttributeError ('module' object has no attribute 'float128')

Traceback (most recent call last):
File "C:\Pyx\lib\site-packages\nose\loader.py", line 251, in generate
for test in g():
File "C:\Pyx\lib\site-packages\mahotas\tests\test_watershed.py", line 39, in test_watershed
np.float32, np.float64, np.float128, float]:
AttributeError: 'module' object has no attribute 'float128'

FAIL: mahotas.tests.test_io.test_pil

Traceback (most recent call last):
File "C:\Pyx\lib\site-packages\nose\case.py", line 197, in runTest
self.test(_self.arg)
File "C:\Pyx\lib\site-packages\mahotas\tests\test_io.py", line 27, in execute
test(_args, **kwargs)
File "C:\Pyx\lib\site-packages\mahotas\tests\test_io.py", line 69, in test_pil
assert np.all( pil.imread(filename) == lena )
AssertionError


Ran 304 tests in 221.107s

FAILED (errors=6, failures=1)

In [15]:_

How can I send the detail debug, include related files?

Thanks

Convolution: weights with integer data type

I'm using mahotas.convolve to detect edges in an image with a Sobel filter:

f = np.array([[1, 2, 1], [0, 0, 0], [-1, -2, -1]], dtype=float)
sobel_h = mh.convolve(image.astype(float), f)
sobel_v = mh.convolve(image.astype(float), f.T)
gradient = np.abs(sobel_v) + np.abs(sobel_h)

This works fine when image and weights f are both cast to type float and gives the same results as MATLAB's imfilter:

f = fspecial('sobel');
sobel_h = imfilter(image, f);
sobel_v = imfilter(image, f');
edges = abs(sobel_h) + abs(sobel_v);

screen shot 2016-07-12 at 16 33 16

However, when using unsigned integer type (same type as image, which has type numpy.uint16!) the output is different.

f = np.array([[1, 2, 1], [0, 0, 0], [-1, -2, -1]])
sobel_h = mh.convolve(image, f)
sobel_v = mh.convolve(image, f.T)
edges = np.abs(sobel_v) + np.abs(sobel_h)

screen shot 2016-07-12 at 16 31 00

erode/dilate offset integers by -1/+1

Booleans are fine.

>>> mahotas.erode(np.array([[0,0,0,1,1,1],[0,0,0,1,1,1],[0,0,0,1,1,1],], dtype=np.bool))
array([[False, False, False, False,  True,  True],
       [False, False, False, False,  True,  True],
       [False, False, False, False,  True,  True]], dtype=bool)
>>> mahotas.dilate(np.array([[0,0,0,1,1,1],[0,0,0,1,1,1],[0,0,0,1,1,1],], dtype=np.bool))
array([[False, False,  True,  True,  True,  True],
       [False, False,  True,  True,  True,  True],
       [False, False,  True,  True,  True,  True]], dtype=bool)
>>> mahotas.dilate(np.array([[0,0,0,1,1,1],[0,0,0,1,1,1],[0,0,0,1,1,1],], dtype=np.int32))
array([[1, 1, 2, 2, 2, 2],
       [1, 1, 2, 2, 2, 2],
       [1, 1, 2, 2, 2, 2]], dtype=int32)
>>> mahotas.erode(np.array([[0,0,0,1,1,1],[0,0,0,1,1,1],[0,0,0,1,1,1],], dtype=np.int32))
array([[-1, -1, -1, -1,  0,  0],
       [-1, -1, -1, -1,  0,  0],
       [-1, -1, -1, -1,  0,  0]], dtype=int32)
>>> mahotas.__version__
'0.9.7'
>>> 

MemoryError in Haralick feature

Working with a uint16 image, I got the following error in mahotas.features.texture line 112:

---------------------------------------------------------------------------
MemoryError                               Traceback (most recent call last)
<ipython-input-6-efdb5c1eef9d> in <module>()
----> 1 np.empty((fm1, fm1), np.int32)

MemoryError: 

In this case the value of fm1 was 37531.

imresize fails

When I run this code:

def read_image_from_path( image ):
    img = mh.imread( image )
    small_img = mh.imresize( img, 256 )
    return small_img

It fails with this error message:

Python(3721,0x7fff71432310) malloc: *** mach_vm_map(size=279550831362048) failed (error code=3)
*** error: can't allocate region
*** set a breakpoint in malloc_error_break to debug

Mac OS X 10.9, Python 3.3, Mahotas 1.0.3

Does anybody know what is happening / how to fix this?
Am I just doing something wrong or does anybody else encounter this problem?

P.S.: Thank you for the awesome library!

`mahotas.polygon.fill_polygon` skips rows of pixels at all vertices on the left hand side of a polygon

As a simple example to reproduce the problem:

import numpy as np
import matplotlib.pyplot as plt
import mahotas.polygon

canvas = np.zeros((100,100))
poly = [(20,10), (35, 0), (60,20), (65, 25), (70,50), (40,60), (30,40), (20,10)]
mahotas.polygon.fill_polygon(poly, canvas)

plt.imshow(canvas, interpolation='nearest')
plt.show()

Fortunately the fix is quite simple. I'm at work and don't have git available, otherwise I'd submit a pull request, but it appears to be a single-line fix.

On line 105 of mahotas/polygon.py:
The line if p[0] <= y and pj[0] >= y or pj[0] <= y and p[0] >= y:
Should be: if p[0] < y and pj[0] >= y or pj[0] < y and p[0] >= y:

Cheers, and thanks for a very useful piece of software!

mahotas.tests.test_convolve.test_center_decenter failure on Windows

FAIL: mahotas.tests.test_convolve.test_center_decenter
----------------------------------------------------------------------
Traceback (most recent call last):
  File "X:\Python27\lib\site-packages\nose\case.py", line 197, in runTest
    self.test(*self.arg)
  File "X:\Python27\lib\site-packages\mahotas\tests\test_convolve.py", line 185, in test_center_decenter
    assert np.all(log2fc_shape == np.floor(log2fc_shape))
AssertionError

log2fc_shape is [ 5.9999999999999991 6.9999999999999991]
np.floor(log2fc_shape)) is [ 5. 6.]

Bernsen thresholding

Hi,
I recently discovered this python program to try bernsen's thresholding method. I liked the option to change gthresh value. I gave it a try and I was getting a different result from bernsen's method implemented in imagej though. After looking at the code, it appears that there may be an error on line 258: fmean = fmax/.2 + fmin/.2. I think the values should be divided by 2 not 0.2. Is it possible to check and recompile the code if it is an error? Thank you.

Not (correctly) pip installable

Hi,

you're importing numpy in setup.py. This causes automatic dependency resolution to fail and one has to manually install numpy. This conflicts with anything that is smarter than a shell script automating installation.

Would you mind making mahtos cleanly install in a fresh virtualenv when calling bin/pip install?

Error while installing using pip / pip3

  1. Ubuntu 16.04, g++ (Ubuntu 5.4.0-6ubuntu1~16.04.2) 5.4.0

Tried installing with pip install mahotas & sudo pip install mahotas. And corresponding commands for pip3 and tried the same on the package from PyPI as well. Get the following error message -

Collecting mahotas
  Downloading mahotas-1.4.2.tar.gz (1.5MB)
    100% |████████████████████████████████| 1.5MB 456kB/s 
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/tmp/pip-build-65OM5L/mahotas/setup.py", line 50, in <module>
        long_description = open('README.md').read()
    IOError: [Errno 2] No such file or directory: 'README.md'

    ----------------------------------------

UnicodeDecodeError from setup.py with Python 3.2 on Mac

I get this error on Mac 10.8:

$ python3.2 setup.py build
Traceback (most recent call last):
  File "setup.py", line 40, in <module>
    long_description = open('docs/source/readme.rst').read()
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/encodings/ascii.py", line 26, in decode
    return codecs.ascii_decode(input, self.errors)[0]
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 5169: ordinal not in range(128)

Building wheels with pip option --user or --prefix fails

When mahotas is installed with pip install mahotas --user building wheels fails with the following error on Ubuntu 16.04 with Python 2.7.12:

    x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fno-strict-aliasing -Wdate-time -D_FORTIFY_SOURCE=2 -g -fstack-protector-strong -Wformat -Werror=format-security -fPIC -DNPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION -DPY_ARRAY_UNIQUE_SYMBOL=Mahotas_PyArray_API_Symbol -I[] -I/usr/include/python2.7 -c mahotas/_histogram.cpp -o build/temp.linux-x86_64-2.7/mahotas/_histogram.o
    cc1plus: warning: command line option '-Wstrict-prototypes' is valid for C/ObjC but not for C++
    In file included from mahotas/numpypp/array.hpp:17:0,
                     from mahotas/_histogram.cpp:10:
    mahotas/numpypp/numpy.hpp:11:33: fatal error: numpy/ndarrayobject.h: No such file or directory
    compilation terminated.
    error: command 'x86_64-linux-gnu-gcc' failed with exit status 1

  ----------------------------------------
  Failed building wheel for mahotas
  Running setup.py clean for mahotas
Failed to build mahotas
Installing collected packages: numpy, mahotas
  Running setup.py install for mahotas ... done
Successfully installed mahotas-1.4.3 numpy-1.12.0

This fails:

docker run -t hackermd/ubuntu-xenial-python pip install mahotas --user

This works:

docker run -t hackermd/ubuntu-xenial-python sudo pip install mahotas

0.7 won't compile on OS X 10.7

I've just tried installing via pip and easy_install, and also from the latest git clone, but I always end up with the same set of errors (below). I went back to 0.6.6 and it works OK. I tried figuring out the cause of the problem, but without success. I have the latest XCode gcc (4.2.1) and also macports gcc (4.4.0), but both produce the same problems (below).

Cheers,

Ian

compile options: '-I/Library/Frameworks/Python.framework/Versions/7.1/lib/python2.7/site-packages/numpy/core/include -I/Library/Frameworks/Python.framework/Versions/7.1/include/python2.7 -c'
g++: mahotas/_interpolate.cpp
In file included from /usr/include/c++/4.2.1/ios:47,
from /usr/include/c++/4.2.1/ostream:45,
from /usr/include/c++/4.2.1/iterator:70,
from mahotas/numpypp/array.hpp:9,
from mahotas/_filters.h:2,
from mahotas/_interpolate.cpp:38:
/usr/include/c++/4.2.1/bits/localefwd.h:58:34: error: macro "isspace" passed 2 arguments, but takes just 1
/usr/include/c++/4.2.1/bits/localefwd.h:70:34: error: macro "isupper" passed 2 arguments, but takes just 1
/usr/include/c++/4.2.1/bits/localefwd.h:74:34: error: macro "islower" passed 2 arguments, but takes just 1
/usr/include/c++/4.2.1/bits/localefwd.h:78:34: error: macro "isalpha" passed 2 arguments, but takes just 1
/usr/include/c++/4.2.1/bits/localefwd.h:94:34: error: macro "isalnum" passed 2 arguments, but takes just 1
/usr/include/c++/4.2.1/bits/localefwd.h:102:34: error: macro "toupper" passed 2 arguments, but takes just 1
/usr/include/c++/4.2.1/bits/localefwd.h:106:34: error: macro "tolower" passed 2 arguments, but takes just 1
In file included from /usr/include/c++/4.2.1/bits/basic_ios.h:44,
from /usr/include/c++/4.2.1/ios:50,
from /usr/include/c++/4.2.1/ostream:45,
from /usr/include/c++/4.2.1/iterator:70,
from mahotas/numpypp/array.hpp:9,
from mahotas/_filters.h:2,
from mahotas/_interpolate.cpp:38:
/usr/include/c++/4.2.1/bits/locale_facets.h:245:53: error: macro "toupper" passed 2 arguments, but takes just 1
/usr/include/c++/4.2.1/bits/locale_facets.h:274:53: error: macro "tolower" passed 2 arguments, but takes just 1
/usr/include/c++/4.2.1/bits/locale_facets.h:817:53: error: macro "toupper" passed 2 arguments, but takes just 1
/usr/include/c++/4.2.1/bits/locale_facets.h:850:53: error: macro "tolower" passed 2 arguments, but takes just 1
/usr/include/c++/4.2.1/bits/locale_facets.h:4614:44: error: macro "isspace" passed 2 arguments, but takes just 1
/usr/include/c++/4.2.1/bits/locale_facets.h:4632:44: error: macro "isupper" passed 2 arguments, but takes just 1
/usr/include/c++/4.2.1/bits/locale_facets.h:4638:44: error: macro "islower" passed 2 arguments, but takes just 1
/usr/include/c++/4.2.1/bits/locale_facets.h:4644:44: error: macro "isalpha" passed 2 arguments, but takes just 1
/usr/include/c++/4.2.1/bits/locale_facets.h:4668:44: error: macro "isalnum" passed 2 arguments, but takes just 1
/usr/include/c++/4.2.1/bits/locale_facets.h:4680:44: error: macro "toupper" passed 2 arguments, but takes just 1
/usr/include/c++/4.2.1/bits/locale_facets.h:4686:44: error: macro "tolower" passed 2 arguments, but takes just 1
In file included from /usr/include/c++/4.2.1/ios:47,
from /usr/include/c++/4.2.1/ostream:45,
from /usr/include/c++/4.2.1/iterator:70,
from mahotas/numpypp/array.hpp:9,
from mahotas/_filters.h:2,
from mahotas/_interpolate.cpp:38:
/usr/include/c++/4.2.1/bits/localefwd.h:58: error: ‘std::isspace’ declared as an ‘inline’ variable
/usr/include/c++/4.2.1/bits/localefwd.h:58: error: template declaration of ‘bool std::isspace’
/usr/include/c++/4.2.1/bits/localefwd.h:70: error: ‘std::isupper’ declared as an ‘inline’ variable
/usr/include/c++/4.2.1/bits/localefwd.h:70: error: template declaration of ‘bool std::isupper’
/usr/include/c++/4.2.1/bits/localefwd.h:74: error: ‘std::islower’ declared as an ‘inline’ variable
/usr/include/c++/4.2.1/bits/localefwd.h:74: error: template declaration of ‘bool std::islower’
/usr/include/c++/4.2.1/bits/localefwd.h:78: error: ‘std::isalpha’ declared as an ‘inline’ variable
/usr/include/c++/4.2.1/bits/localefwd.h:78: error: template declaration of ‘bool std::isalpha’
/usr/include/c++/4.2.1/bits/localefwd.h:94: error: ‘std::isalnum’ declared as an ‘inline’ variable
/usr/include/c++/4.2.1/bits/localefwd.h:94: error: template declaration of ‘bool std::isalnum’
/usr/include/c++/4.2.1/bits/localefwd.h:102: error: ‘std::toupper’ declared as an ‘inline’ variable
/usr/include/c++/4.2.1/bits/localefwd.h:102: error: template declaration of ‘_CharT std::toupper’
/usr/include/c++/4.2.1/bits/localefwd.h:106: error: ‘std::tolower’ declared as an ‘inline’ variable
/usr/include/c++/4.2.1/bits/localefwd.h:106: error: template declaration of ‘_CharT std::tolower’
In file included from /usr/include/c++/4.2.1/bits/basic_ios.h:44,
from /usr/include/c++/4.2.1/ios:50,
from /usr/include/c++/4.2.1/ostream:45,
from /usr/include/c++/4.2.1/iterator:70,
from mahotas/numpypp/array.hpp:9,
from mahotas/_filters.h:2,
from mahotas/_interpolate.cpp:38:
/usr/include/c++/4.2.1/bits/locale_facets.h:230: error: ‘btowc’ is not a type
/usr/include/c++/4.2.1/bits/locale_facets.h:245: error: expected ‘;’ before ‘const’
/usr/include/c++/4.2.1/bits/locale_facets.h:258: error: expected ;' before ‘char_type’ /usr/include/c++/4.2.1/bits/locale_facets.h:259: error: ‘btowc’ is not a type /usr/include/c++/4.2.1/bits/locale_facets.h:274: error: expected ‘;’ before ‘const’ /usr/include/c++/4.2.1/bits/locale_facets.h:290: error: expected;' before ‘char_type’
/usr/include/c++/4.2.1/bits/locale_facets.h: In member function ‘_CharT std::__ctype_abstract_base<CharT>::towupper(int ()(_CharT)) const’:
/usr/include/c++/4.2.1/bits/locale_facets.h:231: error: ‘__c’ was not declared in this scope
/usr/include/c++/4.2.1/bits/locale_facets.h: In member function ‘CharT std::__ctype_abstract_base<CharT>::towlower(int ()(CharT)) const’:
/usr/include/c++/4.2.1/bits/locale_facets.h:260: error: ‘__c’ was not declared in this scope
/usr/include/c++/4.2.1/bits/locale_facets.h: At global scope:
/usr/include/c++/4.2.1/bits/locale_facets.h:800: error: ‘btowc’ is not a type
/usr/include/c++/4.2.1/bits/locale_facets.h:817: error: expected ‘;’ before ‘const’
/usr/include/c++/4.2.1/bits/locale_facets.h:832: error: expected ;' before ‘char_type’ /usr/include/c++/4.2.1/bits/locale_facets.h:833: error: ‘btowc’ is not a type /usr/include/c++/4.2.1/bits/locale_facets.h:850: error: expected ‘;’ before ‘const’ /usr/include/c++/4.2.1/bits/locale_facets.h:869: error: expected;' before ‘char_type’
/usr/include/c++/4.2.1/bits/locale_facets.h: In member function ‘char std::ctype::towupper(int (
)(char)) const’:
/usr/include/c++/4.2.1/bits/locale_facets.h:801: error: ‘__c’ was not declared in this scope
/usr/include/c++/4.2.1/bits/locale_facets.h: In member function ‘char std::ctype::towlower(int (
)(char)) const’:
/usr/include/c++/4.2.1/bits/locale_facets.h:834: error: ‘__c’ was not declared in this scope
In file included from /usr/include/c++/4.2.1/bits/basic_ios.h:44,
from /usr/include/c++/4.2.1/ios:50,
from /usr/include/c++/4.2.1/ostream:45,
from /usr/include/c++/4.2.1/iterator:70,
from mahotas/numpypp/array.hpp:9,
from mahotas/_filters.h:2,
from mahotas/_interpolate.cpp:38:
/usr/include/c++/4.2.1/bits/locale_facets.h: At global scope:
/usr/include/c++/4.2.1/bits/locale_facets.h:4614: error: function definition does not declare parameters
/usr/include/c++/4.2.1/bits/locale_facets.h:4632: error: function definition does not declare parameters
/usr/include/c++/4.2.1/bits/locale_facets.h:4638: error: function definition does not declare parameters
/usr/include/c++/4.2.1/bits/locale_facets.h:4644: error: function definition does not declare parameters
/usr/include/c++/4.2.1/bits/locale_facets.h:4668: error: function definition does not declare parameters
/usr/include/c++/4.2.1/bits/locale_facets.h:4680: error: function definition does not declare parameters
/usr/include/c++/4.2.1/bits/locale_facets.h:4686: error: function definition does not declare parameters
In file included from /usr/include/c++/4.2.1/ios:47,
from /usr/include/c++/4.2.1/ostream:45,
from /usr/include/c++/4.2.1/iterator:70,
from mahotas/numpypp/array.hpp:9,
from mahotas/_filters.h:2,
from mahotas/_interpolate.cpp:38:
/usr/include/c++/4.2.1/bits/localefwd.h:58:34: error: macro "isspace" passed 2 arguments, but takes just 1
/usr/include/c++/4.2.1/bits/localefwd.h:70:34: error: macro "isupper" passed 2 arguments, but takes just 1
/usr/include/c++/4.2.1/bits/localefwd.h:74:34: error: macro "islower" passed 2 arguments, but takes just 1
/usr/include/c++/4.2.1/bits/localefwd.h:78:34: error: macro "isalpha" passed 2 arguments, but takes just 1
/usr/include/c++/4.2.1/bits/localefwd.h:94:34: error: macro "isalnum" passed 2 arguments, but takes just 1
/usr/include/c++/4.2.1/bits/localefwd.h:102:34: error: macro "toupper" passed 2 arguments, but takes just 1
/usr/include/c++/4.2.1/bits/localefwd.h:106:34: error: macro "tolower" passed 2 arguments, but takes just 1
In file included from /usr/include/c++/4.2.1/bits/basic_ios.h:44,
from /usr/include/c++/4.2.1/ios:50,
from /usr/include/c++/4.2.1/ostream:45,
from /usr/include/c++/4.2.1/iterator:70,
from mahotas/numpypp/array.hpp:9,
from mahotas/_filters.h:2,
from mahotas/_interpolate.cpp:38:
/usr/include/c++/4.2.1/bits/locale_facets.h:245:53: error: macro "toupper" passed 2 arguments, but takes just 1
/usr/include/c++/4.2.1/bits/locale_facets.h:274:53: error: macro "tolower" passed 2 arguments, but takes just 1
/usr/include/c++/4.2.1/bits/locale_facets.h:817:53: error: macro "toupper" passed 2 arguments, but takes just 1
/usr/include/c++/4.2.1/bits/locale_facets.h:850:53: error: macro "tolower" passed 2 arguments, but takes just 1
/usr/include/c++/4.2.1/bits/locale_facets.h:4614:44: error: macro "isspace" passed 2 arguments, but takes just 1
/usr/include/c++/4.2.1/bits/locale_facets.h:4632:44: error: macro "isupper" passed 2 arguments, but takes just 1
/usr/include/c++/4.2.1/bits/locale_facets.h:4638:44: error: macro "islower" passed 2 arguments, but takes just 1
/usr/include/c++/4.2.1/bits/locale_facets.h:4644:44: error: macro "isalpha" passed 2 arguments, but takes just 1
/usr/include/c++/4.2.1/bits/locale_facets.h:4668:44: error: macro "isalnum" passed 2 arguments, but takes just 1
/usr/include/c++/4.2.1/bits/locale_facets.h:4680:44: error: macro "toupper" passed 2 arguments, but takes just 1
/usr/include/c++/4.2.1/bits/locale_facets.h:4686:44: error: macro "tolower" passed 2 arguments, but takes just 1
In file included from /usr/include/c++/4.2.1/ios:47,
from /usr/include/c++/4.2.1/ostream:45,
from /usr/include/c++/4.2.1/iterator:70,
from mahotas/numpypp/array.hpp:9,
from mahotas/_filters.h:2,
from mahotas/_interpolate.cpp:38:
/usr/include/c++/4.2.1/bits/localefwd.h:58: error: ‘std::isspace’ declared as an ‘inline’ variable
/usr/include/c++/4.2.1/bits/localefwd.h:58: error: template declaration of ‘bool std::isspace’
/usr/include/c++/4.2.1/bits/localefwd.h:70: error: ‘std::isupper’ declared as an ‘inline’ variable
/usr/include/c++/4.2.1/bits/localefwd.h:70: error: template declaration of ‘bool std::isupper’
/usr/include/c++/4.2.1/bits/localefwd.h:74: error: ‘std::islower’ declared as an ‘inline’ variable
/usr/include/c++/4.2.1/bits/localefwd.h:74: error: template declaration of ‘bool std::islower’
/usr/include/c++/4.2.1/bits/localefwd.h:78: error: ‘std::isalpha’ declared as an ‘inline’ variable
/usr/include/c++/4.2.1/bits/localefwd.h:78: error: template declaration of ‘bool std::isalpha’
/usr/include/c++/4.2.1/bits/localefwd.h:94: error: ‘std::isalnum’ declared as an ‘inline’ variable
/usr/include/c++/4.2.1/bits/localefwd.h:94: error: template declaration of ‘bool std::isalnum’
/usr/include/c++/4.2.1/bits/localefwd.h:102: error: ‘std::toupper’ declared as an ‘inline’ variable
/usr/include/c++/4.2.1/bits/localefwd.h:102: error: template declaration of ‘_CharT std::toupper’
/usr/include/c++/4.2.1/bits/localefwd.h:106: error: ‘std::tolower’ declared as an ‘inline’ variable
/usr/include/c++/4.2.1/bits/localefwd.h:106: error: template declaration of ‘_CharT std::tolower’
In file included from /usr/include/c++/4.2.1/bits/basic_ios.h:44,
from /usr/include/c++/4.2.1/ios:50,
from /usr/include/c++/4.2.1/ostream:45,
from /usr/include/c++/4.2.1/iterator:70,
from mahotas/numpypp/array.hpp:9,
from mahotas/_filters.h:2,
from mahotas/_interpolate.cpp:38:
/usr/include/c++/4.2.1/bits/locale_facets.h:230: error: ‘btowc’ is not a type
/usr/include/c++/4.2.1/bits/locale_facets.h:245: error: expected ‘;’ before ‘const’
/usr/include/c++/4.2.1/bits/locale_facets.h:258: error: expected ;' before ‘char_type’ /usr/include/c++/4.2.1/bits/locale_facets.h:259: error: ‘btowc’ is not a type /usr/include/c++/4.2.1/bits/locale_facets.h:274: error: expected ‘;’ before ‘const’ /usr/include/c++/4.2.1/bits/locale_facets.h:290: error: expected;' before ‘char_type’
/usr/include/c++/4.2.1/bits/locale_facets.h: In member function ‘_CharT std::__ctype_abstract_base<CharT>::towupper(int ()(_CharT)) const’:
/usr/include/c++/4.2.1/bits/locale_facets.h:231: error: ‘__c’ was not declared in this scope
/usr/include/c++/4.2.1/bits/locale_facets.h: In member function ‘CharT std::__ctype_abstract_base<CharT>::towlower(int ()(CharT)) const’:
/usr/include/c++/4.2.1/bits/locale_facets.h:260: error: ‘__c’ was not declared in this scope
/usr/include/c++/4.2.1/bits/locale_facets.h: At global scope:
/usr/include/c++/4.2.1/bits/locale_facets.h:800: error: ‘btowc’ is not a type
/usr/include/c++/4.2.1/bits/locale_facets.h:817: error: expected ‘;’ before ‘const’
/usr/include/c++/4.2.1/bits/locale_facets.h:832: error: expected ;' before ‘char_type’ /usr/include/c++/4.2.1/bits/locale_facets.h:833: error: ‘btowc’ is not a type /usr/include/c++/4.2.1/bits/locale_facets.h:850: error: expected ‘;’ before ‘const’ /usr/include/c++/4.2.1/bits/locale_facets.h:869: error: expected;' before ‘char_type’
/usr/include/c++/4.2.1/bits/locale_facets.h: In member function ‘char std::ctype::towupper(int (
)(char)) const’:
/usr/include/c++/4.2.1/bits/locale_facets.h:801: error: ‘__c’ was not declared in this scope
/usr/include/c++/4.2.1/bits/locale_facets.h: In member function ‘char std::ctype::towlower(int (
)(char)) const’:
/usr/include/c++/4.2.1/bits/locale_facets.h:834: error: ‘__c’ was not declared in this scope
In file included from /usr/include/c++/4.2.1/bits/basic_ios.h:44,
from /usr/include/c++/4.2.1/ios:50,
from /usr/include/c++/4.2.1/ostream:45,
from /usr/include/c++/4.2.1/iterator:70,
from mahotas/numpypp/array.hpp:9,
from mahotas/_filters.h:2,
from mahotas/_interpolate.cpp:38:
/usr/include/c++/4.2.1/bits/locale_facets.h: At global scope:
/usr/include/c++/4.2.1/bits/locale_facets.h:4614: error: function definition does not declare parameters
/usr/include/c++/4.2.1/bits/locale_facets.h:4632: error: function definition does not declare parameters
/usr/include/c++/4.2.1/bits/locale_facets.h:4638: error: function definition does not declare parameters
/usr/include/c++/4.2.1/bits/locale_facets.h:4644: error: function definition does not declare parameters
/usr/include/c++/4.2.1/bits/locale_facets.h:4668: error: function definition does not declare parameters
/usr/include/c++/4.2.1/bits/locale_facets.h:4680: error: function definition does not declare parameters
/usr/include/c++/4.2.1/bits/locale_facets.h:4686: error: function definition does not declare parameters
error: Command "g++ -fno-strict-aliasing -fno-common -dynamic -arch i386 -DNDEBUG -g -O3 -arch i386 -I/Library/Frameworks/Python.framework/Versions/7.1/lib/python2.7/site-packages/numpy/core/include -I/Library/Frameworks/Python.framework/Versions/7.1/include/python2.7 -c mahotas/_interpolate.cpp -o build/temp.macosx-10.5-i386-2.7/mahotas/_interpolate.o" failed with exit status 1

haralick returns empty array

On one particular input I'm getting an empty array from haralick. It has been working fine millions of times so I know it's this particular input.

>>> a = np.array([[  0,   0,   0,   0,   0,   0,   0,   0, 131,   0, 139,   0,   0,   0,   0,   0,   0,   0,
             0,   0,   0,   0,   0,   0,   0,   0],
          [  0,   0,   0,   0,   0, 136,   0,   0,   0,   0,   0,   0,   0, 131,   0,   0,   0, 136,
             0,   0, 139,   0,   0,   0,   0,   0],
          [  0,   0,   0,   0,   0,   0,   0, 137,   0, 139,   0,   0,   0,   0,   0, 129,   0,   0,
             0,   0,   0,   0,   0,   0,   0,   0]])
>>> mh.features.haralick(a, ignore_zeros=True).shape
(0,)

And it's also to do with ignore_zeros

>>> mh.features.haralick(a, ignore_zeros=False).shape
(4, 13)

Are the haralick features not able to be calculated for this input? If so the docs should mention that such a result is possible.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.