Skip to content

Commit ce71c0a

Browse files
committed
Minor maintenance fixes, with thanks to @Koushouu
1 parent c3802cd commit ce71c0a

4 files changed

+47
-51
lines changed

README.md

+28-32
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@ Python BioImage Analysis Tutorial
88

99
----
1010

11-
⚠️ Note that some of the materials in this tuorial are slightly out of date by now (2022), but recent feedback has shown that the tutorial is still very useful and approachable for many learners. I would like to create an updated and slightly extended version by the end of the year, but academic pressures limit my ability to work on this, so we'll have to see how it goes. 🤞 (Jonas, May 22)
11+
⚠️ Note that some of the materials in this tuorial are slightly out of date by now (2023), but recent feedback has shown that the tutorial is still very useful and approachable for many learners. I would like to create an updated and slightly extended version at some point, but academic pressures limit my ability to work on this, so we'll have to see how it goes... 🤞
1212

13-
-----
13+
(The latest maintenance update was done on 17.02.2023 for python 3.9.16 (basic Anaconad distro), with thanks to @Koushouu!)
1414

15+
-----
1516

1617
## Aims and Overview
1718

@@ -23,39 +24,36 @@ Everything you need to know to get started can be found in the jupyter notebook
2324

2425
Note that this tutorial was part of a course aimed at people with basic knowledge of python. The course included introductory sessions/lectures on scientific python (in particular `numpy` and `matplotlib`) as well as on image analysis (see the slides in this repository). For those tackling this tutorial on their own, it is therefore recommended to first acquire basic scientific python knowledge elsewhere (e.g. at [python-course.eu](https://www.python-course.eu)).
2526

26-
2727
## Content Overview
2828

2929
- Lecture
30-
- Working with digital images
31-
- Images as arrays of numbers
32-
- Look-up tables (LUTs)
33-
- Dimensions
34-
- Bit-depth
35-
- Image analysis pipelines
36-
- Preprocessing: filters, kernels, convolution, background subtraction
37-
- Foreground detection: thresholding, morphological operations
38-
- Segmentation: labels, seeds, watershed
39-
- Postprocessing: object filtering
40-
- Making measurements
41-
30+
- Working with digital images
31+
- Images as arrays of numbers
32+
- Look-up tables (LUTs)
33+
- Dimensions
34+
- Bit-depth
35+
- Image analysis pipelines
36+
- Preprocessing: filters, kernels, convolution, background subtraction
37+
- Foreground detection: thresholding, morphological operations
38+
- Segmentation: labels, seeds, watershed
39+
- Postprocessing: object filtering
40+
- Making measurements
4241

4342
- Tutorial
44-
- Importing Modules & Packages
45-
- Loading & Handling Image Data
46-
- Preprocessing
47-
- Manual Thresholding & Threshold Detection
48-
- Adaptive Thresholding
49-
- Improving Masks with Binary Morphology
50-
- Connected Components Labeling
51-
- Cell Segmentation by Seeding & Expansion
52-
- Postprocessing: Removing Cells at the Image Border
53-
- Identifying Cell Edges
54-
- Extracting Quantitative Measurements
55-
- Simple Analysis & Visualization
56-
- Writing Output to Files
57-
- Batch Processing
58-
43+
- Importing Modules & Packages
44+
- Loading & Handling Image Data
45+
- Preprocessing
46+
- Manual Thresholding & Threshold Detection
47+
- Adaptive Thresholding
48+
- Improving Masks with Binary Morphology
49+
- Connected Components Labeling
50+
- Cell Segmentation by Seeding & Expansion
51+
- Postprocessing: Removing Cells at the Image Border
52+
- Identifying Cell Edges
53+
- Extracting Quantitative Measurements
54+
- Simple Analysis & Visualization
55+
- Writing Output to Files
56+
- Batch Processing
5957

6058
## Old Versions and Other Sources
6159

@@ -65,7 +63,6 @@ If you are looking for the python 2 version from 2017, see the `2017_legacy_pyth
6563

6664
The original 2016 materials can be found in Karin Sasaki's corresponding Github [repo](https://github.com/karinsasaki/python-workshop-image-processing).
6765

68-
6966
## Acknowledgements
7067

7168
The first version of this tutorial was created for the `EMBL Python Workshop - Image Processing` course organized by Karin Sasaki and Jonas Hartmann in 2016. Additional lecturers and TAs contributing to this course were Kota Miura, Volker Hilsenstein, Aliaksandr Halavatyi, Imre Gaspar, and Toby Hodges.
@@ -76,7 +73,6 @@ The third version of this tutorial was part of the `EMBL Bio-IT/ALMF Image Analy
7673

7774
Many thanks to all the helpful collaborators and the interested students who were instrumental in making these courses a success.
7875

79-
8076
## Feedback
8177

8278
Feedback on this tutorial is always welcome! Please open an issue on GitHub or write to *jonas.hartmann(AT)ucl.ac.uk*.

batch_processing_solution.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def run_pipeline(dirpath, filename):
5353
## Preprocessing
5454

5555
sigma = 3
56-
img_smooth = ndi.filters.gaussian_filter(img, sigma)
56+
img_smooth = ndi.gaussian_filter(img, sigma)
5757

5858

5959
## Adaptive Thresholding
@@ -85,7 +85,7 @@ def run_pipeline(dirpath, filename):
8585
### Seeding by Distance Transform
8686

8787
dist_trans = ndi.distance_transform_edt(~mem_final)
88-
dist_trans_smooth = ndi.filters.gaussian_filter(dist_trans, sigma=5)
88+
dist_trans_smooth = ndi.gaussian_filter(dist_trans, sigma=5)
8989

9090
from skimage.feature import peak_local_max
9191
seed_coords = peak_local_max(dist_trans_smooth, min_distance=10)

image_analysis_tutorial.ipynb

+7-7
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,7 @@
9494
"\n",
9595
"#### Python version\n",
9696
"\n",
97-
"- The solutions are provided in **python 3.6** (but any version of python 3 should work without changes)\n",
98-
"- Everything shown in the solutions also works in python 2.7 with only very minor changes.\n",
97+
"- The solutions were last tested with **python 3.9**, but any version of python 3 should work without changes\n",
9998
"- To install python, jupyter notebook and the required modules, we recommend the **Anaconda Distribution**. The installer can be downloaded [here](https://www.anaconda.com/download/).\n",
10099
"\n",
101100
"\n",
@@ -106,6 +105,7 @@
106105
" - scipy\n",
107106
" - matplotlib\n",
108107
" - scikit-image\n",
108+
" - ipywidgets\n",
109109
"- All required modules come pre-installed if you are using the **[Anaconda distribution](https://www.anaconda.com/download/)** of python."
110110
]
111111
},
@@ -481,7 +481,7 @@
481481
"source": [
482482
"# (ii) Perform the smoothing on the image\n",
483483
"\n",
484-
"# To do so, use the Gaussian filter function 'ndi.filters.gaussian_filter' from the \n",
484+
"# To do so, use the Gaussian filter function 'ndi.gaussian_filter' from the \n",
485485
"# image processing module 'scipy.ndimage', which was imported at the start of the tutorial. \n",
486486
"# Check out the documentation of scipy to see how to use this function. \n",
487487
"# Allocate the output to a new variable.\n",
@@ -639,9 +639,9 @@
639639
"\n",
640640
"*Important note for those who get a static image (no slider) or a text warning:*\n",
641641
"\n",
642-
"For some users, it is necessary to specifically activate the widgets plugin for Jupyter notebook. To do so, save and exit Jupyter notebook, then go to a terminal and write `jupyter nbextension enable --py --sys-prefix widgetsnbextension`. After this, you should be able to restart Jupyter notebook and the widget should display correctly. \n",
642+
"For some users, it is necessary to specifically activate the widgets plugin for Jupyter notebook. To do so, save and exit Jupyter notebook, then go to a terminal (or Anaconda prompt) and write `jupyter nbextension enable --py --sys-prefix widgetsnbextension`. After this, you should be able to restart Jupyter notebook and the widget should display correctly. \n",
643643
"\n",
644-
"If it still doesn't work, you may instead have to type `jupyter nbextension enable --py widgetsnbextension` in the terminal. However, note that this implies that your installation of Conda/Jupyter is not optimally configured (see [this GitHub issue](https://github.com/jupyter-widgets/ipywidgets/issues/541) for more information, although this is not something you necessarily need to worry about in the context of this course).\n",
644+
"If it still doesn't work, you may instead have to type `jupyter nbextension enable --py widgetsnbextension` in the terminal (or Anaconda prompt). However, note that this implies that your installation of Conda/Jupyter is not optimally configured (see [this GitHub issue](https://github.com/jupyter-widgets/ipywidgets/issues/541) for more information, although this is not something you necessarily need to worry about in the context of this course).\n",
645645
"\n",
646646
"----"
647647
]
@@ -1077,7 +1077,7 @@
10771077
"source": [
10781078
"# (iii) Smoothen the distance transform\n",
10791079
"\n",
1080-
"# Use 'ndi.filters.gaussian_filter' to do so.\n",
1080+
"# Use 'ndi.gaussian_filter' to do so.\n",
10811081
"# You will have to optimize your choice of 'sigma' based on the outcome below.\n",
10821082
"### YOUR CODE HERE!"
10831083
]
@@ -1126,7 +1126,7 @@
11261126
"# using the function 'np.ma.array' with the keyword argument 'mask'. \n",
11271127
"# Check the docs or Stack Overflow to figure out how to do this.\n",
11281128
"\n",
1129-
"# BONUS: As an additional improvement for the visualization, use 'ndi.filters.maximum_filter' to dilate the \n",
1129+
"# BONUS: As an additional improvement for the visualization, use 'ndi.maximum_filter' to dilate the \n",
11301130
"# seeds a little bit, making them bigger and thus better visible.\n",
11311131
"\n",
11321132
"### YOUR CODE HERE!"

