Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -343,11 +343,20 @@ def draw_mask(th, v, d, evt: gr.EventData):
|
|
343 |
pts = pts.reshape((-1,1,2))
|
344 |
|
345 |
bg = cv2.cvtColor(d["background"], cv2.COLOR_RGB2GRAY)
|
346 |
-
|
347 |
-
diff = abs(bg-
|
348 |
mask = cv2.inRange(diff, 0, 5)
|
349 |
d["background"][mask>0] = (0,0,0,255)
|
350 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
351 |
d["layers"][0] = cv2.fillPoly(d["layers"][0], [pts], (0,0,0,255))
|
352 |
d["composite"] = cv2.fillPoly(d["composite"], [pts], (0,0,0,255))
|
353 |
|
|
|
343 |
pts = pts.reshape((-1,1,2))
|
344 |
|
345 |
bg = cv2.cvtColor(d["background"], cv2.COLOR_RGB2GRAY)
|
346 |
+
gr = ((cv2.cvtColor(cv2.imread(masks[len(masks)-1]), cv2.COLOR_RGB2GRAY)-th)*2).astype(np.uint8)
|
347 |
+
diff = abs(bg-gr).astype(np.uint8)
|
348 |
mask = cv2.inRange(diff, 0, 5)
|
349 |
d["background"][mask>0] = (0,0,0,255)
|
350 |
|
351 |
+
n = 16 # Number of levels of quantization
|
352 |
+
indices = np.arange(0,256) # List of all colors
|
353 |
+
divider = np.linspace(0,255,n+1)[1] # we get a divider
|
354 |
+
quantiz = np.int0(np.linspace(0,255,n)) # we get quantization colors
|
355 |
+
color_levels = np.clip(np.int0(indices/divider),0,n-1) # color levels 0,1,2..
|
356 |
+
palette = quantiz[color_levels]
|
357 |
+
|
358 |
+
d["background"] = cv2.convertScaleAbs(palette[d["background"]]) # Converting image back to uint8
|
359 |
+
|
360 |
d["layers"][0] = cv2.fillPoly(d["layers"][0], [pts], (0,0,0,255))
|
361 |
d["composite"] = cv2.fillPoly(d["composite"], [pts], (0,0,0,255))
|
362 |
|