zhiweili commited on
Commit
13b9583
1 Parent(s): e581b1e

fix canny image

Browse files
Files changed (1) hide show
  1. app_haircolor_pix2pix.py +9 -8
app_haircolor_pix2pix.py CHANGED
@@ -3,6 +3,7 @@ import gradio as gr
3
  import time
4
  import torch
5
  import numpy as np
 
6
 
7
  from PIL import Image
8
  from segment_utils import(
@@ -66,7 +67,7 @@ def image_to_image(
66
  run_task_time = 0
67
  time_cost_str = ''
68
  run_task_time, time_cost_str = get_time_cost(run_task_time, time_cost_str)
69
- canny_image = CannyDetector()(input_image, 384, generate_size)
70
 
71
  cond_image = canny_image
72
  cond_scale = cond_scale1
@@ -88,14 +89,14 @@ def image_to_image(
88
 
89
  return generated_image, time_cost_str
90
 
91
- def make_inpaint_condition(image, image_mask):
92
- image = np.array(image.convert("RGB")).astype(np.float32) / 255.0
93
- image_mask = np.array(image_mask.convert("L")).astype(np.float32) / 255.0
94
 
95
- assert image.shape[0:1] == image_mask.shape[0:1], "image and image_mask must have the same image size"
96
- image[image_mask > 0.5] = -1.0 # set as masked pixel
97
- image = np.expand_dims(image, 0).transpose(0, 3, 1, 2)
98
- image = torch.from_numpy(image)
 
99
  return image
100
 
101
  def get_time_cost(run_task_time, time_cost_str):
 
3
  import time
4
  import torch
5
  import numpy as np
6
+ import cv2
7
 
8
  from PIL import Image
9
  from segment_utils import(
 
67
  run_task_time = 0
68
  time_cost_str = ''
69
  run_task_time, time_cost_str = get_time_cost(run_task_time, time_cost_str)
70
+ canny_image = custom_canny_detector(input_image)
71
 
72
  cond_image = canny_image
73
  cond_scale = cond_scale1
 
89
 
90
  return generated_image, time_cost_str
91
 
92
+ def custom_canny_detector(image):
93
+ image = np.array(image)
 
94
 
95
+ low_threshold = 100
96
+ high_threshold = 200
97
+
98
+ image = cv2.Canny(image, low_threshold, high_threshold)
99
+ image = Image.fromarray(image)
100
  return image
101
 
102
  def get_time_cost(run_task_time, time_cost_str):