-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #516 from computational-cell-analytics/dev
Merge dev in preparation for new release
- Loading branch information
Showing
234 changed files
with
19,091 additions
and
3,513 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,13 @@ | ||
name: micro_sam | ||
version: 0.1.0 | ||
license_file: ../LICENSE | ||
installer_type: pkg #[osx] # This will trigger pkg build on Mac Os. On windows and linux, native build will be done and this has no effect. | ||
environment: __MICROSAM_BUILD_ENV__ | ||
welcome_image: ../doc/images/micro-sam-logo.png | ||
header_image: ../doc/images/micro-sam-logo.png | ||
icon_image: ../doc/images/micro-sam-logo.png | ||
channels: | ||
- conda-forge | ||
welcome_text: Install Segment Anything for Microscopy. | ||
conclusion_text: Segment Anything for Microscopy has been installed. | ||
initialize_by_default: false | ||
name: micro_sam | ||
version: 0.0.1 | ||
license_file: ../LICENSE | ||
installer_type: pkg #[osx] # This will trigger pkg build on Mac Os. On windows and linux, native build will be done and this has no effect. | ||
environment: __MICROSAM_BUILD_ENV__ | ||
welcome_image: ../doc/images/micro-sam-logo.png | ||
header_image: ../doc/images/micro-sam-logo.png | ||
icon_image: ../doc/images/micro-sam-logo.png | ||
channels: | ||
- conda-forge | ||
welcome_text: Install Segment Anything for Microscopy. | ||
conclusion_text: Segment Anything for Microscopy has been installed. | ||
initialize_by_default: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
import os | ||
|
||
import h5py | ||
from math import ceil | ||
|
||
from micro_sam.sam_annotator import image_series_annotator, annotator_3d | ||
|
||
|
||
DATA_ROOT = "/home/anwai/data/lucchi/lucchi_test.h5" | ||
EMBEDDING_ROOT = "/home/anwai/embeddiings/test/" | ||
OUTPUT_ROOT = "/home/anwai/data/lucchi/outputs/" | ||
|
||
|
||
def _get_volume(volume_path): | ||
"""Getting the lucchi test volume""" | ||
with h5py.File(volume_path, "r") as f: | ||
raw = f["raw"][:] | ||
labels = f["labels"][:] | ||
|
||
return raw, labels | ||
|
||
|
||
def segment_volume(input_volume, embedding_path): | ||
"""Load the entire volume in the tool for segmentation. | ||
""" | ||
assert input_volume.ndim == 3 | ||
annotator_3d( | ||
image=input_volume, | ||
embedding_path=embedding_path, | ||
model_type="vit_b_em_organelles", | ||
tile_shape=None, | ||
halo=None, | ||
) | ||
|
||
|
||
def segment_each_slice(input_volume, embedding_dir, output_folder): | ||
"""Load each slice from the volume one-by-one in the tool for segmentation. | ||
""" | ||
assert input_volume.ndim == 3 | ||
|
||
all_slices = [each_slice for each_slice in input_volume] | ||
image_series_annotator( | ||
images=all_slices, | ||
output_folder=output_folder, | ||
model_type="vit_b_em_organelles", | ||
embedding_path=embedding_dir, | ||
tile_shape=None, | ||
halo=None, | ||
) | ||
|
||
|
||
def segment_each_n_slices(z_batch, input_volume, embedding_dir, output_folder): | ||
"""Load n slices from the volume one-by-one in the tool for segmentation. | ||
""" | ||
assert input_volume.ndim == 3 | ||
|
||
n_z_slices = input_volume.shape[0] | ||
all_z_idxx = int(ceil(n_z_slices / z_batch)) | ||
|
||
all_per_n_slices_volumes = [] | ||
for z_id in range(all_z_idxx): | ||
z_start = z_id * z_batch | ||
z_stop = min((z_id + 1) * z_batch, n_z_slices) | ||
|
||
batch_volume = input_volume[z_start: z_stop] | ||
all_per_n_slices_volumes.append(batch_volume) | ||
|
||
print(f"We split the volume into {len(all_per_n_slices_volumes)} sub-volumes.") | ||
image_series_annotator( | ||
images=all_per_n_slices_volumes, | ||
output_folder=output_folder, | ||
model_type="vit_b_em_organelles", | ||
embedding_path=embedding_dir, | ||
tile_shape=None, | ||
halo=None, | ||
is_volumetric=True, | ||
) | ||
|
||
|
||
def main(): | ||
raw, _ = _get_volume(DATA_ROOT) | ||
|
||
# segment_volume( | ||
# input_volume=raw, | ||
# embedding_path=os.path.join(EMBEDDING_ROOT, "lucchi_3d_volume") | ||
# ) | ||
|
||
# segment_each_slice( | ||
# input_volume=raw, | ||
# embedding_dir=os.path.join(EMBEDDING_ROOT, "lucchi_2d_per_slice"), | ||
# output_folder=os.path.join(OUTPUT_ROOT, "per_slice_segmentation") | ||
# ) | ||
|
||
segment_each_n_slices( | ||
z_batch=15, | ||
input_volume=raw, | ||
embedding_dir=os.path.join(EMBEDDING_ROOT, "lucchi_3d_per_n_slices"), | ||
output_folder=os.path.join(OUTPUT_ROOT, "per_n_slices") | ||
) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Segment Anything for Electron Microscopy | ||
|
||
This is a [Segment Anything](https://segment-anything.com/) model that was specialized for segmenting mitochondria and nuclei in electron microscopy with [micro_sam](https://github.com/computational-cell-analytics/micro-sam). | ||
This model uses a %s vision transformer as image encoder. | ||
|
||
Segment Anything is a model for interactive and automatic instance segmentation. | ||
We improve it for light microscopy by finetuning on a large and diverse microscopy dataset. | ||
It should perform well for segmenting mitochondria and nuclei in electron microscopy. It can also work well for other organelles, but was not explicitly trained for this purpose. You may get better results for other organelles (e.g. ER or Golgi) with the default Segment Anything models. | ||
|
||
See [the dataset overview](https://github.com/computational-cell-analytics/micro-sam/blob/master/doc/datasets/em_organelles_v%i.md) for further informations on the training data and the [micro_sam documentation](https://computational-cell-analytics.github.io/micro-sam/micro_sam.html) for details on how to use the model for interactive and automatic segmentation. | ||
|
||
|
||
## Validation | ||
|
||
The easiest way to validate the model is to visually check the segmentation quality for your data. | ||
If you have annotations you can use for validation you can also quantitative validation, see [here for details](https://github.com/computational-cell-analytics/micro-sam/blob/master/doc/bioimageio/validation.md). | ||
Please note that the required quality for segmentation always depends on the analysis task you want to solve. |
Oops, something went wrong.