carsen-stringer commited on
Commit
958ea27
·
1 Parent(s): 787a5ea

updating with resize

Browse files
Files changed (1) hide show
  1. app.py +5 -5
app.py CHANGED
@@ -90,18 +90,18 @@ def image_resize(img, resize=224):
90
  img = img.astype(np.uint8)
91
  return img
92
 
93
- def cellpose_segment(img):
94
- img_input = image_resize(img.copy())
95
- masks, flows, _ = model.eval(img_input, channels=[0,0])
96
  flows = flows[0]
97
  # masks = np.zeros(img.shape[:2])
98
  # flows = np.zeros_like(img)
99
  target_size = (img_input.shape[1], img_input.shape[0])
100
- if (target_size[0]!=img.shape[1] and target_size[1]!=img.shape[0]):
101
  # scale it back to keep the orignal size
102
  masks = cv2.resize(masks.astype('uint16'), target_size, interpolation=cv2.INTER_NEAREST).astype('uint16')
103
  flows = cv2.resize(flows.astype('float32'), target_size).astype('uint8')
104
-
105
  outpix = plot_outlines(img, masks)
106
  overlay = plot_overlay(img, masks)
107
  return outpix, overlay, flows, masks
 
90
  img = img.astype(np.uint8)
91
  return img
92
 
93
+ def cellpose_segment(img_input):
94
+ img = image_resize(img_input)
95
+ masks, flows, _ = model.eval(img, channels=[0,0])
96
  flows = flows[0]
97
  # masks = np.zeros(img.shape[:2])
98
  # flows = np.zeros_like(img)
99
  target_size = (img_input.shape[1], img_input.shape[0])
100
+ if (target_size[0]!=img.shape[1] or target_size[1]!=img.shape[0]):
101
  # scale it back to keep the orignal size
102
  masks = cv2.resize(masks.astype('uint16'), target_size, interpolation=cv2.INTER_NEAREST).astype('uint16')
103
  flows = cv2.resize(flows.astype('float32'), target_size).astype('uint8')
104
+
105
  outpix = plot_outlines(img, masks)
106
  overlay = plot_overlay(img, masks)
107
  return outpix, overlay, flows, masks