我从图像中提取字符的代码有问题:
例子:
原始图像 处理后的图像
我正在应用一堆过滤器来尝试从这些标志中提取特定字符并将它们发送到我的 OCR 软件(高斯过滤器、水脱落和阈值处理)。
我想对图像应用 otsu 阈值过滤器,但是当我尝试保存图像时,它被转换为 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)
我能做些什么来解决这个问题?