srijaydeshpande commited on
Commit
6619f95
·
verified ·
1 Parent(s): b73ccb5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -9
app.py CHANGED
@@ -237,16 +237,16 @@ def predict_wsi(image):
237
  @spaces.GPU(duration=120)
238
  def segment_image(image):
239
  img = image
240
- img = np.asarray(img)
241
-
242
- # pad if necessary
243
- min_side = 768
244
- h, w = img.shape[:2]
245
- pad_h = max(0, min_side - h)
246
- pad_w = max(0, min_side - w)
247
- if(pad_h > 0 or pad_w > 0):
248
- img = np.pad(img, ((0, pad_h), (0, pad_w), (0, 0)), mode='constant', constant_values=0)
249
 
 
250
  if (np.max(img) > 100):
251
  img = img / 255.0
252
  transform = T.Compose([T.ToTensor()])
 
237
  @spaces.GPU(duration=120)
238
  def segment_image(image):
239
  img = image
240
+
241
+ # resize if necessary
242
+ min_side=768
243
+ w, h = image.size
244
+ if min(w, h) < min_side:
245
+ scale = min_side / min(w, h)
246
+ new_w, new_h = int(w * scale), int(h * scale)
247
+ img = img.resize((new_w, new_h), Image.ANTIALIAS)
 
248
 
249
+ img = np.asarray(img)
250
  if (np.max(img) > 100):
251
  img = img / 255.0
252
  transform = T.Compose([T.ToTensor()])