删除像素少于(N)的点
我试过了几乎所有在 PIL
中的滤镜,但都没有成功。有没有什么方法可以在 numpy 或 scipy 中去除噪声?就像 Matlab 中的 Bwareaopen() 函数一样?
例如:
另外,如果有办法把字母填成黑色,我会非常感激。
3 个回答
13
Numpy和Scipy的解决方案是:scipy.ndimage.morphology.binary_opening
。如果需要更强大的功能,可以使用scikits-image。
from skimage import morphology
cleaned = morphology.remove_small_objects(YOUR_IMAGE, min_size=64, connectivity=2)
可以查看这个链接了解更多信息:http://scikit-image.org/docs/0.9.x/api/skimage.morphology.html#remove-small-objects
15
Numpy和Scipy可以像Matlab一样进行形态学操作。
你可以查看 scipy.ndimage.morphology,里面有很多功能,其中包括 binary_opening()
,这个功能和Matlab里的 bwareaopen()
是一样的。
10
我觉得这可能不是你想要的,但这个方法是可行的(它使用了Opencv,而Opencv又依赖于Numpy):
import cv2
# load image
fname = 'Myimage.jpg'
im = cv2.imread(fname,cv2.COLOR_RGB2GRAY)
# blur image
im = cv2.blur(im,(4,4))
# apply a threshold
im = cv2.threshold(im, 175 , 250, cv2.THRESH_BINARY)
im = im[1]
# show image
cv2.imshow('',im)
cv2.waitKey(0)
输出结果(在窗口中显示的图像):
你可以用 cv2.imwrite
来保存这个图像。