skimage函数添加椒盐噪声是怎么添加的啊?

记不清在哪看到的了,好像skimage函数来添加椒盐噪声,也是利用numpy模块进行运算,然后random随机数来判断比例的方式来决定该点是0还是255。是这样吗?

from skimage import util
    noise = util.random_noise(img,mode="s&p",amount = 0.1)
def salt(img,portion):
    output = np.zeros(img.shape,np.uint8)
    res = 1 - portion/2 
    for i in range(img.shape[0]):
        for j in range(img.shape[1]):
            ans = random.random()
            if ans < portion:
                output[i][j] = 0
            elif ans > res:
                output[i][j] = 255
            else:
                output[i][j] = img[i][j]
    return output

在通过skimage函数来添加噪声,其中的过程中也是下面这段代码的这个实际实现原理吗?(就是利用numpy模块进行运算,然后random随机数来判断比例的方式来决定该点是0还是255。)

不知道你这个问题是否已经解决, 如果还没有解决的话:

如果你已经解决了该问题, 非常希望你能够分享一下解决方案, 以帮助更多的人 ^-^