Nie*_*NL4 -1 python image image-processing
我正在制作一个脚本,以从扫描的图像中去除斑点(例如噪点和对比度),但是现在我想从图像中去除污点,但是有什么好的方法来解决此问题?
我想去除污渍,但又不会丢失太多图像细节,因为我需要能够看到线条和文字。
由于imag仅具有黑白颜色,因此您可以尝试将其二值化。有很多方法可以做到这一点,但是scikit-image包可以选择查看应用多个阈值的结果:
import matplotlib.pyplot as plt
from skimage import io
from skimage.filters import try_all_threshold
img = io.imread('your_img')
fig, ax = try_all_threshold(img, figsize=(10, 8), verbose=False)
plt.show()
Run Code Online (Sandbox Code Playgroud)
编辑:二值化仅适用于灰度图像,因此您应该将图像转换为黑白:
import matplotlib.pyplot as plt
from skimage import io
from skimage.filters import try_all_threshold
from skimage.color import rgb2gray
img = io.imread('your_img')
img = rgb2gray(img)
fig, ax = try_all_threshold(img, figsize=(15, 15), verbose=False)
plt.show()
Run Code Online (Sandbox Code Playgroud)
结果附在这里。
当然,您也可以尝试应用自己的阈值。检查图像的直方图以查看阈值的最佳值将是很好的。