-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBilateral.py
More file actions
50 lines (36 loc) · 1.02 KB
/
Bilateral.py
File metadata and controls
50 lines (36 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Mon Jul 22 21:07:19 2019
@author: vaeahc
"""
import cv2
import numpy as np
import matplotlib.pyplot as plt
def Bilateral(A):
#5 * 5双边滤波
#定义域标准差
sigma_d = 4
#值域标准差
sigma_r = 0.1
w = np.zeros((11, 11))
for i in range(11):
for j in range(11):
c = A[5][5]
w[i][j] = np.exp(-((i - 5) ** 2 + (j - 5) ** 2) / (2 * sigma_d ** 2) - (c - A[i][j]) ** 2 / (2 * sigma_r ** 2))
w /= np.sum(w)
return w
img = cv2.imread('lena512color.tiff', 0) / 255
im_out = np.zeros(np.shape(img))
img = cv2.copyMakeBorder(img, 5, 5, 5, 5, cv2.BORDER_DEFAULT)
for i in range(im_out.shape[0]):
for j in range(im_out.shape[1]):
A = img[i: i + 11, j : j + 11]
im_out[i][j] = np.sum(A * Bilateral(A))
plt.imshow(im_out, 'gray')
plt.show()
'''
im = cv2.GaussianBlur(img, (11, 11), 4)
plt.imshow(im, 'gray')
plt.show()
'''