freealise commited on
Commit
e057879
1 Parent(s): 36e0e10

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -15
app.py CHANGED
@@ -345,15 +345,15 @@ def draw_mask(ksize, th, v, d, evt: gr.EventData):
345
  d["layers"][0] = cv2.fillPoly(d["layers"][0], [pts], (0,0,0,255))
346
  d["composite"] = cv2.fillPoly(d["composite"], [pts], (0,0,0,255))
347
 
348
- #img = cv2.cvtColor(d["background"], cv2.COLOR_RGB2GRAY)
349
- #rows, cols = img.shape
350
- #crow, ccol = rows//2, cols//2
351
- #f = np.fft.fft2(img)
352
- #fshift = np.fft.fftshift(f)
353
- #fshift[crow-int(ksize/2):crow+int(ksize/2+1), ccol-int(ksize/2):ccol+int(ksize/2+1)] = 0
354
- #f_ishift = np.fft.ifftshift(fshift)
355
- #img_back = np.fft.ifft2(f_ishift)
356
- #img_back = np.real(img_back).astype(np.uint8)
357
 
358
 
359
  #scale = 1
@@ -370,10 +370,10 @@ def draw_mask(ksize, th, v, d, evt: gr.EventData):
370
 
371
  #grad = cv2.addWeighted(abs_grad_x, 0.5, abs_grad_y, 0.5, 0)
372
  #bw = cv2.cvtColor(cv2.threshold(255-img_back, th, 255, cv2.THRESH_BINARY)[1], cv2.COLOR_GRAY2RGB)
373
- #bw = cv2.cvtColor(255-img_back, cv2.COLOR_GRAY2RGB)
374
 
375
- #d["background"] = bw
376
- #d["composite"] = bw
377
  print(d["composite"])
378
 
379
  return gr.ImageEditor(value=d)
@@ -430,7 +430,7 @@ with gr.Blocks(css=css) as demo:
430
  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")
431
  ksize = gr.Slider(label="Kernel", value=128, minimum=0, maximum=1024, step=1)
432
  threshold = gr.Slider(label="Threshold", value=128, minimum=0, maximum=255, step=1)
433
- selector = gr.HTML(value="""<div id='select_cursor' style='width:1px;height:1px;position:absolute;border:1px dotted #ffffff;'></div>
434
  <a href='#' id='selector' onclick='this.style.fontWeight=\"bold\";
435
  document.body.appendChild(document.getElementById(\"select_cursor\"));
436
  document.getElementById(\"image_edit\").getElementsByTagName(\"canvas\")[0].oncontextmenu = function(e){e.preventDefault();}
@@ -466,12 +466,15 @@ with gr.Blocks(css=css) as demo:
466
  }
467
  document.getElementById(\"mouse\").getElementsByTagName(\"textarea\")[0].value = \"[\" + p + \"]\";
468
 
 
 
 
 
469
  document.getElementById(\"select_cursor\").style.left = e.clientX-1 + \"px\";
470
  document.getElementById(\"select_cursor\").style.top = e.clientY-1 + \"px\";
471
  }
472
  }
473
- document.getElementById(\"image_edit\").getElementsByTagName(\"canvas\")[0].ondblclick = function(e) {
474
- e.preventDefault();
475
  document.getElementById(\"mouse\").getElementsByTagName(\"textarea\")[0].value = \"[]\";
476
 
477
  document.getElementById(\"select_cursor\").style.left = 0;
 
345
  d["layers"][0] = cv2.fillPoly(d["layers"][0], [pts], (0,0,0,255))
346
  d["composite"] = cv2.fillPoly(d["composite"], [pts], (0,0,0,255))
347
 
348
+ img = cv2.cvtColor(d["background"], cv2.COLOR_RGB2GRAY)
349
+ rows, cols = img.shape
350
+ crow, ccol = rows//2, cols//2
351
+ f = np.fft.fft2(img)
352
+ fshift = np.fft.fftshift(f)
353
+ fshift[crow-int(ksize/2):crow+int(ksize/2+1), ccol-int(ksize/2):ccol+int(ksize/2+1)] = 0
354
+ f_ishift = np.fft.ifftshift(fshift)
355
+ img_back = np.fft.ifft2(f_ishift)
356
+ img_back = np.real(img_back).astype(np.uint8)
357
 
358
 
359
  #scale = 1
 
370
 
371
  #grad = cv2.addWeighted(abs_grad_x, 0.5, abs_grad_y, 0.5, 0)
372
  #bw = cv2.cvtColor(cv2.threshold(255-img_back, th, 255, cv2.THRESH_BINARY)[1], cv2.COLOR_GRAY2RGB)
373
+ bw = cv2.cvtColor(255-img_back, cv2.COLOR_GRAY2RGB)
374
 
375
+ d["background"] = bw
376
+ d["composite"] = bw
377
  print(d["composite"])
378
 
379
  return gr.ImageEditor(value=d)
 
430
  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")
431
  ksize = gr.Slider(label="Kernel", value=128, minimum=0, maximum=1024, step=1)
432
  threshold = gr.Slider(label="Threshold", value=128, minimum=0, maximum=255, step=1)
433
+ selector = gr.HTML(value="""<div id='select_cursor' style='width:1px;height:1px;position:absolute;border:3px dotted #ffffff;'></div>
434
  <a href='#' id='selector' onclick='this.style.fontWeight=\"bold\";
435
  document.body.appendChild(document.getElementById(\"select_cursor\"));
436
  document.getElementById(\"image_edit\").getElementsByTagName(\"canvas\")[0].oncontextmenu = function(e){e.preventDefault();}
 
466
  }
467
  document.getElementById(\"mouse\").getElementsByTagName(\"textarea\")[0].value = \"[\" + p + \"]\";
468
 
469
+ var evt = document.createEvent(\"Event\");
470
+ evt.initEvent(\"input\", true, false);
471
+ document.getElementById(\"mouse\").getElementsByTagName(\"textarea\")[0].dispatchEvent(evt);
472
+
473
  document.getElementById(\"select_cursor\").style.left = e.clientX-1 + \"px\";
474
  document.getElementById(\"select_cursor\").style.top = e.clientY-1 + \"px\";
475
  }
476
  }
477
+ document.getElementById(\"image_edit\").getElementsByTagName(\"canvas\")[0].onblur = function(e) {
 
478
  document.getElementById(\"mouse\").getElementsByTagName(\"textarea\")[0].value = \"[]\";
479
 
480
  document.getElementById(\"select_cursor\").style.left = 0;