KenjieDec commited on
Commit
715fe0c
·
1 Parent(s): d341489

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -31
app.py CHANGED
@@ -78,36 +78,11 @@ def brush_stroke_mask(img, color=(255,255,255)):
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
 
@@ -132,7 +107,7 @@ def inference(file, mode):
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
  im3 = np.asarray(brush_stroke_mask(Image.fromarray(im2)))
 
78
  mask = generate_mask(height, width, img)
79
  return mask
80
 
81
+ def resize(self,image,width = 1024):
82
+ aspect_ratio = float(image.shape[1])/float(image.shape[0])
83
+ height = width/aspect_ratio
84
+ image = cv2.resize(image, (int(height),int(width)))
85
+ return image
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
86
 
87
  def inference(file, mode):
88
 
 
107
  return os.path.join("output.png")
108
  elif mode == "inpainting":
109
  im1 = cv2.imread(file, cv2.IMREAD_COLOR)
110
+ im2 = resize(im1, width = 1024)
111
  model = {'name':'GPEN-Inpainting-1024', 'size':1024}
112
  faceinpainter = FaceInpainting(size=model['size'], model=model['name'], channel_multiplier=2, device='cpu')
113
  im3 = np.asarray(brush_stroke_mask(Image.fromarray(im2)))