freealise commited on
Commit
39d3066
1 Parent(s): 2563c5c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -8
app.py CHANGED
@@ -360,12 +360,6 @@ def draw_mask(f, v, d, evt: gr.EventData):
360
  else:
361
  gradient = cv2.imread(f[2]).astype(np.uint8)
362
 
363
- bg = cv2.cvtColor(d["background"], cv2.COLOR_RGB2GRAY)
364
- gd = cv2.cvtColor(gradient, cv2.COLOR_RGB2GRAY)
365
- diff = abs(bg-gd).astype(np.uint8)
366
- mask = cv2.inRange(diff, 0, 5)
367
- d["background"][mask>0] = (0,0,0,255)
368
-
369
  n = 16 # Number of levels of quantization
370
  #for i in range(n):
371
  # im[(im >= i*255/n) & (im < (i+1)*255/n)] = i*255/(n-1)
@@ -375,7 +369,15 @@ def draw_mask(f, v, d, evt: gr.EventData):
375
  color_levels = np.clip(np.int0(indices/divider),0,n-1) # color levels 0,1,2..
376
  palette = quantiz[color_levels]
377
 
378
- d["background"] = cv2.convertScaleAbs(palette[d["background"]]) # Converting image back to uint8
 
 
 
 
 
 
 
 
379
 
380
  d["layers"][0] = cv2.fillPoly(d["layers"][0], [pts], (0,0,0,255))
381
  d["composite"] = cv2.fillPoly(d["composite"], [pts], (0,0,0,255))
@@ -434,7 +436,7 @@ with gr.Blocks(css=css) as demo:
434
  output_switch = gr.Checkbox(label="Show depths")
435
  output_switch.input(fn=switch_rows, inputs=[output_switch], outputs=[output_frame])
436
  output_mask = gr.ImageEditor(layers=True, sources=None, type="numpy", interactive=True, transforms=(None,), eraser=gr.Eraser(), brush=gr.Brush(default_size=0, colors=['black', '#505050', '#a0a0a0', 'white']), elem_id="image_edit")
437
- gradients = gr.Files(value=['./gradient_large.png', './gradient.png', './gradient_small.png'])
438
  selector = gr.HTML(value="""<div id='select_cursor' style='width:1px;height:1px;position:absolute;border:8px dotted #ffffff;opacity:50%;'></div>
439
  <a href='#' id='selector' onclick='this.style.fontWeight=\"bold\";
440
  document.body.appendChild(document.getElementById(\"select_cursor\"));
 
360
  else:
361
  gradient = cv2.imread(f[2]).astype(np.uint8)
362
 
 
 
 
 
 
 
363
  n = 16 # Number of levels of quantization
364
  #for i in range(n):
365
  # im[(im >= i*255/n) & (im < (i+1)*255/n)] = i*255/(n-1)
 
369
  color_levels = np.clip(np.int0(indices/divider),0,n-1) # color levels 0,1,2..
370
  palette = quantiz[color_levels]
371
 
372
+ bg = cv2.cvtColor(d["background"], cv2.COLOR_RGB2GRAY)
373
+ gd = cv2.cvtColor(gradient, cv2.COLOR_RGB2GRAY)
374
+
375
+ bg = cv2.convertScaleAbs(palette[bg]) # Converting image back to uint8
376
+ gd = cv2.convertScaleAbs(palette[gd])
377
+
378
+ diff = (bg-gd).astype(np.uint8)
379
+ mask = cv2.inRange(diff, -int(n/2), int(n/2))
380
+ d["background"][mask>0] = (0,0,0,255)
381
 
382
  d["layers"][0] = cv2.fillPoly(d["layers"][0], [pts], (0,0,0,255))
383
  d["composite"] = cv2.fillPoly(d["composite"], [pts], (0,0,0,255))
 
436
  output_switch = gr.Checkbox(label="Show depths")
437
  output_switch.input(fn=switch_rows, inputs=[output_switch], outputs=[output_frame])
438
  output_mask = gr.ImageEditor(layers=True, sources=None, type="numpy", interactive=True, transforms=(None,), eraser=gr.Eraser(), brush=gr.Brush(default_size=0, colors=['black', '#505050', '#a0a0a0', 'white']), elem_id="image_edit")
439
+ gradients = gr.Files(visible=False, value=['./gradient_large.png', './gradient.png', './gradient_small.png'])
440
  selector = gr.HTML(value="""<div id='select_cursor' style='width:1px;height:1px;position:absolute;border:8px dotted #ffffff;opacity:50%;'></div>
441
  <a href='#' id='selector' onclick='this.style.fontWeight=\"bold\";
442
  document.body.appendChild(document.getElementById(\"select_cursor\"));