KenjieDec commited on
Commit
0775a2e
·
1 Parent(s): 65f117f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -4
app.py CHANGED
@@ -78,6 +78,37 @@ def brush_stroke_mask(img, color=(255,255,255)):
78
  mask = generate_mask(height, width, img)
79
  return mask
80
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
81
  def inference(file, mode):
82
 
83
  im = cv2.imread(file, cv2.IMREAD_COLOR)
@@ -101,12 +132,11 @@ def inference(file, mode):
101
  return os.path.join("output.png")
102
  elif mode == "inpainting":
103
  im1 = cv2.imread(file, cv2.IMREAD_COLOR)
104
- im2 = imutils.resize(im1, width=2048)
105
- im3 = cv2.resize(im2, (0,0), fx=3, fy=3)
106
  model = {'name':'GPEN-Inpainting-1024', 'size':1024}
107
  faceinpainter = FaceInpainting(size=model['size'], model=model['name'], channel_multiplier=2, device='cpu')
108
- im = np.asarray(brush_stroke_mask(Image.fromarray(im3)))
109
- inpaint = faceinpainter.process(im3)
110
 
111
  cv2.imwrite(os.path.join("output.png"), inpaint)
112
  return os.path.join("output.png")
 
78
  mask = generate_mask(height, width, img)
79
  return mask
80
 
81
+ def image_resize(image, width = None, height = None, inter = cv2.INTER_AREA):
82
+ # initialize the dimensions of the image to be resized and
83
+ # grab the image size
84
+ dim = None
85
+ (h, w) = image.shape[:2]
86
+
87
+ # if both the width and height are None, then return the
88
+ # original image
89
+ if width is None and height is None:
90
+ return image
91
+
92
+ # check to see if the width is None
93
+ if width is None:
94
+ # calculate the ratio of the height and construct the
95
+ # dimensions
96
+ r = height / float(h)
97
+ dim = (int(w * r), height)
98
+
99
+ # otherwise, the height is None
100
+ else:
101
+ # calculate the ratio of the width and construct the
102
+ # dimensions
103
+ r = width / float(w)
104
+ dim = (width, int(h * r))
105
+
106
+ # resize the image
107
+ resized = cv2.resize(image, dim, interpolation = inter)
108
+
109
+ # return the resized image
110
+ return resized
111
+
112
  def inference(file, mode):
113
 
114
  im = cv2.imread(file, cv2.IMREAD_COLOR)
 
132
  return os.path.join("output.png")
133
  elif mode == "inpainting":
134
  im1 = cv2.imread(file, cv2.IMREAD_COLOR)
135
+ im2 = image_resize(im1, width = 1024)
 
136
  model = {'name':'GPEN-Inpainting-1024', 'size':1024}
137
  faceinpainter = FaceInpainting(size=model['size'], model=model['name'], channel_multiplier=2, device='cpu')
138
+ im = np.asarray(brush_stroke_mask(Image.fromarray(im2)))
139
+ inpaint = faceinpainter.process(im2)
140
 
141
  cv2.imwrite(os.path.join("output.png"), inpaint)
142
  return os.path.join("output.png")