#coding:utf-8
import sys,os
from PIL import Image,ImageDraw
#二值判断,如果确认是噪声,用改点的上面一个点的灰度进行替换
#该函数也可以改成RGB判断的,具体看需求如何
def getPixel(image,x,y,G,N):
L = image.getpixel((x,y))
if L > G:
L = True
else:
L = False
nearDots = 0
if L == (image.getpixel((x - 1,y - 1)) > G):
nearDots += 1
if L == (image.getpixel((x - 1,y)) > G):
nearDots += 1
if L == (image.getpixel((x - 1,y + 1)) > G):
nearDots += 1
if L == (image.getpixel((x,y - 1)) > G):
nearDots += 1
if L == (image.getpixel((x,y + 1)) > G):
nearDots += 1
if L == (image.getpixel((x + 1,y - 1)) > G):
nearDots += 1
if L == (image.getpixel((x + 1,y)) > G):
nearDots += 1
if L == (image.getpixel((x + 1,y + 1)) >
完整的图片去噪代码(python)
最新推荐文章于 2024-08-27 21:46:53 发布
这是一个使用Python进行图片去噪的完整代码示例。通过定义getPixel函数进行二值判断,并结合clearNoise函数进行降噪处理,根据设定的阀值和降噪率来识别并替换噪点。最后,通过main函数读取图片、转换为灰度图并执行降噪,将处理后的图片保存。
摘要由CSDN通过智能技术生成