mouseland commited on
Commit
18b4441
·
verified ·
1 Parent(s): d874e72

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -12
app.py CHANGED
@@ -138,17 +138,19 @@ def cellpose_segment(img_input):
138
  flows = flows[0]
139
  # masks = np.zeros(img.shape[:2])
140
  # flows = np.zeros_like(img)
 
 
 
 
141
  target_size = (img_input.shape[1], img_input.shape[0])
142
  if (target_size[0]!=img.shape[1] or target_size[1]!=img.shape[0]):
143
  # scale it back to keep the orignal size
144
  masks = cv2.resize(masks.astype('uint16'), target_size, interpolation=cv2.INTER_NEAREST).astype('uint16')
145
- flows = cv2.resize(flows.astype('float32'), target_size).astype('uint8')
146
 
147
- outpix = plot_outlines(img_input, masks)
148
- overlay = plot_overlay(img_input, masks)
149
-
150
- crand = .2 + .8 * np.random.rand(np.max(masks.flatten()).astype('int')+1,).astype('float32')
151
- crand[0] = 0
152
 
153
  #overlay = Image.fromarray(overlay)
154
  #flows = Image.fromarray(flows)
@@ -183,17 +185,24 @@ with gr.Blocks(title = "Hello",
183
 
184
  with gr.Row():
185
  with gr.Column(scale=2):
 
 
 
 
186
  input_image = gr.Image(label = "Input image", type = "numpy")
187
  send_btn = gr.Button("Run Cellpose-SAM")
188
- with gr.Column(scale=1):
189
- down_btn = gr.DownloadButton("Download masks (TIFF)", visible=False)
190
- with gr.Column(scale=1):
191
  down_btn2 = gr.DownloadButton("Download outlines (PNG)", visible=False)
192
 
 
 
 
 
193
  with gr.Column(scale=2):
194
- img_outlines = gr.Image(label = "Output image", type = "pil")
195
- img_overlay = gr.Image(label = "Output image", type = "numpy")
196
- flows = gr.Image(label = "Output image", type = "numpy")
197
  #masks = gr.Image(label = "Output image", type = "numpy")
198
 
199
 
 
138
  flows = flows[0]
139
  # masks = np.zeros(img.shape[:2])
140
  # flows = np.zeros_like(img)
141
+
142
+ outpix = plot_outlines(img_input, masks)
143
+ overlay = plot_overlay(img_input, masks)
144
+
145
  target_size = (img_input.shape[1], img_input.shape[0])
146
  if (target_size[0]!=img.shape[1] or target_size[1]!=img.shape[0]):
147
  # scale it back to keep the orignal size
148
  masks = cv2.resize(masks.astype('uint16'), target_size, interpolation=cv2.INTER_NEAREST).astype('uint16')
149
+ #flows = cv2.resize(flows.astype('float32'), target_size).astype('uint8')
150
 
151
+
152
+ #crand = .2 + .8 * np.random.rand(np.max(masks.flatten()).astype('int')+1,).astype('float32')
153
+ #crand[0] = 0
 
 
154
 
155
  #overlay = Image.fromarray(overlay)
156
  #flows = Image.fromarray(flows)
 
185
 
186
  with gr.Row():
187
  with gr.Column(scale=2):
188
+ gr.HTML("""<div style="font-family:'Times New Roman', 'Serif'; font-size:16pt; font-weight:bold; text-align:center; color:white;">Cellpose-SAM for cellular segmentation</div>""")
189
+ gr.HTML("""<h4 style="color:white;">You may need to refresh/login for 5 minutes of free GPU compute time/day. </h4>""")
190
+ gr.HTML("""<h4 style="color:white;">"pip install cellpose" for full functionality. </h4>""")
191
+
192
  input_image = gr.Image(label = "Input image", type = "numpy")
193
  send_btn = gr.Button("Run Cellpose-SAM")
194
+ with gr.Row():
195
+ down_btn = gr.DownloadButton("Download masks (TIFF)", visible=False)
 
196
  down_btn2 = gr.DownloadButton("Download outlines (PNG)", visible=False)
197
 
198
+ gr.HTML("""<li><a href="https://github.com/MouseLand/cellpose" target="_blank">github page for cellpose</a>""")
199
+ gr.HTML("""<li><a style="color:white;" href="https://github.com/MouseLand/cellpose" target="_blank">Cellpose-SAM paper</a>""")
200
+
201
+
202
  with gr.Column(scale=2):
203
+ img_outlines = gr.Image(label = "Outlines", type = "pil")
204
+ img_overlay = gr.Image(label = "Overlay", type = "numpy")
205
+ flows = gr.Image(label = "Cellpose flows", type = "numpy")
206
  #masks = gr.Image(label = "Output image", type = "numpy")
207
 
208