Skip to content

Commit 9ad8317

Browse files
Implement CLI for the image series annotator
1 parent 9cac4ed commit 9ad8317

File tree

2 files changed

+44
-4
lines changed

2 files changed

+44
-4
lines changed

micro_sam/sam_annotator/image_series_annotator.py

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,51 @@ def _next_image(v):
8787
napari.run()
8888

8989

90-
def image_folder_annotator(root_folder, output_folder, pattern="*", embedding_path=None, **kwargs):
91-
image_files = sorted(glob(os.path.join(root_folder, pattern)))
90+
def image_folder_annotator(input_folder, output_folder, pattern="*", embedding_path=None, **kwargs):
91+
image_files = sorted(glob(os.path.join(input_folder, pattern)))
9292
image_series_annotator(image_files, output_folder, embedding_path, **kwargs)
9393

9494

95-
# TODO implement the CLI
9695
def main():
9796
import argparse
98-
image_folder_annotator()
97+
98+
parser = argparse.ArgumentParser(description="Annotate a series of images from a folder.")
99+
parser.add_argument(
100+
"-i", "--input_folder", required=True,
101+
help="The folder containing the image data. The data can be stored in any common format (tif, jpg, png, ...)."
102+
)
103+
parser.add_argument(
104+
"-o", "--output_folder", required=True,
105+
help="The folder where the segmentation results will be stored."
106+
)
107+
parser.add_argument(
108+
"-p", "--pattern", default="*",
109+
help="The pattern to select the images to annotator from the input folder. E.g. *.tif to annotate all tifs."
110+
"By default all files in the folder will be loaded and annotated."
111+
)
112+
parser.add_argument(
113+
"-e", "--embedding_path",
114+
help="The filepath for saving/loading the pre-computed image embeddings. "
115+
"NOTE: It is recommended to pass this argument and store the embeddings, "
116+
"otherwise they will be recomputed every time (which can take a long time)."
117+
)
118+
parser.add_argument(
119+
"--model_type", default="vit_h", help="The segment anything model that will be used, one of vit_h,l,b."
120+
)
121+
parser.add_argument(
122+
"--tile_shape", nargs="+", type=int, help="The tile shape for using tiled prediction", default=None
123+
)
124+
parser.add_argument(
125+
"--halo", nargs="+", type=int, help="The halo for using tiled prediction", default=None
126+
)
127+
128+
args = parser.parse_args()
129+
130+
if args.embedding_path is None:
131+
warnings.warn("You have not passed an embedding_path. Restarting the annotator may take a long time.")
132+
133+
image_folder_annotator(
134+
args.input_folder, args.output_folder, args.pattern,
135+
embedding_path=args.embedding_path, model_type=args.model_type,
136+
tile_shape=args.tile_shape, halo=args.halo,
137+
)

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"micro_sam.annotator_2d = micro_sam.sam_annotator.annotator_2d:main",
1717
"micro_sam.annotator_3d = micro_sam.sam_annotator.annotator_3d:main",
1818
"micro_sam.annotator_tracking = micro_sam.sam_annotator.annotator_tracking:main",
19+
"micro_sam.image_series_annotator = micro_sam.sam_annotator.image_series_annotator:main",
1920
"micro_sam.precompute_embeddings = micro_sam.util:main",
2021
]
2122
}

0 commit comments

Comments
 (0)