python - 使用 Mahotas 读写图像

标签 python image-processing mahotas

我正在尝试用 Mahotas 写一幅图像,但发现它出奇地困难。

img = mahotas.imread('foo.png', True)
mahotas.imsave('bar.png', img)

我得到的错误是:

ValueError: mahotas.freeimage: cannot write arrays of given type and shape.

我在 OS X 上并使用 brew 安装 freeimage。

最佳答案

mahotas 的作者在这里。错误消息并不理想(将修复它),但这是正在发生的事情。

灰度图像是浮点图像(即 img.dtype == numpy.float64),您不能将浮点图像保存为 PNG。

转换为numpy.uint8:

mahotas.imsave('test.png', img.astype(numpy.uint8))

它会按预期工作。

关于python - 使用 Mahotas 读写图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8888406/

相关文章:

python - 如何设置 SET VS90COMNTOOLS=%VS110COMNTOOLS%

python mahotas : Applying threshold filter and saving image as pgn

python - 在numpy数组中过滤2D图像并在python中计算

python - pip install 默认带有删除选项

python - 有关 “Ignoring visible gpu device and Adding visible gpu device”的问题

python - 给定一定的比例,我如何调整图像的大小?

algorithm - Lowe 如何计算他的 SIFT 算法的 “repeatability”?

python-3.x - 减少/增强图像中的已知特征

python - 使用 inferred_freq 设置 pandas.tseries.index.DatetimeIndex.freq

c++ - matlab在opencv中查找函数实现?