# done ver1

unknown
python
2 years ago
2.9 kB
3
Indexable
Never
```from pickletools import uint8
import numpy as np
import cv2
import math
def show(image):
cv2.imshow('image',image)
cv2.waitKey(0)
cv2.destroyAllWindows()

'''return gs, size: (window_size, window_size)'''
gs = np.zeros((window_size, window_size, 3))
for i in range(window_size):
for j in range(i, window_size):
gs[i, j, :] = result
gs[j, i, :] = result
return gs

# def get_gr_value(p, q, gr_dict):
#     p_red, p_green, p_blue = p[0], p[1], p[2]
#     q_red, q_green, q_blue = q[0], q[1], q[2]
#     gr = gr_dict[abs(p_red - q_red)] * gr_dict[abs(p_green -  q_green)] * gr_dict[abs(p_blue-q_blue)]
#     return gr

class Joint_bilateral_filter(object):
def __init__(self, sigma_s, sigma_r):
self.sigma_r = sigma_r
self.sigma_s = sigma_s
self.wndw_size = 6*sigma_s+1 # ws

def joint_bilateral_filter(self, img, guidance):
BORDER_TYPE = cv2.BORDER_REFLECT
window_size = self.wndw_size
print("window size: ", window_size)
print("=============")

### TODO ###
# save Gs kernel dict

gr_dict = [np.exp(-(x * 0.5 / ((self.sigma_r**2)* (255**2)))) for x in range(256)]

output = np.zeros(img.shape)

shift = 0
i, j = 0, 0
shift_x, shift_y = 0, 0

# for a window
for i in range(img.shape[0]):
for j in range(img.shape[1]):