pythonthresholdmahotas

Python module Mahotas thresholding issue


I'm using this tutorial http://pythonvision.org/basic-tutorial

However when I pass a png image:

T = mahotas.thresholding.otsu(dna)

I get an error:

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

Does anyone have exp. w/this issue? Thanks!


Solution

  • The error basically says that the type of the elements in your image array is 32 bit float, not integer, which is required. The docs also say that this method requires unsigned int. See here.

    To convert a numpy array to unsigned 8 bit integers, do the following:

    # Assuming I is your image. Convert to 8 bit unsigned integers.
    I_uint8 = I.astype('uint8')
    

    UPDATE: Please see comment by Mahotas' creator below on the issue of multi-channel images.