Spaces:
Sleeping
Sleeping
Upload 10 files
Browse files- .gitattributes +3 -0
- 13d_128_img.png +0 -0
- README.md +0 -14
- cellpose_train_folder_qpi_live_0520 +3 -0
- crl_112_img.png +0 -0
- gradio_app.py +120 -0
- packages.txt +9 -0
- psi_train_00021_img.png +0 -0
- requirements.txt +7 -0
- zangle_0506_00641_img.png +3 -0
- zangle_0520_00221_img.png +3 -0
.gitattributes
CHANGED
|
@@ -33,3 +33,6 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
+
cellpose_train_folder_qpi_live_0520 filter=lfs diff=lfs merge=lfs -text
|
| 37 |
+
zangle_0506_00641_img.png filter=lfs diff=lfs merge=lfs -text
|
| 38 |
+
zangle_0520_00221_img.png filter=lfs diff=lfs merge=lfs -text
|
13d_128_img.png
ADDED
|
README.md
CHANGED
|
@@ -1,14 +0,0 @@
|
|
| 1 |
-
---
|
| 2 |
-
title: Cellphase Demo
|
| 3 |
-
emoji: 🚀
|
| 4 |
-
colorFrom: yellow
|
| 5 |
-
colorTo: gray
|
| 6 |
-
sdk: gradio
|
| 7 |
-
sdk_version: 5.42.0
|
| 8 |
-
app_file: app.py
|
| 9 |
-
pinned: false
|
| 10 |
-
license: mit
|
| 11 |
-
short_description: Cellphase Private Demo
|
| 12 |
-
---
|
| 13 |
-
|
| 14 |
-
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cellpose_train_folder_qpi_live_0520
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:0955525f16f0332c5ae14f1988c9622f26b878e4de74386917ad7a987a87cb83
|
| 3 |
+
size 26566572
|
crl_112_img.png
ADDED
|
gradio_app.py
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import numpy as np
|
| 3 |
+
import cv2
|
| 4 |
+
import os
|
| 5 |
+
import tifffile
|
| 6 |
+
from PIL import Image
|
| 7 |
+
from cellpose import models
|
| 8 |
+
|
| 9 |
+
# === Load your trained model ===
|
| 10 |
+
model = models.CellposeModel(pretrained_model="cellphase_train_folder_qpi_0520", gpu=True)
|
| 11 |
+
|
| 12 |
+
# === Image Loader ===
|
| 13 |
+
def load_image_robust(uploaded_file):
|
| 14 |
+
ext = os.path.splitext(uploaded_file.name)[-1].lower()
|
| 15 |
+
if ext in [".tif", ".tiff"]:
|
| 16 |
+
image = tifffile.imread(uploaded_file.name)
|
| 17 |
+
else:
|
| 18 |
+
image = cv2.imread(uploaded_file.name, cv2.IMREAD_UNCHANGED)
|
| 19 |
+
if image is None:
|
| 20 |
+
raise ValueError("Failed to load the uploaded image.")
|
| 21 |
+
return image
|
| 22 |
+
|
| 23 |
+
# === Gamma Correction ===
|
| 24 |
+
def apply_gamma_correction(image, gamma):
|
| 25 |
+
image = image.astype(np.float32)
|
| 26 |
+
image = image - image.min()
|
| 27 |
+
image = image / (image.max() + 1e-8)
|
| 28 |
+
image = np.power(image, gamma)
|
| 29 |
+
image = (image * 255).astype(np.uint8)
|
| 30 |
+
return image
|
| 31 |
+
|
| 32 |
+
# === Show gamma corrected preview ===
|
| 33 |
+
def update_gamma_display(file, use_gamma, gamma_val):
|
| 34 |
+
if file is None:
|
| 35 |
+
return None
|
| 36 |
+
img = load_image_robust(file)
|
| 37 |
+
if img.ndim == 3:
|
| 38 |
+
img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
|
| 39 |
+
if use_gamma:
|
| 40 |
+
img = apply_gamma_correction(img, gamma_val)
|
| 41 |
+
else:
|
| 42 |
+
img = img.astype(np.float32)
|
| 43 |
+
img = (img - img.min()) / (img.max() + 1e-8)
|
| 44 |
+
img = (img * 255).astype(np.uint8)
|
| 45 |
+
return img
|
| 46 |
+
|
| 47 |
+
import tempfile
|
| 48 |
+
|
| 49 |
+
def segment_image(file, use_gamma, gamma_val, diameter, flow_threshold):
|
| 50 |
+
image = load_image_robust(file)
|
| 51 |
+
|
| 52 |
+
if image.ndim == 3:
|
| 53 |
+
image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
|
| 54 |
+
|
| 55 |
+
if use_gamma:
|
| 56 |
+
image = apply_gamma_correction(image, gamma_val)
|
| 57 |
+
else:
|
| 58 |
+
image = image.astype(np.float32)
|
| 59 |
+
image = (image - image.min()) / (image.max() + 1e-8)
|
| 60 |
+
image = (image * 255).astype(np.uint8)
|
| 61 |
+
|
| 62 |
+
masks = model.eval(image, diameter=diameter, flow_threshold=flow_threshold, channels=[0, 0])[0]
|
| 63 |
+
masks = (masks / (masks.max() + 1e-8) * 255).astype(np.uint8)
|
| 64 |
+
|
| 65 |
+
# Save as grayscale PNG to temporary file
|
| 66 |
+
output_path = os.path.join(tempfile.gettempdir(), "predicted_mask.png")
|
| 67 |
+
Image.fromarray(masks).convert("L").save(output_path)
|
| 68 |
+
|
| 69 |
+
# Visualization
|
| 70 |
+
masks_for_overlay = (masks % 256).astype(np.uint8)
|
| 71 |
+
overlay = cv2.applyColorMap(masks_for_overlay, cv2.COLORMAP_JET)
|
| 72 |
+
overlay = cv2.addWeighted(cv2.cvtColor(image, cv2.COLOR_GRAY2BGR), 0.5, overlay, 0.5, 0)
|
| 73 |
+
|
| 74 |
+
return overlay, temp_mask_path
|
| 75 |
+
|
| 76 |
+
# === Description ===
|
| 77 |
+
description = """
|
| 78 |
+
**CellPhase1.0** is developed and released by the **Center for Label-free Imaging and Multiscale Biophotonics**, Beckman Institute, University of Illinois Urbana-Champaign.
|
| 79 |
+
Supported by the **National Institute of Health/National Institute of Biomedical Imaging and Bioengineering**, Award #: **P41EB031772**.
|
| 80 |
+
|
| 81 |
+
For inquiries, contact **Sourya Sengupta** at [souryas2@illinois.edu](mailto:souryas2@illinois.edu)
|
| 82 |
+
Source code available on [GitHub](https://github.com/...)
|
| 83 |
+
|
| 84 |
+
**Please cite**: "Sengupta et al., CellPhase1.0" if you use this in your work.
|
| 85 |
+
**License**: Open Source – [MIT License](https://opensource.org/licenses/MIT)
|
| 86 |
+
"""
|
| 87 |
+
|
| 88 |
+
# === Gradio Interface ===
|
| 89 |
+
with gr.Blocks(title="CellPhase1.0 - Cell Segmentation Tool") as demo:
|
| 90 |
+
gr.Markdown(description)
|
| 91 |
+
|
| 92 |
+
with gr.Row():
|
| 93 |
+
with gr.Column():
|
| 94 |
+
file_input = gr.File(label="Upload Cell Image", file_types=[".jpg", ".jpeg", ".png", ".tif", ".tiff"])
|
| 95 |
+
|
| 96 |
+
use_gamma = gr.Checkbox(label="Use Gamma Correction", value=False)
|
| 97 |
+
gamma_slider = gr.Slider(0.2, 2.5, value=1.0, step=0.1, label="Gamma Value")
|
| 98 |
+
|
| 99 |
+
gamma_preview = gr.Image(type="numpy", label="Gamma Corrected Image Preview")
|
| 100 |
+
|
| 101 |
+
diameter_slider = gr.Slider(10, 120, value=50, step=5, label="Diameter")
|
| 102 |
+
flow_slider = gr.Slider(0.2, 1.0, value=0.6, step=0.1, label="Flow Threshold")
|
| 103 |
+
run_btn = gr.Button("Run Segmentation")
|
| 104 |
+
|
| 105 |
+
with gr.Column():
|
| 106 |
+
overlay_output = gr.Image(type="numpy", label="Segmentation Overlay")
|
| 107 |
+
mask_output = gr.File(label="Download Grayscale Mask (.png)")
|
| 108 |
+
|
| 109 |
+
|
| 110 |
+
# === Live gamma preview update ===
|
| 111 |
+
file_input.change(update_gamma_display, inputs=[file_input, use_gamma, gamma_slider], outputs=gamma_preview)
|
| 112 |
+
gamma_slider.change(update_gamma_display, inputs=[file_input, use_gamma, gamma_slider], outputs=gamma_preview)
|
| 113 |
+
use_gamma.change(update_gamma_display, inputs=[file_input, use_gamma, gamma_slider], outputs=gamma_preview)
|
| 114 |
+
|
| 115 |
+
# === Button triggers segmentation ===
|
| 116 |
+
run_btn.click(fn=segment_image, inputs=[file_input, use_gamma, gamma_slider, diameter_slider, flow_slider],
|
| 117 |
+
outputs=[overlay_output, mask_output])
|
| 118 |
+
|
| 119 |
+
if __name__ == "__main__":
|
| 120 |
+
demo.launch(share=True)
|
packages.txt
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
git
|
| 2 |
+
git-lfs
|
| 3 |
+
ffmpeg
|
| 4 |
+
libsm6
|
| 5 |
+
libxext6
|
| 6 |
+
libglib2.0-0
|
| 7 |
+
libgl1
|
| 8 |
+
cmake
|
| 9 |
+
rsync
|
psi_train_00021_img.png
ADDED
|
requirements.txt
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Core dependencies
|
| 2 |
+
cellpose==3.1.1
|
| 3 |
+
#opencv-python-headless==4.8.0.76
|
| 4 |
+
tifffile
|
| 5 |
+
matplotlib
|
| 6 |
+
roifile
|
| 7 |
+
|
zangle_0506_00641_img.png
ADDED
|
Git LFS Details
|
zangle_0520_00221_img.png
ADDED
|
Git LFS Details
|