Spaces:
Starting
Starting
Update app.py
Browse files
app.py
CHANGED
@@ -392,20 +392,28 @@ def optimize(v, d):
|
|
392 |
scale = 1
|
393 |
delta = 0
|
394 |
ddepth = cv2.CV_16S
|
|
|
395 |
|
396 |
indices = np.arange(0,256) # List of all colors
|
397 |
-
divider = np.linspace(0,255,
|
398 |
-
quantiz = np.int0(np.linspace(0,255,
|
399 |
-
color_levels = np.clip(np.int0(indices/divider),0,
|
400 |
palette = quantiz[color_levels]
|
401 |
for k, f in enumerate(frames):
|
402 |
frame = cv2.imread(frames[k]).astype(np.uint8)
|
403 |
frame = cv2.convertScaleAbs(palette[frame]).astype(np.uint8) # Converting image back to uint
|
404 |
cv2.imwrite(frames[k], frame)
|
|
|
405 |
return frames
|
406 |
else:
|
407 |
return depths
|
408 |
|
|
|
|
|
|
|
|
|
|
|
|
|
409 |
def reset_mask():
|
410 |
global frame_selected
|
411 |
global masks
|
|
|
392 |
scale = 1
|
393 |
delta = 0
|
394 |
ddepth = cv2.CV_16S
|
395 |
+
l = 48
|
396 |
|
397 |
indices = np.arange(0,256) # List of all colors
|
398 |
+
divider = np.linspace(0,255,l+1)[1] # we get a divider
|
399 |
+
quantiz = np.int0(np.linspace(0,255,l)) # we get quantization colors
|
400 |
+
color_levels = np.clip(np.int0(indices/divider),0,l-1) # color levels 0,1,2..
|
401 |
palette = quantiz[color_levels]
|
402 |
for k, f in enumerate(frames):
|
403 |
frame = cv2.imread(frames[k]).astype(np.uint8)
|
404 |
frame = cv2.convertScaleAbs(palette[frame]).astype(np.uint8) # Converting image back to uint
|
405 |
cv2.imwrite(frames[k], frame)
|
406 |
+
print(bincount(frame))
|
407 |
return frames
|
408 |
else:
|
409 |
return depths
|
410 |
|
411 |
+
def bincount(a):
|
412 |
+
a2D = a.reshape(-1,a.shape[-1])
|
413 |
+
col_range = (256, 256, 256) # generically : a2D.max(0)+1
|
414 |
+
a1D = np.ravel_multi_index(a2D.T, col_range)
|
415 |
+
return np.unravel_index(np.bincount(a1D).argmax(), col_range)
|
416 |
+
|
417 |
def reset_mask():
|
418 |
global frame_selected
|
419 |
global masks
|