tombetthauser commited on
Commit
a05b949
Β·
1 Parent(s): 2db9643

Added canny edges tab

Browse files
Files changed (1) hide show
  1. app.py +43 -1
app.py CHANGED
@@ -368,7 +368,49 @@ with gr.Blocks() as beta:
368
 
369
 
370
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
371
  # ----- Launch Tabs -----------------------------------------------------------------
372
 
373
- tabbed_interface = gr.TabbedInterface([new_welcome, advanced_tab, beta], ["Welcome", "Advanced", "Beta"])
374
  tabbed_interface.launch()
 
368
 
369
 
370
 
371
+
372
+
373
+ # ----- Canny Edge Tab -----------------------------------------------------------------
374
+
375
+ from PIL import Image
376
+ # import gradio as gr
377
+ import numpy as np
378
+ import cv2
379
+
380
+ # Define a function to process the uploaded image
381
+ def canny_process_image(input_image, input_low_threshold, input_high_threshold, input_invert):
382
+ # Convert the input image to a NumPy array
383
+ np_image = np.array(input_image)
384
+
385
+ output_image = input_image # For example, just return the input image
386
+ numpy_image = np.array(output_image)
387
+ # Return the processed image
388
+
389
+ low_threshold = 100
390
+ high_threshold = 200
391
+ canny_1 = cv2.Canny(numpy_image, input_low_threshold, input_high_threshold)
392
+ canny_1 = canny_1[:, :, None]
393
+ canny_1 = np.concatenate([canny_1, canny_1, canny_1], axis=2)
394
+ if input_invert:
395
+ canny_1 = 255 - canny_1
396
+ canny_2 = Image.fromarray(canny_1)
397
+
398
+ return np.array(canny_2)
399
+
400
+ # Define the input and output interfaces
401
+ canny_input_image = gr.inputs.Image()
402
+ canny_input_low_threshold = gr.inputs.Slider(minimum=0, maximum=1000, step=1, label="Lower Threshold:", default=100)
403
+ canny_input_high_threshold = gr.inputs.Slider(minimum=0, maximum=1000, step=1, label="Upper Threshold:", default=200)
404
+ canny_input_invert = gr.inputs.Checkbox(label="Invert Image")
405
+
406
+ canny_outputs = gr.outputs.Image(type="numpy")
407
+
408
+ # Create the Gradio interface
409
+ canny_interface = gr.Interface(fn=canny_process_image, inputs=[canny_input_image, canny_input_low_threshold, canny_input_high_threshold, canny_input_invert], outputs=canny_outputs, title='Canny Edge Tracing', allow_flagging='never')
410
+
411
+
412
+
413
  # ----- Launch Tabs -----------------------------------------------------------------
414
 
415
+ tabbed_interface = gr.TabbedInterface([new_welcome, advanced_tab, beta, canny_interface], ["Welcome", "Advanced", "Beta", "Edges"])
416
  tabbed_interface.launch()