如何对有错误的图像进行降级

问题描述 投票:1回答:2

我想在图像内产生合成噪声。如何在每个点具有独立的错误概率的情况下,对具有错误的黑白图像进行降级。我将如何在Python中执行此操作(例如错误概率= 0.0011)?

enter image description here

python python-3.x image image-processing noise
2个回答
1
投票

这是一个示例程序,使用Pillow库简单地将“降级”像素替换为黑色

from PIL import Image
import random

img = Image.open('text.png')
pixels = img.load()

for x in range(img.size[0]):
    for y in range(img.size[1]):
        if random.random() < 0.011:
            pixels[x,y] = 0 # only 1 number given since the image is grayscale

img.save('text_degraded.png')

我将概率提高到0.011,以使其更加引人注目,这是输出enter image description here


0
投票

这里是使用OpenCV + skimage.util.random_noise的矢量化方法。您可以尝试使用skimage.util.random_noiselocalvarpeppers&p等噪声模式来获得所需的结果。您可以使用speckle参数设置噪声比例。这是将amounts&p结合使用的示例:

amount=0.011

enter image description here
© www.soinside.com 2019 - 2024. All rights reserved.