Skip to content

Commit b80092c

Browse files
authored
Merge pull request #9 from BiAPoL/feature-extraction
Add feature extraction slides/exercises to the repo
2 parents c4e1966 + 2f0da03 commit b80092c

File tree

8 files changed

+2100
-1
lines changed

8 files changed

+2100
-1
lines changed

05_feature_extraction/00_plotting_in_python.ipynb

Lines changed: 368 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 192 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,192 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"id": "6595df14-f25f-4f5a-b631-c1abbebaa0bb",
6+
"metadata": {},
7+
"source": [
8+
"# Exercise 1\n",
9+
"\n",
10+
"In this exercise, we will try out different threshold methods and see how they perform on the same data and create a label image from the binarized image data.\n",
11+
"\n",
12+
"## Recap\n",
13+
"\n",
14+
"Thresholding is the process of separating the background and the foreground of an image by comparing the intensities of each image to a single value, the threshold value. Finding a \"good\" threshold value is therefore of key importance. \n",
15+
"\n",
16+
"The output of a thresholding operation is a binary image, consiting of 0s and 1s - which is equivalent to `True` and `False` in terms of boolean values. \n",
17+
"\n",
18+
"**Vocabulary:** Thresholding is a type of segmentation. Separating the image into two types of pixels (background and foreground) is a type of semantic segmentation, and is - since only two types of pixels exist in the output - referred to as a binarization operation.\n",
19+
"\n",
20+
"**How to code:** Remember - in Python you can compare objects (single numbers or images) to threshold values simply by using the `<` or `>` operator - make sure to put the output into a new variable!"
21+
]
22+
},
23+
{
24+
"cell_type": "code",
25+
"execution_count": 6,
26+
"id": "96bb8728-eaf9-48aa-985b-f4eb94ed5c7f",
27+
"metadata": {},
28+
"outputs": [],
29+
"source": [
30+
"from skimage import data, filters, measure\n",
31+
"import matplotlib.pyplot as plt\n",
32+
"import napari"
33+
]
34+
},
35+
{
36+
"cell_type": "code",
37+
"execution_count": 2,
38+
"id": "2ab114eb-c9a6-417c-be01-a59105cf0202",
39+
"metadata": {},
40+
"outputs": [],
41+
"source": [
42+
"image = data.human_mitosis()"
43+
]
44+
},
45+
{
46+
"cell_type": "markdown",
47+
"id": "19ae7d4c-2382-428a-8c06-f6908f4710a3",
48+
"metadata": {},
49+
"source": [
50+
"As a first task, use the `plt.imshow()` function to display the image in the notebook:"
51+
]
52+
},
53+
{
54+
"cell_type": "code",
55+
"execution_count": null,
56+
"id": "bb85b7d4-5fec-48e6-9dce-883218196c80",
57+
"metadata": {},
58+
"outputs": [],
59+
"source": [
60+
"# Code goes here"
61+
]
62+
},
63+
{
64+
"cell_type": "markdown",
65+
"id": "1b3bef6e-bac7-4355-8387-f5f403cb73ea",
66+
"metadata": {},
67+
"source": [
68+
"Now, apply several of the thresholds from `skimage` to the image data! Choose one that you think is suitable.\n",
69+
"Hint: You can find them under `filters.threshold_...` - use the `tab` key or the [documentation](https://scikit-image.org/docs/stable/api/skimage.filters.html?highlight=filters#module-skimage.filters) to find out how to use the implemented threshold functions."
70+
]
71+
},
72+
{
73+
"cell_type": "code",
74+
"execution_count": null,
75+
"id": "2168ef40-5913-4d44-815b-6b328262b2e0",
76+
"metadata": {},
77+
"outputs": [],
78+
"source": [
79+
"binary_image = # code goes here"
80+
]
81+
},
82+
{
83+
"cell_type": "markdown",
84+
"id": "ee9147cf-4773-4a01-9da4-5f5867b35ed5",
85+
"metadata": {},
86+
"source": [
87+
"Again, use `plt.imshow()` to visualize the results"
88+
]
89+
},
90+
{
91+
"cell_type": "code",
92+
"execution_count": null,
93+
"id": "23ed60a0-9cb6-48d7-949a-8d572f693f9c",
94+
"metadata": {},
95+
"outputs": [],
96+
"source": [
97+
"# Code goes here"
98+
]
99+
},
100+
{
101+
"cell_type": "markdown",
102+
"id": "82f5717f-2fad-495f-84eb-f0ba543b0922",
103+
"metadata": {},
104+
"source": [
105+
"Now we would like to perform connected-component analysis. Use the appropriate function from skimage (`measure.label()`) for this task!"
106+
]
107+
},
108+
{
109+
"cell_type": "code",
110+
"execution_count": null,
111+
"id": "58550efa-a032-417d-90d2-e009f760a8db",
112+
"metadata": {},
113+
"outputs": [],
114+
"source": [
115+
"label_image = # code goes here"
116+
]
117+
},
118+
{
119+
"cell_type": "markdown",
120+
"id": "8e316ab9-10e9-489a-96af-fb98e65b7ac8",
121+
"metadata": {},
122+
"source": [
123+
"## Visualization in Napari"
124+
]
125+
},
126+
{
127+
"cell_type": "code",
128+
"execution_count": 5,
129+
"id": "f8fa699b-8764-4b8f-8967-2da4a292cdb1",
130+
"metadata": {},
131+
"outputs": [
132+
{
133+
"name": "stderr",
134+
"output_type": "stream",
135+
"text": [
136+
"WARNING: DirectWrite: CreateFontFaceFromHDC() failed (Indicates an error in an input file such as a font file.) for QFontDef(Family=\"8514oem\", pointsize=12, pixelsize=20, styleHint=5, weight=50, stretch=100, hintingPreference=0) LOGFONT(\"8514oem\", lfWidth=0, lfHeight=-20) dpi=240\n"
137+
]
138+
}
139+
],
140+
"source": [
141+
"viewer = napari.Viewer()"
142+
]
143+
},
144+
{
145+
"cell_type": "markdown",
146+
"id": "d8b83da7-0e93-4922-9468-cc0735ae5ce6",
147+
"metadata": {},
148+
"source": [
149+
"Use the `add_image()` and the `add_labels()` function to add `image`, `binary_image` and `label_image` to the viewer and create screenshot of the viewer with the `napari.utils.nbscreenshot()` function."
150+
]
151+
},
152+
{
153+
"cell_type": "code",
154+
"execution_count": 8,
155+
"id": "0f648bb4-ee2e-41ac-befa-33f54f9f3843",
156+
"metadata": {},
157+
"outputs": [],
158+
"source": [
159+
"# Code goes here"
160+
]
161+
},
162+
{
163+
"cell_type": "code",
164+
"execution_count": null,
165+
"id": "b6614988-1613-4a37-b6b0-591f8c643f38",
166+
"metadata": {},
167+
"outputs": [],
168+
"source": []
169+
}
170+
],
171+
"metadata": {
172+
"kernelspec": {
173+
"display_name": "Python 3 (ipykernel)",
174+
"language": "python",
175+
"name": "python3"
176+
},
177+
"language_info": {
178+
"codemirror_mode": {
179+
"name": "ipython",
180+
"version": 3
181+
},
182+
"file_extension": ".py",
183+
"mimetype": "text/x-python",
184+
"name": "python",
185+
"nbconvert_exporter": "python",
186+
"pygments_lexer": "ipython3",
187+
"version": "3.9.12"
188+
}
189+
},
190+
"nbformat": 4,
191+
"nbformat_minor": 5
192+
}

05_feature_extraction/02_thresholding_and_noise.ipynb

Lines changed: 386 additions & 0 deletions
Large diffs are not rendered by default.

05_feature_extraction/03_Otsu_threshold.ipynb

Lines changed: 363 additions & 0 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)