小编use*_*151的帖子

如何使用python从图像中去除椒盐噪声?

我尝试实现以下算法,但生成的图像看起来相同。

第 1 步:读取噪声图像。

步骤 2:选择大小为 3x3 的 2D 窗口,中心元素作为处理像素。假设正在处理的像素是 P ij 。

步骤3:如果P ij 是未损坏的像素(即0< P ij <255),则其值保持不变。

步骤4:如果P ij = 0 或P ij = 255,则P ij 是损坏的像素。

第 5 步:如果所选窗口中有 3/4 或更多像素有噪声,则将窗口大小增加到 5x5。步骤 6:如果所选窗口中的所有元素都是 0?s 和 255?s,则将 Pij 替换为窗口中元素的均值,否则转到步骤 7。

步骤 7:从所选窗口中消除 0?s 和 255?s,并找到剩余元素的中值。用中值替换 Pij。

步骤8:重复步骤2到6,直到处理完整幅图像中的所有像素。

这是我的代码。请提出改进​​建议。

import Image

im=Image.open("no.jpg")
im = im.convert('L')

for i in range(2,im.size[0]-2):
    for j in range(2,im.size[1]-2):
        b=[]
        if im.getpixel((i,j))>0 and im.getpixel((i,j))<255:
            pass
        elif im.getpixel((i,j))==0 or …
Run Code Online (Sandbox Code Playgroud)

python image image-processing noise noise-reduction

2
推荐指数
1
解决办法
2万
查看次数

标签 统计

image ×1

image-processing ×1

noise ×1

noise-reduction ×1

python ×1