image_analysis_tutorial_solutions.ipynb

+10-10
Original file line numberDiff line numberDiff line change
@@ -284,11 +284,11 @@
284284
"source": [
285285
"# (ii) Perform the smoothing on the image\n",
286286
"\n",
287-
"# To do so, use the Gaussian filter function 'ndi.filters.gaussian_filter' from the \n",
287+
"# To do so, use the Gaussian filter function 'ndi.gaussian_filter' from the \n",
288288
"# image processing module 'scipy.ndimage', which was imported at the start of the tutorial. \n",
289289
"# Check out the documentation of scipy to see how to use this function. \n",
290290
"# Allocate the output to a new variable.\n",
291-
"img_smooth = ndi.filters.gaussian_filter(img, sigma)"
291+
"img_smooth = ndi.gaussian_filter(img, sigma)"
292292
]
293293
},
294294
{
@@ -776,11 +776,11 @@
776776
"source": [
777777
"# (iii) Smoothen the distance transform\n",
778778
"\n",
779-
"# Use 'ndi.filters.gaussian_filter' to do so.\n",
779+
"# Use 'ndi.gaussian_filter' to do so.\n",
780780
"# You will have to optimize your choice of 'sigma' based on the outcome below.\n",
781781
"\n",
782782
"# Applying the filter\n",
783-
"dist_trans_smooth = ndi.filters.gaussian_filter(dist_trans, sigma=5)\n",
783+
"dist_trans_smooth = ndi.gaussian_filter(dist_trans, sigma=5)\n",
784784
"\n",
785785
"# Visualizing\n",
786786
"plt.figure(figsize=(7,7))\n",
@@ -834,11 +834,11 @@
834834
"# using the function 'np.ma.array' with the keyword argument 'mask'. \n",
835835
"# Check the docs or Stack Overflow to figure out how to do this.\n",
836836
"\n",
837-
"# BONUS: As an additional improvement to the visualization, use 'ndi.filters.maximum_filter' to dilate the \n",
837+
"# BONUS: As an additional improvement to the visualization, use 'ndi.maximum_filter' to dilate the \n",
838838
"# seeds a little bit, making them bigger and thus better visible.\n",
839839
"\n",
840840
"# Dilate seeds\n",
841-
"seeds_dil = ndi.filters.maximum_filter(seeds, size=10)\n",
841+
"seeds_dil = ndi.maximum_filter(seeds, size=10)\n",
842842
"\n",
843843
"# Create plot\n",
844844
"plt.figure(figsize=(7,7))\n",
@@ -859,7 +859,7 @@
859859
"seeds_labeled = ndi.label(seeds)[0]\n",
860860
"\n",
861861
"# Visualize the final result (the labeled seeds) as an overlay on the raw (or smoothed) image\n",
862-
"seeds_labeled_dil = ndi.filters.maximum_filter(seeds_labeled, size=10) # Expand a bit for visualization\n",
862+
"seeds_labeled_dil = ndi.maximum_filter(seeds_labeled, size=10) # Expand a bit for visualization\n",
863863
"plt.figure(figsize=(10,10))\n",
864864
"plt.imshow(img_smooth, interpolation='none', cmap='gray')\n",
865865
"plt.imshow(np.ma.array(seeds_labeled_dil, mask=seeds_labeled_dil==0), interpolation='none', cmap='prism')\n",
@@ -1748,9 +1748,9 @@
17481748
],
17491749
"metadata": {
17501750
"kernelspec": {
1751-
"display_name": "Python 3 (ipykernel)",
1751+
"display_name": "Python [conda env:py39_tutorial_test]",
17521752
"language": "python",
1753-
"name": "python3"
1753+
"name": "conda-env-py39_tutorial_test-py"
17541754
},
17551755
"language_info": {
17561756
"codemirror_mode": {
@@ -1762,7 +1762,7 @@
17621762
"name": "python",
17631763
"nbconvert_exporter": "python",
17641764
"pygments_lexer": "ipython3",
1765-
"version": "3.7.3"
1765+
"version": "3.9.16"
17661766
}
17671767
},
17681768
"nbformat": 4,

0 commit comments

Comments
 (0)