我正在使用本教程http://pythonvision.org/basic-tutorial
但是,当我传递一个png图像时:
T = mahotas.thresholding.otsu(dna)我收到一个错误:
TypeError: mahotas.otsu:此函数只接受整数类型(传递的数组类型为float32)
有人有经验吗。这个问题?谢谢!
发布于 2013-11-19 02:29:36
错误基本上表示图像数组中元素的类型是32位浮点数,而不是整数,这是必需的。文档还指出,此方法需要无符号int。见这里。
若要将numpy数组转换为无符号8位整数,请执行以下操作:
# Assuming I is your image. Convert to 8 bit unsigned integers.
I_uint8 = I.astype('uint8')UPDATE:请参阅下面Mahotas的创建者对多通道图像问题的评论。
发布于 2014-07-11 12:32:07
@光滑石化学家的解决方案奏效了,请记住,首先要将图像乘以255:
img = (img*255).astype('uint8')发布于 2019-08-22 03:35:14
我也是这样做的。经过高斯滤波后,dnaf变成了float64。
print(dnaf.dtype)您需要将其转换回8位映像。
dnaf = dnaf.astype('uint8')
print(dnaf.dtype)并继续进行脱粒
T = mh.thresholding.otsu(dnaf)https://stackoverflow.com/questions/20061729
复制相似问题