Spaces:
Build error
Build error
has12zen
commited on
Commit
·
a880d2c
1
Parent(s):
3af08fb
test
Browse files
utils.py
CHANGED
@@ -52,44 +52,42 @@ for i in range(0,len(l)):
|
|
52 |
|
53 |
|
54 |
def calc_filtered_img(img):
|
55 |
-
residual_img= np.zeros(img.shape)
|
56 |
# residual_img = np.array(img);
|
57 |
-
|
58 |
-
|
59 |
-
for i in range(img.shape[0]):
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
return residual_img
|
70 |
|
71 |
def calc_q_t_img(img, q, t):
|
72 |
-
qt_img = np.zeros(img.shape)
|
73 |
-
|
74 |
-
for
|
75 |
-
|
76 |
-
|
77 |
-
dct[val] = dct.get(val,0)+1
|
78 |
-
qt_img[i, j] = val
|
79 |
# print(dct)
|
|
|
80 |
return qt_img
|
81 |
|
82 |
def process_frame(frame_and_index):
|
83 |
frame, index = frame_and_index
|
84 |
# processing logic for a single frame
|
85 |
-
|
86 |
filtered_image = calc_filtered_img(frame)
|
87 |
output_image = calc_q_t_img(filtered_image, q, t)
|
88 |
output_image=output_image+2
|
89 |
# plt.imshow(output_image)
|
90 |
return output_image.astype(np.uint8)
|
91 |
|
92 |
-
|
93 |
# Center the filtered image at zero by adding 128
|
94 |
q = 3
|
95 |
t = 2
|
|
|
52 |
|
53 |
|
54 |
def calc_filtered_img(img):
|
55 |
+
# residual_img= np.zeros(img.shape)
|
56 |
# residual_img = np.array(img);
|
57 |
+
fil = np.array([[-1,3,-3,1]])
|
58 |
+
residual_img = cv2.filter2D(img, -1, fil)
|
59 |
+
# for i in range(img.shape[0]):
|
60 |
+
# for j in range(img.shape[1]):
|
61 |
+
# residual_img[i, j] = - 3*img[i, j];
|
62 |
+
# if(j>0):
|
63 |
+
# residual_img[i, j] += img[i, j-1]
|
64 |
+
# if(j+1<img.shape[1]):
|
65 |
+
# residual_img[i, j] += 3*img[i, j+1]
|
66 |
+
# if(j+2<img.shape[1]):
|
67 |
+
# residual_img[i,j]-= img[i, j+2]
|
68 |
+
# residual_img = np.convolve(img,[1,-3,3,-1],mode='same')
|
69 |
return residual_img
|
70 |
|
71 |
def calc_q_t_img(img, q, t):
|
72 |
+
# qt_img = np.zeros(img.shape)
|
73 |
+
# for i in range(img.shape[0]):
|
74 |
+
# for j in range(img.shape[1]):
|
75 |
+
# val = np.minimum(t, np.maximum(-t, np.round(img[i, j]/q)))
|
76 |
+
# qt_img[i, j] = val
|
|
|
|
|
77 |
# print(dct)
|
78 |
+
qt_img = np.minimum(t, np.maximum(-t, np.round(img/q)))
|
79 |
return qt_img
|
80 |
|
81 |
def process_frame(frame_and_index):
|
82 |
frame, index = frame_and_index
|
83 |
# processing logic for a single frame
|
84 |
+
logging.info(f"Processing frame {index}")
|
85 |
filtered_image = calc_filtered_img(frame)
|
86 |
output_image = calc_q_t_img(filtered_image, q, t)
|
87 |
output_image=output_image+2
|
88 |
# plt.imshow(output_image)
|
89 |
return output_image.astype(np.uint8)
|
90 |
|
|
|
91 |
# Center the filtered image at zero by adding 128
|
92 |
q = 3
|
93 |
t = 2
|