Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
368 changes: 368 additions & 0 deletions 05_feature_extraction/00_plotting_in_python.ipynb

Large diffs are not rendered by default.

192 changes: 192 additions & 0 deletions 05_feature_extraction/01_thresholding.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,192 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "6595df14-f25f-4f5a-b631-c1abbebaa0bb",
"metadata": {},
"source": [
"# Exercise 1\n",
"\n",
"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",
"\n",
"## Recap\n",
"\n",
"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",
"\n",
"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",
"\n",
"**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",
"\n",
"**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!"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "96bb8728-eaf9-48aa-985b-f4eb94ed5c7f",
"metadata": {},
"outputs": [],
"source": [
"from skimage import data, filters, measure\n",
"import matplotlib.pyplot as plt\n",
"import napari"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "2ab114eb-c9a6-417c-be01-a59105cf0202",
"metadata": {},
"outputs": [],
"source": [
"image = data.human_mitosis()"
]
},
{
"cell_type": "markdown",
"id": "19ae7d4c-2382-428a-8c06-f6908f4710a3",
"metadata": {},
"source": [
"As a first task, use the `plt.imshow()` function to display the image in the notebook:"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "bb85b7d4-5fec-48e6-9dce-883218196c80",
"metadata": {},
"outputs": [],
"source": [
"# Code goes here"
]
},
{
"cell_type": "markdown",
"id": "1b3bef6e-bac7-4355-8387-f5f403cb73ea",
"metadata": {},
"source": [
"Now, apply several of the thresholds from `skimage` to the image data! Choose one that you think is suitable.\n",
"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."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "2168ef40-5913-4d44-815b-6b328262b2e0",
"metadata": {},
"outputs": [],
"source": [
"binary_image = # code goes here"
]
},
{
"cell_type": "markdown",
"id": "ee9147cf-4773-4a01-9da4-5f5867b35ed5",
"metadata": {},
"source": [
"Again, use `plt.imshow()` to visualize the results"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "23ed60a0-9cb6-48d7-949a-8d572f693f9c",
"metadata": {},
"outputs": [],
"source": [
"# Code goes here"
]
},
{
"cell_type": "markdown",
"id": "82f5717f-2fad-495f-84eb-f0ba543b0922",
"metadata": {},
"source": [
"Now we would like to perform connected-component analysis. Use the appropriate function from skimage (`measure.label()`) for this task!"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "58550efa-a032-417d-90d2-e009f760a8db",
"metadata": {},
"outputs": [],
"source": [
"label_image = # code goes here"
]
},
{
"cell_type": "markdown",
"id": "8e316ab9-10e9-489a-96af-fb98e65b7ac8",
"metadata": {},
"source": [
"## Visualization in Napari"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "f8fa699b-8764-4b8f-8967-2da4a292cdb1",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"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"
]
}
],
"source": [
"viewer = napari.Viewer()"
]
},
{
"cell_type": "markdown",
"id": "d8b83da7-0e93-4922-9468-cc0735ae5ce6",
"metadata": {},
"source": [
"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."
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "0f648bb4-ee2e-41ac-befa-33f54f9f3843",
"metadata": {},
"outputs": [],
"source": [
"# Code goes here"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "b6614988-1613-4a37-b6b0-591f8c643f38",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.12"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
386 changes: 386 additions & 0 deletions 05_feature_extraction/02_thresholding_and_noise.ipynb

Large diffs are not rendered by default.

363 changes: 363 additions & 0 deletions 05_feature_extraction/03_Otsu_threshold.ipynb

Large diffs are not rendered by default.

Loading