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!
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.
the solution by @lightalchemist works, just remember to multiply the image by 255 first:
img = (img*255).astype('uint8')
I am also following this example. After the gaussian filter, dnaf becomes a float64
print(dnaf.dtype)
You need to convert back to a 8-bit image
dnaf = dnaf.astype('uint8')
print(dnaf.dtype)
And carry on with the thresholding
T = mh.thresholding.otsu(dnaf)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With