diff --git a/docs/source/documentation/brainglobe-segmentation/index.md b/docs/source/documentation/brainglobe-segmentation/index.md index 2322c3a1..bc8bdea6 100644 --- a/docs/source/documentation/brainglobe-segmentation/index.md +++ b/docs/source/documentation/brainglobe-segmentation/index.md @@ -26,8 +26,6 @@ Alternatively, the plugin can be installed into a Python environment with `pip i ```{toctree} :maxdepth: 1 user-guide/index -user-guide/segmenting-1d-tracks -user-guide/segmenting-3d-structures user-guide/analysing-external-segmentation ``` diff --git a/docs/source/documentation/brainglobe-segmentation/user-guide/analysing-external-segmentation.md b/docs/source/documentation/brainglobe-segmentation/user-guide/analysing-external-segmentation.md index fb664cda..f8b853b0 100644 --- a/docs/source/documentation/brainglobe-segmentation/user-guide/analysing-external-segmentation.md +++ b/docs/source/documentation/brainglobe-segmentation/user-guide/analysing-external-segmentation.md @@ -51,8 +51,8 @@ At this point you could load a layer segmented previously and saved to disk add the region/points from the layer to the `brainglobe-segmentation` analysis list (in the same way as if it had been analysed manually within `brainglobe-segmentation`). - Follow the instructions for either: - - [1D track analysis](segmenting-1d-tracks) - - [2/3D region analysis](segmenting-3d-structures) + - [1D track analysis](../../../tutorials/segmenting-1d-tracks) + - [2/3D region analysis](../../../tutorials/segmenting-3d-structures) :::{note} All data will be saved into your brainreg output directory diff --git a/docs/source/documentation/brainglobe-segmentation/user-guide/index.md b/docs/source/documentation/brainglobe-segmentation/user-guide/index.md index a82c9260..9070645b 100644 --- a/docs/source/documentation/brainglobe-segmentation/user-guide/index.md +++ b/docs/source/documentation/brainglobe-segmentation/user-guide/index.md @@ -48,7 +48,7 @@ enhancement, contrast limits (right-click for finer control) and the colormap us The buttons directly below the layers can be used to rotate the data, reset the view and view in 3D. For information on how to segment specific types of structure, see: -- [Segmenting 1D tracks](./segmenting-1d-tracks) -- [Segmenting 2/3D structures](segmenting-3d-structures) +- [Segmenting 1D tracks](../../../tutorials/segmenting-1d-tracks) +- [Segmenting 2/3D structures](../../../tutorials/segmenting-3d-structures) - [Analysing segmentation from other napari plugins](analysing-external-segmentation) diff --git a/docs/source/documentation/brainglobe-segmentation/user-guide/segmenting-1d-tracks.md b/docs/source/documentation/brainglobe-segmentation/user-guide/segmenting-1d-tracks.md deleted file mode 100644 index 9098eab1..00000000 --- a/docs/source/documentation/brainglobe-segmentation/user-guide/segmenting-1d-tracks.md +++ /dev/null @@ -1,66 +0,0 @@ -# Segmenting 1D tracks - -:::{hint} -For more information about how to process silicon probe tracks, please see [Silicon probe tracking](/tutorials/silicon-probe-tracking). -::: - -To segment a 1D track, such as a fibre track, or a silicone probe track, select the `Track tracing` button in the `Segmentation panel`. - -![Segmenting a 1D track](../images/segment_1d.webp) - -Then: - -* Click the `Add track` button -* If required, rename the track (by selecting the `track_0` text) -* Navigate to where you want to draw your region of interest. -* Make sure the add points mode is activated (by selecting the `+` symbol) -* Trace your track by adding points along it. You can add as many, or as few as you like, and this can be done in 3D by changing the viewer plane as you go along. - -:::{caution} -Make sure you select the points in the order you wish them to be joined -::: - -* Repeat the above for each track you wish to trace -* If the brain surface is damaged, you may not be able to trace perfectly from the surface. If you want to add an -additional first point at the surface of the brain, click `Add surface points`. Selecting this option will add an -additional point at the closest part of the brain surface to the first point, so that the track starts there. -* The points can then be joined using spline interpolation by clicking `Trace tracks`. You can change: -* `Summarise` - Defaults to on, this will save a csv file, showing the brain area for each part of the interpolated -track (determined by `Spline points` ) -* `Save tracing` - Defaults to off. This will save your segmentation layer at the same time as running the analysis - (this may make your analysis take longer) -* `Fit degree` - What order spline fit to use (the default is 3, cubic) -* `Spline smoothing` - How closely or not to fit the points (lower numbers fit more closely, for a less smooth interpolation) -* `Spline points` - This doesn't affect the interpolation, but determines how many points are sampled from the interpolation (used for the summary) -* `Add surface points` - If the brain surface is damaged, you may not be able to trace perfectly from the surface. -Selecting this option will add an additional point at the closest part of the brain surface to the first point, so that the track starts there - -You will then see the track fit appear in the napari window, and a `.csv` file will be saved, showing the brain region -for every spline point along the track. - -You can also use `Save` independently of the analysis to save your points to be reloaded at a later date, and if you -loaded your data in atlas space, -you can also export the track to [brainrender](/documentation/brainrender/index). The file will be -saved as e.g. `track_0.npy`. Using the Python API, you can visualise the track as follows: - - -```python -from brainrender import Scene -from brainrender.actors import Points -from myterial import blue - -file = ("/path/to/track_0.npy") - -scene = Scene() -scene.add(Points(file, colors=blue, radius=100, alpha=0.7)) -scene.render() -``` - -:::{note} -All data will be saved into your brainreg output directory -::: - -:::{hint} -For more information about how to use automated methods to segment your feature of interest, please see -[Analysing segmentation from other napari plugins](./analysing-external-segmentation). -::: \ No newline at end of file diff --git a/docs/source/documentation/brainglobe-segmentation/user-guide/segmenting-3d-structures.md b/docs/source/documentation/brainglobe-segmentation/user-guide/segmenting-3d-structures.md deleted file mode 100644 index 5fee6106..00000000 --- a/docs/source/documentation/brainglobe-segmentation/user-guide/segmenting-3d-structures.md +++ /dev/null @@ -1,39 +0,0 @@ -# Segmenting 2/3D structures - -To segment a 3D (or 2D) structure, such as an injection site, select the `Region Segmentation` button in the -`Segmentation panel`. - -![Segmenting a 2/3D structure](../images/segment_3d.webp) - -Then: - -* Click the `Add region` buttons -* If required, rename this region (by selecting the e.g. `region_0` text) -* Navigate to where you want to draw your region of interest. -* Choose a brush size (top left box). N.B. this is in 3D. -* Make sure painting mode is activated (by selecting the paintbrush, top left). You can go back to the navigation -* mode by selecting the magnifying glass. -* Colour in your region that you want to segment, ensuring that you make a - - solid object. - -* Add a new region if required (`Add region`) -* Repeat above for each region you wish to segment. -* Click `Analyse regions` to analyse the spatial distribution of the regions you have drawn. - * If `Calculate volumes` is selected, the volume of each brain area included in the segmented region will be calculated and saved. - * If `Summarise volumes` is selected, then each region will be summarised (centers, volumes etc) - * If `Save segmentation` is selected, then the segmented layer will be saved at the same time as the analysis is run -(this may make your analysis take longer) - -You can also use `Save` independently of the analysis to save your regions to be reloaded at a later date, and if you -loaded your data in atlas -space, you can also export the regions to [brainrender](/documentation/brainrender/index). - -:::{note} -All data will be saved into your brainreg output directory -::: - -:::{hint} -For more information about how to use automated methods to segment your feature of interest, please see -[Analysing segmentation from other napari plugins](./analysing-external-segmentation). -::: \ No newline at end of file diff --git a/docs/source/tutorials/images/brainglobe-segmentation-1d-icon.png b/docs/source/tutorials/images/brainglobe-segmentation-1d-icon.png new file mode 100644 index 00000000..012c798a Binary files /dev/null and b/docs/source/tutorials/images/brainglobe-segmentation-1d-icon.png differ diff --git a/docs/source/tutorials/images/brainglobe-segmentation-3d-icon.png b/docs/source/tutorials/images/brainglobe-segmentation-3d-icon.png new file mode 100644 index 00000000..694fdc3b Binary files /dev/null and b/docs/source/tutorials/images/brainglobe-segmentation-3d-icon.png differ diff --git a/docs/source/tutorials/images/brainglobe-segmentation/brainglobe-segmentation-added-new-region.png b/docs/source/tutorials/images/brainglobe-segmentation/brainglobe-segmentation-added-new-region.png new file mode 100644 index 00000000..f10312d6 Binary files /dev/null and b/docs/source/tutorials/images/brainglobe-segmentation/brainglobe-segmentation-added-new-region.png differ diff --git a/docs/source/tutorials/images/brainglobe-segmentation/brainglobe-segmentation-added-new-track.png b/docs/source/tutorials/images/brainglobe-segmentation/brainglobe-segmentation-added-new-track.png new file mode 100644 index 00000000..11afe22b Binary files /dev/null and b/docs/source/tutorials/images/brainglobe-segmentation/brainglobe-segmentation-added-new-track.png differ diff --git a/docs/source/tutorials/images/brainglobe-segmentation/brainglobe-segmentation-added-points.png b/docs/source/tutorials/images/brainglobe-segmentation/brainglobe-segmentation-added-points.png new file mode 100644 index 00000000..a746592c Binary files /dev/null and b/docs/source/tutorials/images/brainglobe-segmentation/brainglobe-segmentation-added-points.png differ diff --git a/docs/source/tutorials/images/brainglobe-segmentation/brainglobe-segmentation-fitted-points.png b/docs/source/tutorials/images/brainglobe-segmentation/brainglobe-segmentation-fitted-points.png new file mode 100644 index 00000000..18906418 Binary files /dev/null and b/docs/source/tutorials/images/brainglobe-segmentation/brainglobe-segmentation-fitted-points.png differ diff --git a/docs/source/tutorials/images/brainglobe-segmentation/brainglobe-segmentation-loaded-data.png b/docs/source/tutorials/images/brainglobe-segmentation/brainglobe-segmentation-loaded-data.png new file mode 100644 index 00000000..30d819f9 Binary files /dev/null and b/docs/source/tutorials/images/brainglobe-segmentation/brainglobe-segmentation-loaded-data.png differ diff --git a/docs/source/tutorials/images/brainglobe-segmentation/brainglobe-segmentation-open-plugin.png b/docs/source/tutorials/images/brainglobe-segmentation/brainglobe-segmentation-open-plugin.png new file mode 100644 index 00000000..d16b1b9d Binary files /dev/null and b/docs/source/tutorials/images/brainglobe-segmentation/brainglobe-segmentation-open-plugin.png differ diff --git a/docs/source/tutorials/images/brainglobe-segmentation/brainglobe-segmentation-painted-new-region.png b/docs/source/tutorials/images/brainglobe-segmentation/brainglobe-segmentation-painted-new-region.png new file mode 100644 index 00000000..5a76f613 Binary files /dev/null and b/docs/source/tutorials/images/brainglobe-segmentation/brainglobe-segmentation-painted-new-region.png differ diff --git a/docs/source/documentation/brainglobe-segmentation/images/segment_1d.webp b/docs/source/tutorials/images/segment_1d.webp similarity index 100% rename from docs/source/documentation/brainglobe-segmentation/images/segment_1d.webp rename to docs/source/tutorials/images/segment_1d.webp diff --git a/docs/source/documentation/brainglobe-segmentation/images/segment_3d.webp b/docs/source/tutorials/images/segment_3d.webp similarity index 100% rename from docs/source/documentation/brainglobe-segmentation/images/segment_3d.webp rename to docs/source/tutorials/images/segment_3d.webp diff --git a/docs/source/tutorials/index.md b/docs/source/tutorials/index.md index 050e2f3c..ec284806 100644 --- a/docs/source/tutorials/index.md +++ b/docs/source/tutorials/index.md @@ -17,6 +17,20 @@ Visualise atlas data in napari :link-type: doc Registering a whole-brain dataset to an atlas. ::: + +:::{grid-item-card} {fas}`brain;sd-text-primary` Track segmentation +:img-bottom: images/brainglobe-segmentation-1d-icon.png +:link: segmenting-1d-tracks +:link-type: doc +Manually segmenting a 1d track. +::: + +:::{grid-item-card} {fas}`brain;sd-text-primary` Structure segmentation +:img-bottom: images/brainglobe-segmentation-3d-icon.png +:link: segmenting-3d-structures +:link-type: doc +Manually segmenting a 3d structure +::: :::: ## Specific applications @@ -54,6 +68,8 @@ Whole brain cell detection and registration :hidden: visualise-atlas-napari tutorial-whole-brain-registration +segmenting-1d-tracks +segmenting-3d-structures silicon-probe-tracking tracing-tracking cellfinder-cli/index diff --git a/docs/source/tutorials/segmenting-1d-tracks.md b/docs/source/tutorials/segmenting-1d-tracks.md new file mode 100644 index 00000000..5ac24b89 --- /dev/null +++ b/docs/source/tutorials/segmenting-1d-tracks.md @@ -0,0 +1,67 @@ +# Segmenting a 1D track + +In this tutorial, you will use the [brainglobe-segmentation](../documentation/brainglobe-segmentation/index.md) plugin for [napari](https://napari.org) to segment a 1D track, such as a fibre track, or a silicon probe track. As a prerequisite, you will need to have registered your data to an atlas [using `brainreg`](../documentation/brainreg/index.md) and know what folder you saved this in (your "`brainreg` output directory"). If you don't have this, please follow [our registration tutorial](./tutorial-whole-brain-registration.md) first. + +The focus of this tutorial is simply to successfully register a single, straight 1D track. For more information about how to process silicon probe tracks, please see [Silicon probe tracking](/tutorials/silicon-probe-tracking). + +:::{note} +You will need `napari` installed on your computer - please follow [`napari`'s installation instructions](https://napari.org/stable/tutorials/fundamentals/installation.html) to do so (including their recommendation to use a `conda` environment). +::: + +1. Open `napari`. +2. Install `brainglobe-segmentation` by selecting `Plugins > Install/Uninstall plugins` and searching for `brainglobe-segmentation` in the searchbox. If it is not installed yet, click on the `Install` button. + +:::{caution} +On Silicon Macs you may have to run `conda install hdf5` on the command line (in your conda environment) first for the installation to be successful. +::: + +3. Open the `brainglobe-segmentation` widget by selecting `Plugins > Region/track segmentation (brainglobe-segmentation)` in the napari menu bar near the top left of the window. +![brainglobe segmentation widget](./images/brainglobe-segmentation/brainglobe-segmentation-open-plugin.png) + +**The brainglobe segmentation widget appears on the right-hand side of the window.** + +4. Load your registered data in atlas space by clicking on `Load project (atlas space)` and navigating to your `brainreg` output directory. +5. If required, adjust the contrast on the registered image by selecting the `Registered Image` layer on the left of the screen, and clicking on `Autocontrast: once` on the top left of the screen. +6. Select the `Track tracing` button in the `Segmentation` panel. +7. Click the `Add track` button. + +![Segmenting a 1D track](./images/brainglobe-segmentation/brainglobe-segmentation-added-new-track.png) +**A new Points layer named `track_0` appears on the left hand side.** + +8. If required, rename the track (by selecting the `track_0` text). +9. Navigate in the image to where you want to draw your track. +10. Make sure the add points mode is activated (by selecting the `+` symbol on the top left - find out [more about how to add/delete/select points in napari](https://napari.org/stable/howtos/layers/points.html#adding-deleting-and-selecting-points)). +11. Trace your track by clicking along it. You can add as many, or as few, points as you like, and this can be done in 3D by changing the viewer plane as you go along. + +![Segmenting a 1D track](./images/brainglobe-segmentation/brainglobe-segmentation-added-points.png) + +**Points appear where you've clicked in the image** + +:::{caution} +Make sure you select the points in the order you wish them to be joined. +::: + +12. (Optional) If you want to add an additional first point exactly at the surface of the brain, click `Add surface points`. Selecting this option will add an additional point at the closest part of the brain surface (based on the registration) to the first point, so that the track starts there. +13. Join the points using spline interpolation by clicking `Trace tracks`. You can change: + * `Summarise` - Defaults to on, this will save a csv file, showing the brain area for each part of the interpolated track (determined by `Spline points` ) + * `Save tracing` - Defaults to off. This will save your segmentation layer at the same time as running the analysis + (this may make your analysis take longer) + * `Fit degree` - What order spline fit to use (the default is 3, cubic) + * `Spline smoothing` - How closely or not to fit the points (lower numbers fit more closely, for a less smooth interpolation) + * `Spline points` - This doesn't affect the interpolation, but determines how many points are sampled from the interpolation (used for the summary) + * `Add surface points` - Selecting this option will add an additional point at the closest part of the brain surface to the first point, so that the track starts there. + + +![Segmenting a 1D track](./images/brainglobe-segmentation/brainglobe-segmentation-fitted-points.png) +**A new Points layer containing the fitted points named `track_0_fit` appears on the left hand side and in the napari window, and a `.csv` file will be saved, showing the brain region for every spline point along the track.** + +:::{note} +All data will be saved into your brainreg output directory +::: + +14. (Optional) Use the `Save` button to save your points to be reloaded at a later date. + +:::{hint} +For more information about how to use automated methods to segment your feature of interest, please see [Analysing segmentation from other napari plugins](../documentation/brainglobe-segmentation/user-guide/analysing-external-segmentation). +For full information on how to use brainglobe-segmentation, please see the [brainglobe-segmentation page](/documentation/brainglobe-segmentation/index) +::: diff --git a/docs/source/tutorials/segmenting-3d-structures.md b/docs/source/tutorials/segmenting-3d-structures.md new file mode 100644 index 00000000..c518e59d --- /dev/null +++ b/docs/source/tutorials/segmenting-3d-structures.md @@ -0,0 +1,55 @@ +# Segmenting 2/3D structures + +In this tutorial, you will use the [brainglobe-segmentation](../documentation/brainglobe-segmentation/index.md) plugin for [napari](https://napari.org) to segment a a 3D (or 2D) structure, such as an injection site. As a prerequisite, you will need to have registered your data to an atlas [using `brainreg`](../documentation/brainreg/index.md) and know what folder you saved this in (your "`brainreg` output directory"). If you don't have this, please follow [our registration tutorial](./tutorial-whole-brain-registration.md) first. + +:::{note} +You will need `napari` installed on your computer - please follow [`napari`'s installation instructions](https://napari.org/stable/tutorials/fundamentals/installation.html) to do so (including their recommendation to use a `conda` environment). +::: + +1. Open `napari`. +2. Install `brainglobe-segmentation` by selecting `Plugins > Install/Uninstall plugins` and searching for `brainglobe-segmentation` in the searchbox. If it is not installed yet, click on the `Install` button. + +:::{caution} +On Silicon Macs you may have to `conda install hdf5` first for the installation to be successful. +::: + +3. Open the `brainglobe-segmentation` widget by selecting `Plugins > Region/track segmentation (brainglobe-segmentation)` in the napari menu bar near the top left of the window. +![The brainglobe-segmentation widget appears](./images/brainglobe-segmentation/brainglobe-segmentation-open-plugin.png) + +**The brainglobe segmentation widget appears on the right-hand side of the window.** + +4. Load your registered data in atlas space by clicking on `Load project (atlas space)` and navigating to your `brainreg` output directory. +5. If required, adjust the contrast on the registered image by selecting the `Registered Image` layer on the left of the screen, and clicking on `Autocontrast: once` on the top left of the screen. +6. Click the `Region Segmentation` button in the +`Segmentation` panel. +7. Click the `Add new region` button. + +![A new Labels layer appears](./images/brainglobe-segmentation/brainglobe-segmentation-added-new-region.png) + +**A new Labels layer named `region_0` appears on the left hand side.** + +8. If required, rename this region (by selecting the e.g. `region_0` text) +9. Navigate to where you want to draw your region of interest. +10. Choose a brush size (top left box). +11. Make sure painting mode is activated (by selecting the paintbrush icon, top left). You can go back to the navigation mode by selecting the magnifying glass. +12. Colour in your region that you want to segment by holding down the left mouse button, ensuring that you make a solid object. For 3D structures, set `n edit dim` to `3` to paint a sphere instead of a circle, or paint circles across several slices. You can change slice using the slider at the bottom of the screen. + +![A brain region is coloured in](./images/brainglobe-segmentation/brainglobe-segmentation-painted-new-region.png) + +13. Repeat steps 6.-11. for each other region you would like to segment. +14. Click `Analyse regions` to analyse the spatial distribution of the regions you have drawn. + * If `Calculate volumes` is selected, the volume of each brain area included in the segmented region will be calculated and saved. + * If `Summarise volumes` is selected, then each region will be summarised (centers, volumes etc) + * If `Save segmentation` is selected, then the segmented layer will be saved at the same time as the analysis is run +(this may make your analysis take longer) + +15. (Optional) Use the `Save` button to save your segmented regions to be reloaded at a later date. + +:::{note} +All data will be saved into your brainreg output directory +::: + +:::{hint} +For more information about how to use automated methods to segment your feature of interest, please see [Analysing segmentation from other napari plugins](../documentation/brainglobe-segmentation/user-guide/analysing-external-segmentation). +For full information on how to use brainglobe-segmentation, please see the [brainglobe-segmentation page](/documentation/brainglobe-segmentation/index) +::: diff --git a/docs/source/tutorials/silicon-probe-tracking.md b/docs/source/tutorials/silicon-probe-tracking.md index a024c6ae..83a5f4cc 100644 --- a/docs/source/tutorials/silicon-probe-tracking.md +++ b/docs/source/tutorials/silicon-probe-tracking.md @@ -84,7 +84,7 @@ To open the graphical user interface, open napari and then load the `brainglobe- [User guide](/documentation/brainglobe-segmentation/user-guide/index)). The `brainglobe-segmentation`graphical user interface opens and shows a set of tools.You can then load your brainreg output -directory, and follow the main brainglobe-segmentation instructions [here](/documentation/brainglobe-segmentation/user-guide/segmenting-1d-tracks) for +directory, and follow the main brainglobe-segmentation instructions [here](./segmenting-1d-tracks) for segmenting a 1D track. Setting `Spline points` will determine how many times along the length of the track that the brain region is sampled at. This can be used to determine the brain region for each recording site on your probe. diff --git a/docs/source/tutorials/tracing-tracking.md b/docs/source/tutorials/tracing-tracking.md index 742c308d..71314785 100644 --- a/docs/source/tutorials/tracing-tracking.md +++ b/docs/source/tutorials/tracing-tracking.md @@ -95,7 +95,7 @@ To use Otsu's method from the `napari-simpleitk-image-processing` plugin, follow - Select the image layer to be thresholded and click `run`. This will automatically segment your image using Otsu's algorithm. This will create a new labels layer. -- Follow the instructions for [2/3D region analysis](/documentation/brainglobe-segmentation/user-guide/segmenting-3d-structures) +- Follow the instructions for [2/3D region analysis](./segmenting-3d-structures) to analyse the distribution of the thresholded voxels. **Instructions by** [**Sara Mederos**](https://www.sainsburywellcome.org/web/people/sara-mederos). diff --git a/screenshot_maker.py b/screenshot_maker.py new file mode 100644 index 00000000..2c723150 --- /dev/null +++ b/screenshot_maker.py @@ -0,0 +1,114 @@ +import napari +from skimage.io import imsave +from skimage.draw import disk +import pytest +import numpy as np +import shutil +from pathlib import Path + +VIEWPORT_WIDTH = 1400 +VIEWPORT_HEIGHT = 700 + +COMPARE_OR_REGENERATE = "REGENERATE" +RELATIVE_PATH_FOR_SCREENSHOTS = Path("./docs/source/tutorials/images/brainglobe-segmentation/") + +@pytest.fixture +def standard_size_viewer(qtbot): + viewer = napari.Viewer() + viewer.window.resize(VIEWPORT_WIDTH, VIEWPORT_HEIGHT) + yield viewer + viewer.close() + +@pytest.fixture +def take_viewer_screenshot(qtbot): + def _take_viewer_screenshot(viewer, path): + qtbot.wait(2000) # figure out how replace with qtbot.wait_exposed instead + screenshot = viewer.window.screenshot() + # hackily stick in a green point (or later, a cursor) at (x,y) with: + # screenshot[y, x] = [0, 255, 0, 255] + imsave(path, screenshot) + return _take_viewer_screenshot + +@pytest.fixture +def clean_configure_segmentation_widget(tmp_path, standard_size_viewer, take_viewer_screenshot): + """Returns an inner function that + - opens the brainglobe-segmentation widget + - configures the widget so an example project is loaded in atlas space + - saves a screenshot after each of the above steps + - returns the viewer and the widget + """ + def _clean_configure_segmentation_widget(): + viewer = standard_size_viewer + _, segmentation_widget = viewer.window.add_plugin_dock_widget( + plugin_name="brainglobe-segmentation", + widget_name="Region/track segmentation" + ) + segmentation_widget.viewer = viewer + viewer.show() + + screenshot_file = RELATIVE_PATH_FOR_SCREENSHOTS / "brainglobe-segmentation-open-plugin.png" + take_viewer_screenshot(viewer, screenshot_file) + + brainreg_dir = Path.home() / "dev/brainglobe-segmentation/tests/data" / "brainreg_output" + + tmp_input_dir = tmp_path / "brainreg_output" + shutil.copytree(brainreg_dir, tmp_input_dir) + shutil.rmtree(brainreg_dir/"manual_segmentation"/"atlas_space", ignore_errors=True) + shutil.rmtree(brainreg_dir/"manual_segmentation"/"sample_space", ignore_errors=True) + + segmentation_widget.atlas_space = True + segmentation_widget.plugin = ( + "brainglobe-napari-io.brainreg_read_dir_atlas_space" + ) + segmentation_widget.directory = Path(tmp_input_dir) + segmentation_widget.load_brainreg_directory() + # delete manual segmentation data to ensure it's saved correctly in tests + shutil.rmtree(segmentation_widget.paths.main_directory) + viewer.layers['Registered image'].contrast_limits=(0, 600) + + screenshot_file = RELATIVE_PATH_FOR_SCREENSHOTS / "brainglobe-segmentation-loaded-data.png" + take_viewer_screenshot(viewer, screenshot_file) + return viewer, segmentation_widget + + return _clean_configure_segmentation_widget + +def test_segmentation_widget_screenshot_3d(take_viewer_screenshot, clean_configure_segmentation_widget): + viewer, segmentation_widget = clean_configure_segmentation_widget() + + segmentation_widget.show_regionseg_button.click() + segmentation_widget.region_seg.add_new_region() + + # this setting to zero is needed, weirdly + viewer.layers["region_0"].data = np.zeros_like(viewer.layers["region_0"].data) + + screenshot_file = RELATIVE_PATH_FOR_SCREENSHOTS / "brainglobe-segmentation-added-new-region.png" + take_viewer_screenshot(viewer, screenshot_file) + + rr, cc = disk((70, 30), 10, shape=viewer.layers["region_0"].data.shape) + viewer.layers["region_0"].data[132, cc, rr] = 1 + viewer.layers["region_0"].refresh() + + screenshot_file = RELATIVE_PATH_FOR_SCREENSHOTS / "brainglobe-segmentation-painted-new-region.png" + take_viewer_screenshot(viewer, screenshot_file) + + +def test_segmentation_widget_screenshot_1d(take_viewer_screenshot, clean_configure_segmentation_widget): + viewer, segmentation_widget = clean_configure_segmentation_widget() + + segmentation_widget.show_trackseg_button.click() + segmentation_widget.track_seg.add_track() + + screenshot_file = RELATIVE_PATH_FOR_SCREENSHOTS / "brainglobe-segmentation-added-new-track.png" + take_viewer_screenshot(viewer, screenshot_file) + + viewer.layers["track_0"].data = [[132,30,70],[132,50,80],[132, 60, 90],[132, 70, 130]] + viewer.layers["track_0"].refresh() + + screenshot_file = RELATIVE_PATH_FOR_SCREENSHOTS / "brainglobe-segmentation-added-points.png" + take_viewer_screenshot(viewer, screenshot_file) + + segmentation_widget.track_seg.run_track_analysis() + + screenshot_file = RELATIVE_PATH_FOR_SCREENSHOTS / "brainglobe-segmentation-fitted-points.png" + take_viewer_screenshot(viewer, screenshot_file) + \ No newline at end of file