Update app.py
Browse files
app.py
CHANGED
|
@@ -7,7 +7,7 @@ from matplotlib.colors import hsv_to_rgb
|
|
| 7 |
import matplotlib.pyplot as plt
|
| 8 |
import os, io, base64
|
| 9 |
from PIL import Image
|
| 10 |
-
from cellpose.io import imread
|
| 11 |
|
| 12 |
# @title Data retrieval
|
| 13 |
def download_weights():
|
|
@@ -165,15 +165,19 @@ def cellpose_segment(img_pil):
|
|
| 165 |
flows = flows.resize((Lx, Ly), resample = Image.BICUBIC)
|
| 166 |
|
| 167 |
#masks = Image.fromarray(255. * crand[masks])
|
|
|
|
|
|
|
| 168 |
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
|
| 173 |
-
|
|
|
|
|
|
|
|
|
|
| 174 |
|
| 175 |
-
b1 = gr.DownloadButton(visible=True, value =
|
| 176 |
-
b2 = gr.DownloadButton(visible=True, value =
|
| 177 |
|
| 178 |
return outpix, overlay, flows, b1, b2
|
| 179 |
|
|
@@ -203,7 +207,7 @@ with gr.Blocks(title = "Hello",
|
|
| 203 |
input_image = gr.Image(label = "Input image", type = "filepath")
|
| 204 |
send_btn = gr.Button("Run Cellpose-SAM")
|
| 205 |
with gr.Row():
|
| 206 |
-
down_btn = gr.DownloadButton("Download masks (
|
| 207 |
down_btn2 = gr.DownloadButton("Download outlines (PNG)", visible=False)
|
| 208 |
|
| 209 |
gr.HTML("""<a style="color:white;" href="https://github.com/MouseLand/cellpose" target="_blank">github page for cellpose</a>""")
|
|
|
|
| 7 |
import matplotlib.pyplot as plt
|
| 8 |
import os, io, base64
|
| 9 |
from PIL import Image
|
| 10 |
+
from cellpose.io import imread, imsave
|
| 11 |
|
| 12 |
# @title Data retrieval
|
| 13 |
def download_weights():
|
|
|
|
| 165 |
flows = flows.resize((Lx, Ly), resample = Image.BICUBIC)
|
| 166 |
|
| 167 |
#masks = Image.fromarray(255. * crand[masks])
|
| 168 |
+
#pil_masks = Image.fromarray(masks.astype('int32'))
|
| 169 |
+
#pil_masks.save(fname_mask)
|
| 170 |
|
| 171 |
+
fname_out = os.path.splitext(img_pil)[0]+"_outlines.png"
|
| 172 |
+
fname_masks = os.path.splitext(img_pil)[0]+"_masks.tif"
|
|
|
|
| 173 |
|
| 174 |
+
imsave(fname_masks, masks)
|
| 175 |
+
|
| 176 |
+
|
| 177 |
+
outpix.save(fname_out) #"outlines.png")
|
| 178 |
|
| 179 |
+
b1 = gr.DownloadButton(visible=True, value = fname_masks)
|
| 180 |
+
b2 = gr.DownloadButton(visible=True, value = fname_out) #"outlines.png")
|
| 181 |
|
| 182 |
return outpix, overlay, flows, b1, b2
|
| 183 |
|
|
|
|
| 207 |
input_image = gr.Image(label = "Input image", type = "filepath")
|
| 208 |
send_btn = gr.Button("Run Cellpose-SAM")
|
| 209 |
with gr.Row():
|
| 210 |
+
down_btn = gr.DownloadButton("Download masks (TIF)", visible=False)
|
| 211 |
down_btn2 = gr.DownloadButton("Download outlines (PNG)", visible=False)
|
| 212 |
|
| 213 |
gr.HTML("""<a style="color:white;" href="https://github.com/MouseLand/cellpose" target="_blank">github page for cellpose</a>""")
|