- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我在从图像中提取字符的代码时遇到问题:
示例:
原始图像 处理后的图像
我正在应用一堆过滤器来尝试从这些标志中提取特定字符,并将它们发送到我的 OCR 软件(高斯过滤器、水脱落和阈值处理)。
我想对图像应用大津阈值过滤器,但当我尝试保存图像时,它被转换为 float64,使其无法保存为 png:
seeds,nseeds = mahotas.label(dnaf < T)
labeled = mahotas.cwatershed(dnaf.max() - dnaf, seeds)
labeled = labeled.astype('uint8')
T = mahotas.thresholding.otsu(labeled)
pylab.imshow(labeled > T)
pylab.show()
mahotas.imsave('py.png', labeled > T)
给我
File "imgtest2.py", line 67, in <module>
mahotas.imsave('py.png', labeled > T)
File "/usr/local/lib/python2.7/site-packages/mahotas/io/freeimage.py", line 798, in imsave
write(img, filename)
File "/usr/local/lib/python2.7/site-packages/mahotas/io/freeimage.py", line 586, in write
bitmap, fi_type = _array_to_bitmap(array)
File "/usr/local/lib/python2.7/site-packages/mahotas/io/freeimage.py", line 653, in _array_to_bitmap
'mahotas.freeimage: cannot write arrays of given type and shape.')
ValueError: mahotas.freeimage: cannot write arrays of given type and shape.
如果我尝试创建一个中间变量来保存应用了阈值的图像,则图像将变为空白:
seeds,nseeds = mahotas.label(dnaf < T)
labeled = mahotas.cwatershed(dnaf.max() - dnaf, seeds)
labeled = labeled.astype('uint8')
T = mahotas.thresholding.otsu(labeled)
final = labeled > T
final = final.astype('uint8')
pylab.imshow(final)
pylab.show()
mahotas.imsave('py.png', final)
我可以做什么来解决这个问题?
最佳答案
(此处为 mahotas 的作者):
我的猜测是图像保存正确,但你看错了。行后
final = final.astype('uint8')
final 是一个包含 0
和 1
的 uint8
图像。因此,“白色”位非常暗。尝试将其乘以 255:
mahotas.imsave('py.png', 255 * final)
或者像这样保存它,但以拉伸(stretch)版本可视化它:
pylab.imshow(255 * final)
pylab.show()
关于 python mahotas : Applying threshold filter and saving image as pgn,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26764015/
我正在尝试用 Mahotas 写一幅图像,但发现它出奇地困难。 img = mahotas.imread('foo.png', True) mahotas.imsave('bar.png', img)
我正在使用本教程 http://pythonvision.org/basic-tutorial 但是当我传递一个 png 图像时: T = mahotas.thresholding.otsu(dna)
我是 python 新手,建议我使用 Canopy。我正在努力跟进 with this tutorial ,但我陷入了 mahotas.imread 行。我收到一个错误,说以这个结尾: Full er
我正在使用 mahotas 库对卫星图像(250 x 200 像素)进行纹理分析 (GLCM)。 GLCM 计算是在一个窗口大小内进行的。因此,对于滑动窗口的两个相邻位置,我们需要从头开始计算两个共生
我有这样一张图片: 在我通过 scikit 图像的骨架化功能对其进行骨架化之后 from skimage import morphology out = morphology.skeletonize(
我的另一个代码保存了一张图片。图像是普通的 JPG 文件。我用 imsave 保存了它。 现在当我在另一个代码中阅读它时,它似乎是 3d :S 图像是here . 阅读它的简单代码是这样的: impo
您好,我是 Python 新手,正在关注 Python Image Tutorial . 安装教程中描述的包后,下面的命令没有错误地执行 import numpy import scipy impor
我最近不得不用 Python 做很多与视觉相关的工作,而且我在格式之间切换时遇到了很多困难。当我使用 Mahotas 读取图像时,我似乎无法将其转换为 cv2,尽管它们都使用 numpy.ndarra
我在从图像中提取字符的代码时遇到问题: 示例: 原始图像 处理后的图像 我正在应用一堆过滤器来尝试从这些标志中提取特定字符,并将它们发送到我的 OCR 软件(高斯过滤器、水脱落和阈值处理)。 我想对图
我正在使用命令提示符安装 Manhotas 1.1.0。我在 zip 文件中有 mahotas,我已将其解压缩。我的程序是:'python setup.py install'。但是,它给我错误: 提前
如何在 Python cv2 中从 Internet URL 读取图像? 这个 Stack Overflow answer , import cv2.cv as cv import urllib2 f
我是一名优秀的程序员,十分优秀!