Skip to content

Commit 82868a7

Browse files
thompson318K-Meech
andauthored
Added a callout to rename layers (#122)
* Added a callout to rename layers * Add image * Update episodes/filters-and-thresholding.md Co-authored-by: Kimberly Meechan <24316371+K-Meech@users.noreply.github.com> * Bigger figure * tidy up renaming layers * Update episodes/filters-and-thresholding.md Co-authored-by: Kimberly Meechan <24316371+K-Meech@users.noreply.github.com> --------- Co-authored-by: Kimberly Meechan <24316371+K-Meech@users.noreply.github.com>
1 parent 4d6953c commit 82868a7

2 files changed

Lines changed: 35 additions & 17 deletions

File tree

episodes/fig/layer-rename.png

31.2 KB
Loading

episodes/filters-and-thresholding.md

Lines changed: 35 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -325,11 +325,27 @@ Try increasing the 'sigma' value to three and clicking run again:
325325
of 3" width='40%'}
326326

327327
You should see a new 'nuclei_gaussian_σ=3.0' layer that is much more heavily blurred.
328-
If you used the `+`/`-` buttons to set the sigma value, you may see many more
329-
decimal places in the layer name e.g. 'nuclei_gaussian_σ=3.00000000000000'.
330-
If so, double click on the layer name to re-name it to `nuclei_gaussian_σ=3.0`.
331328

332-
What's happening here? What exactly does a gaussian blur do? A gaussian blur is
329+
::::::::::::::::::::::::::::::::::::: callout
330+
331+
## Renaming Layer Names
332+
333+
The Gaussian filter plugin uses the special character `σ` in the layer names.
334+
This naming convention makes it difficult to type layer names in the Napari
335+
console (unless your keyboard has the `σ` character). To make life easier
336+
change the name of the added layer now. Double click on the layer name, delete `σ`
337+
and change it to `sigma`
338+
339+
![](fig/layer-rename.png){alt="The mouse cursor hovers over a napari image layer named nuclei_gaussian_sigma=1.0." width='70%'}
340+
341+
342+
Similarly, if you used the `+`/`-` buttons to set the sigma value, you may see excessive
343+
decimal places in the layer name e.g. `nuclei_gaussian_σ=3.00000000000000`.
344+
If so, double click on the layer name to re-name it to `nuclei_gaussian_sigma=3.0`.
345+
346+
:::::::::::::::::::::::::::::::::::::
347+
348+
What's happening here? What exactly does a gaussian blur do? A gaussian blur is
333349
an example of a 'linear filter' which is used to manipulate pixel values in
334350
images. When a filter is applied to an image, each pixel value is replaced by
335351
some combination of the pixel values around it. For example, below is shown a
@@ -510,23 +526,25 @@ shrink in size. Increasing the 'Footprint size' of the filter enhances the effec
510526

511527
## Thresholding the blurred image
512528

513-
First, let's clean up our layer list. Make sure you only have the 'nuclei'
514-
layer in the layer list - select any others and remove them by clicking the ![](
529+
First, let's clean up our layer list. Make sure you only have the `nuclei` and
530+
`nuclei_gaussian_sigma=3.0` layers in the layer list - select any others and remove them by clicking the ![](
515531
https://raw.githubusercontent.com/napari/napari/main/src/napari/resources/icons/delete.svg
516-
){alt="A screenshot of Napari's delete layer button" height='30px'} icon. Also,
517-
close all filter settings panels on the right side of Napari (apart from the
532+
){alt="A screenshot of Napari's delete layer button" height='30px'} icon.
533+
Close all filter settings panels on the right side of Napari (apart from the
518534
gaussian settings) by clicking the tiny `X` icon at their top left corner.
519535

520-
Now let's try thresholding our image again. Make sure you set your gaussian blur
521-
sigma to three, then click 'Apply Gaussian Filter'.
536+
If you don't have the `nuclei_gaussian_sigma=3.0` in your layer list then make it now
537+
using the Gaussian Filter with sigma set to three. You may need to rename the layer,
538+
replacing `σ` with `sigma`.
522539

523-
Then, we'll apply the same threshold as before, now to the
524-
'nuclei_gaussian_σ=3.0' layer:
540+
Now let's try thresholding our image again.
541+
We'll apply the same threshold as before, now to the
542+
`nuclei_gaussian_sigma=3.0` layer:
525543

526544
```python
527545

528546
# Get the image data for the blurred nuclei
529-
blurred = viewer.layers["nuclei_gaussian_σ=3.0"].data
547+
blurred = viewer.layers["nuclei_gaussian_sigma=3.0"].data
530548

531549
# Create mask with a threshold of 8266
532550
blurred_mask = blurred > 8266
@@ -578,7 +596,7 @@ Finally, open the `napari-matplotlib` histogram again with:
578596
the nuclei image after a gaussian blur. The left contrast limit is set
579597
to 0.134."}
580598

581-
Make sure you have 'nuclei_gaussian_σ=3.0' selected in the layer list (should
599+
Make sure you have 'nuclei_gaussian_sigma=3.0' selected in the layer list (should
582600
be highlighted in blue).
583601

584602
You should see that this histogram now runs from 0 to 1, reflecting the new
@@ -588,7 +606,7 @@ threshold between the two peaks - around 0.134:
588606
```python
589607

590608
# Get the image data for the blurred nuclei
591-
blurred = viewer.layers["nuclei_gaussian_σ=3.0"].data
609+
blurred = viewer.layers["nuclei_gaussian_sigma=3.0"].data
592610

593611
# Create mask with a threshold of 0.134
594612
blurred_mask = blurred > 0.134
@@ -633,7 +651,7 @@ clear that some areas are still missed or incorrectly labelled.
633651
## Automated thresholding
634652

635653
First, let's clean up our layer list again. Make sure you only have the
636-
'nuclei', 'mask', 'blurred_mask' and 'nuclei_gaussian_σ=3.0' layers in the
654+
'nuclei', 'mask', 'blurred_mask' and 'nuclei_gaussian_sigma=3.0' layers in the
637655
layer list - select any others and remove them by clicking the ![](
638656
https://raw.githubusercontent.com/napari/napari/main/src/napari/resources/icons/delete.svg
639657
){alt="A screenshot of Napari's delete layer button" height='30px'} icon. Then,
@@ -648,7 +666,7 @@ the most common methods is _Otsu thresholding_, which we will look at now.
648666

649667
Let's go ahead and apply this to our blurred image:
650668

651-
- Select 'nuclei_gaussian_σ=3.0' in the `Image` row
669+
- Select 'nuclei_gaussian_sigma=3.0' in the `Image` row
652670
- Select 'otsu' as the method
653671
- Click the 'Apply Thresholding' button
654672

0 commit comments

Comments
 (0)