-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add examples for Dataset functions in documentation. (#901)
* Add example for Dataset functions in documentation. * Update docs/src/webknossos-py/examples/image_list_to_wkw.md Co-authored-by: Tom Herold <[email protected]> * Add examples to mkdocs.yml and resolve issues. * Add tests to ensure correct behaviour of examples. * Refine markdown of image stack to dataset example. * Format test_example.py with black version 23.1.0. --------- Co-authored-by: Tom Herold <[email protected]>
- Loading branch information
1 parent
d36e0b0
commit 60e78be
Showing
7 changed files
with
123 additions
and
0 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
9 changes: 9 additions & 0 deletions
9
docs/src/webknossos-py/examples/create_dataset_from_images.md
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,9 @@ | ||
# Create Dataset from Images | ||
|
||
This example shows how to [convert a folder of images into a new dataset](../../api/webknossos/dataset/dataset.md#Dataset.from_images). | ||
|
||
```python | ||
--8<-- | ||
webknossos/examples/create_dataset_from_images.py | ||
--8<-- | ||
``` |
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,16 @@ | ||
# Image Stack to Dataset | ||
|
||
This example shows how to [create a new WEBKNOSSOS dataset from a stack of images](../../api/webknossos/dataset/dataset.md#Dataset.from_images), e.g. Tiff, JPEG, etc files. | ||
|
||
There are a few assumptions we made about the images used for this example: | ||
|
||
- all images have the same size | ||
- they have the same dtype (e.g. `uint8` or `float`) | ||
- they are greyscale images from microscopy / MRI / CT scan, therefore the category is `color` | ||
- masks and segmentations are not included yet | ||
|
||
```python | ||
--8<-- | ||
webknossos/examples/image_stack_to_dataset.py | ||
--8<-- | ||
``` |
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,26 @@ | ||
from pathlib import Path | ||
|
||
from webknossos import Dataset | ||
from webknossos.dataset import COLOR_CATEGORY | ||
|
||
INPUT_DIR = Path(__file__).parent.parent / "testdata" / "tiff" | ||
OUTPUT_DIR = Path("testoutput/my_tiff_dataset") | ||
|
||
|
||
def main() -> None: | ||
"""Convert a folder of image files to a WEBKNOSSOS dataset.""" | ||
dataset = Dataset.from_images( | ||
input_path=INPUT_DIR, | ||
output_path=OUTPUT_DIR, | ||
voxel_size=(11, 11, 11), | ||
layer_category=COLOR_CATEGORY, | ||
compress=True, | ||
) | ||
|
||
print(f"Saved {dataset.name} at {dataset.path}.") | ||
|
||
# dataset.upload() | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
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,31 @@ | ||
from pathlib import Path | ||
|
||
from webknossos import Dataset | ||
from webknossos.dataset import COLOR_CATEGORY | ||
|
||
INPUT_FILES = ( | ||
Path(__file__).parent.parent / "testdata" / "tiff" / "test.0000.tiff", | ||
Path(__file__).parent.parent / "testdata" / "tiff" / "test.0001.tiff", | ||
) | ||
OUTPUT_FOLDER = Path("testoutput/tiff_dataset") | ||
|
||
|
||
def main() -> None: | ||
"""Convert a list of images into a WEBKNOSSOS dataset and directly add them as a new layer.""" | ||
dataset = Dataset( | ||
dataset_path=OUTPUT_FOLDER, | ||
voxel_size=(11, 11, 11), | ||
name="My_new_dataset", | ||
exist_ok=False, | ||
) | ||
dataset.add_layer_from_images( | ||
images=INPUT_FILES, | ||
layer_name="test", | ||
category=COLOR_CATEGORY, | ||
) | ||
|
||
# dataset.upload() | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
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