Skip to content

Commit 4f4736d

Browse files
Merge pull request #26 from ajinkya-kulkarni/patch-1
Minor documentation changes
2 parents db4f5ec + b166d81 commit 4f4736d

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

development/instance_segmentation.py

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,25 @@
1-
import micro_sam.util as util
21
import napari
3-
42
from elf.io import open_file
53
from micro_sam.segment_instances import segment_instances_from_embeddings, segment_instances_sam
4+
from micro_sam.util import get_sam_model, precompute_image_embeddings
65
from micro_sam.visualization import compute_pca
76

7+
INPUT_PATH = "../examples/data/Lucchi++/Test_In"
8+
EMBEDDINGS_PATH = "../examples/embeddings/embeddings-mito2d.zarr"
9+
TIMESERIES_PATH = "../examples/data/DIC-C2DH-HeLa/train/01"
10+
EMBEDDINGS_TRACKING_PATH = "../examples/embeddings/embeddings-ctc.zarr"
811

9-
def mito_segmentation():
10-
input_path = "../examples/data/Lucchi++/Test_In"
11-
with open_file(input_path) as f:
12+
def mito_segmentation() -> None:
13+
"""Performs mito segmentation on the input image."""
14+
with open_file(INPUT_PATH) as f:
1215
raw = f["*.png"][-1, :768, :768]
1316

1417
predictor, sam = util.get_sam_model(return_sam=True)
1518

1619
print("Run SAM prediction ...")
1720
seg_sam = segment_instances_sam(sam, raw)
1821

19-
image_embeddings = util.precompute_image_embeddings(predictor, raw, "../examples/embeddings/embeddings-mito2d.zarr")
22+
image_embeddings = util.precompute_image_embeddings(predictor, raw, EMBEDDINGS_PATH)
2023
embedding_pca = compute_pca(image_embeddings["features"])
2124

2225
print("Run prediction from embeddings ...")
@@ -33,9 +36,9 @@ def mito_segmentation():
3336
napari.run()
3437

3538

36-
def cell_segmentation():
37-
path = "../examples/data/DIC-C2DH-HeLa/train/01"
38-
with open_file(path, mode="r") as f:
39+
def cell_segmentation() -> None:
40+
"""Performs cell segmentation on the input timeseries."""
41+
with open_file(TIMESERIES_PATH, mode="r") as f:
3942
timeseries = f["*.tif"][:50]
4043

4144
frame = 11
@@ -44,8 +47,8 @@ def cell_segmentation():
4447

4548
print("Run prediction from embeddings ...")
4649
image_embeddings = util.precompute_image_embeddings(
47-
predictor, timeseries, "../examples/embeddings/embeddings-ctc.zarr"
48-
)
50+
predictor, timeseries, EMBEDDINGS_TRACKING_PATH)
51+
4952
embedding_pca = compute_pca(image_embeddings["features"][frame])
5053

5154
seg, initial_seg = segment_instances_from_embeddings(

0 commit comments

Comments
 (0)