opencv去除高斯噪声(H1范数)

Python +opencv

# _*_ coding:UTF-8 _*_

import numpy as np

import cv2

def Normalize(value):

    if value > 255:

        value = 255

    elif value < 0:

        value = 0

    return value;

img=cv2.imread("D:/xiaomao.jpg")

def addGaussian(image):

    for i in range(0,image.shape[0]):

        for j in range(0,image.shape[1]):    image[i,j]=[int(Normalize(image[i,j,0]+(np.random.normal(50,25)))),int(Normalize(image[i,j,1]+(np.random.normal(50,25)))),int(Normalize(image[i,j,2]+(np.random.normal(50,25))))]         

    return;

def process(img):

    a=0.1

    k=0

    while k<8:      

        for i in range(0,img.shape[0]-1):

            for j in range(0,img.shape[1]-1):

                Uxx0 = float(img[i+1,j,0] - img[i,j,0] * 2 + img[i-1,j,0])

                Uxx1 = float(img[i+1,j,1] - img[i,j,1] * 2 + img[i-1,j,1])

                Uxx2 = float(img[i+1,j,2] - img[i,j,2] * 2 + img[i-1,j,2])

                Uyy0 = float(img[i,j+1,0] - 2 * img[i,j,0] + img[i,j-1,0])

                Uyy1 = float(img[i,j+1,1] - 2 * img[i,j,1] + img[i,j-1,1])

                Uyy2 = float(img[i,j+1,2] - 2 * img[i,j,2] + img[i,j-1,2])

                img[i,j,0] = img[i,j,0] + a * (Uxx0 + Uyy0) 

                img[i,j,1] = img[i,j,1] + a * (Uxx1 + Uyy1)

                img[i,j,2] = img[i,j,2] + a * (Uxx2 + Uyy2)

          k=k+1

        print k 

    return;                      

img=cv2.imread("D:/xiaomao.jpg")

cv2.imshow('image',img)

addGaussian(img)

cv2.imshow('Gaussian',img)

process(img)

cv2.imshow('迭代8',img)

cv2.waitKey(0)

cv2.destroyAllWindows()

结果:

原图:


添加高斯噪声:
 
去除高斯噪声

 


你可能感兴趣的:(opencv,python,高斯去噪)