diff --git a/03_machine_learning/interactive_object_classification/apoc21.png b/03_supervised_machine_learning/interactive_object_classification/apoc21.png similarity index 100% rename from 03_machine_learning/interactive_object_classification/apoc21.png rename to 03_supervised_machine_learning/interactive_object_classification/apoc21.png diff --git a/03_machine_learning/interactive_object_classification/apoc22.png b/03_supervised_machine_learning/interactive_object_classification/apoc22.png similarity index 100% rename from 03_machine_learning/interactive_object_classification/apoc22.png rename to 03_supervised_machine_learning/interactive_object_classification/apoc22.png diff --git a/03_machine_learning/interactive_object_classification/apoc23.png b/03_supervised_machine_learning/interactive_object_classification/apoc23.png similarity index 100% rename from 03_machine_learning/interactive_object_classification/apoc23.png rename to 03_supervised_machine_learning/interactive_object_classification/apoc23.png diff --git a/03_machine_learning/interactive_object_classification/apoc24.png b/03_supervised_machine_learning/interactive_object_classification/apoc24.png similarity index 100% rename from 03_machine_learning/interactive_object_classification/apoc24.png rename to 03_supervised_machine_learning/interactive_object_classification/apoc24.png diff --git a/03_machine_learning/interactive_object_classification/apoc25.png b/03_supervised_machine_learning/interactive_object_classification/apoc25.png similarity index 100% rename from 03_machine_learning/interactive_object_classification/apoc25.png rename to 03_supervised_machine_learning/interactive_object_classification/apoc25.png diff --git a/03_machine_learning/interactive_object_classification/apoc26.png b/03_supervised_machine_learning/interactive_object_classification/apoc26.png similarity index 100% rename from 03_machine_learning/interactive_object_classification/apoc26.png rename to 03_supervised_machine_learning/interactive_object_classification/apoc26.png diff --git a/03_machine_learning/interactive_object_classification/apoc27.png b/03_supervised_machine_learning/interactive_object_classification/apoc27.png similarity index 100% rename from 03_machine_learning/interactive_object_classification/apoc27.png rename to 03_supervised_machine_learning/interactive_object_classification/apoc27.png diff --git a/03_machine_learning/interactive_object_classification/apoc28.png b/03_supervised_machine_learning/interactive_object_classification/apoc28.png similarity index 100% rename from 03_machine_learning/interactive_object_classification/apoc28.png rename to 03_supervised_machine_learning/interactive_object_classification/apoc28.png diff --git a/03_machine_learning/interactive_object_classification/apoc29.png b/03_supervised_machine_learning/interactive_object_classification/apoc29.png similarity index 100% rename from 03_machine_learning/interactive_object_classification/apoc29.png rename to 03_supervised_machine_learning/interactive_object_classification/apoc29.png diff --git a/03_machine_learning/interactive_object_classification/apoc30.png b/03_supervised_machine_learning/interactive_object_classification/apoc30.png similarity index 100% rename from 03_machine_learning/interactive_object_classification/apoc30.png rename to 03_supervised_machine_learning/interactive_object_classification/apoc30.png diff --git a/03_machine_learning/interactive_object_classification/apoc31.png b/03_supervised_machine_learning/interactive_object_classification/apoc31.png similarity index 100% rename from 03_machine_learning/interactive_object_classification/apoc31.png rename to 03_supervised_machine_learning/interactive_object_classification/apoc31.png diff --git a/03_machine_learning/interactive_object_classification/apoc32.png b/03_supervised_machine_learning/interactive_object_classification/apoc32.png similarity index 100% rename from 03_machine_learning/interactive_object_classification/apoc32.png rename to 03_supervised_machine_learning/interactive_object_classification/apoc32.png diff --git a/03_machine_learning/interactive_object_classification/apoc33.png b/03_supervised_machine_learning/interactive_object_classification/apoc33.png similarity index 100% rename from 03_machine_learning/interactive_object_classification/apoc33.png rename to 03_supervised_machine_learning/interactive_object_classification/apoc33.png diff --git a/03_machine_learning/interactive_object_classification/apoc34.png b/03_supervised_machine_learning/interactive_object_classification/apoc34.png similarity index 100% rename from 03_machine_learning/interactive_object_classification/apoc34.png rename to 03_supervised_machine_learning/interactive_object_classification/apoc34.png diff --git a/03_machine_learning/interactive_object_classification/apoc_object_classification.mp4 b/03_supervised_machine_learning/interactive_object_classification/apoc_object_classification.mp4 similarity index 100% rename from 03_machine_learning/interactive_object_classification/apoc_object_classification.mp4 rename to 03_supervised_machine_learning/interactive_object_classification/apoc_object_classification.mp4 diff --git a/03_machine_learning/interactive_object_classification/readme.md b/03_supervised_machine_learning/interactive_object_classification/readme.md similarity index 95% rename from 03_machine_learning/interactive_object_classification/readme.md rename to 03_supervised_machine_learning/interactive_object_classification/readme.md index 01c0dd5..90f2138 100644 --- a/03_machine_learning/interactive_object_classification/readme.md +++ b/03_supervised_machine_learning/interactive_object_classification/readme.md @@ -24,7 +24,8 @@ or using the menu `Tools > Segmentation / labeling > Gauss-Otsu Labeling (clespe ## Object classification -Our starting point is a loaded image and a label image with segmented objects. The following procedure is also shown in [this video](apoc_object_classification.mp4). +Our starting point is a loaded image and a label image with segmented objects. +The following procedure is also shown in [this video](apoc_object_classification.mp4). ![](apoc21.png) diff --git a/03_machine_learning/interactive_pixel_classification/apoc1.png b/03_supervised_machine_learning/interactive_pixel_classification/apoc1.png similarity index 100% rename from 03_machine_learning/interactive_pixel_classification/apoc1.png rename to 03_supervised_machine_learning/interactive_pixel_classification/apoc1.png diff --git a/03_machine_learning/interactive_pixel_classification/apoc10.png b/03_supervised_machine_learning/interactive_pixel_classification/apoc10.png similarity index 100% rename from 03_machine_learning/interactive_pixel_classification/apoc10.png rename to 03_supervised_machine_learning/interactive_pixel_classification/apoc10.png diff --git a/03_machine_learning/interactive_pixel_classification/apoc11.png b/03_supervised_machine_learning/interactive_pixel_classification/apoc11.png similarity index 100% rename from 03_machine_learning/interactive_pixel_classification/apoc11.png rename to 03_supervised_machine_learning/interactive_pixel_classification/apoc11.png diff --git a/03_machine_learning/interactive_pixel_classification/apoc2.png b/03_supervised_machine_learning/interactive_pixel_classification/apoc2.png similarity index 100% rename from 03_machine_learning/interactive_pixel_classification/apoc2.png rename to 03_supervised_machine_learning/interactive_pixel_classification/apoc2.png diff --git a/03_machine_learning/interactive_pixel_classification/apoc3.png b/03_supervised_machine_learning/interactive_pixel_classification/apoc3.png similarity index 100% rename from 03_machine_learning/interactive_pixel_classification/apoc3.png rename to 03_supervised_machine_learning/interactive_pixel_classification/apoc3.png diff --git a/03_machine_learning/interactive_pixel_classification/apoc4.png b/03_supervised_machine_learning/interactive_pixel_classification/apoc4.png similarity index 100% rename from 03_machine_learning/interactive_pixel_classification/apoc4.png rename to 03_supervised_machine_learning/interactive_pixel_classification/apoc4.png diff --git a/03_machine_learning/interactive_pixel_classification/apoc5.png b/03_supervised_machine_learning/interactive_pixel_classification/apoc5.png similarity index 100% rename from 03_machine_learning/interactive_pixel_classification/apoc5.png rename to 03_supervised_machine_learning/interactive_pixel_classification/apoc5.png diff --git a/03_machine_learning/interactive_pixel_classification/apoc6.png b/03_supervised_machine_learning/interactive_pixel_classification/apoc6.png similarity index 100% rename from 03_machine_learning/interactive_pixel_classification/apoc6.png rename to 03_supervised_machine_learning/interactive_pixel_classification/apoc6.png diff --git a/03_machine_learning/interactive_pixel_classification/apoc7.png b/03_supervised_machine_learning/interactive_pixel_classification/apoc7.png similarity index 100% rename from 03_machine_learning/interactive_pixel_classification/apoc7.png rename to 03_supervised_machine_learning/interactive_pixel_classification/apoc7.png diff --git a/03_machine_learning/interactive_pixel_classification/apoc8.png b/03_supervised_machine_learning/interactive_pixel_classification/apoc8.png similarity index 100% rename from 03_machine_learning/interactive_pixel_classification/apoc8.png rename to 03_supervised_machine_learning/interactive_pixel_classification/apoc8.png diff --git a/03_machine_learning/interactive_pixel_classification/apoc9.png b/03_supervised_machine_learning/interactive_pixel_classification/apoc9.png similarity index 100% rename from 03_machine_learning/interactive_pixel_classification/apoc9.png rename to 03_supervised_machine_learning/interactive_pixel_classification/apoc9.png diff --git a/03_machine_learning/interactive_pixel_classification/apoc_object_segmentation.mp4 b/03_supervised_machine_learning/interactive_pixel_classification/apoc_object_segmentation.mp4 similarity index 100% rename from 03_machine_learning/interactive_pixel_classification/apoc_object_segmentation.mp4 rename to 03_supervised_machine_learning/interactive_pixel_classification/apoc_object_segmentation.mp4 diff --git a/03_machine_learning/interactive_pixel_classification/readme.md b/03_supervised_machine_learning/interactive_pixel_classification/readme.md similarity index 100% rename from 03_machine_learning/interactive_pixel_classification/readme.md rename to 03_supervised_machine_learning/interactive_pixel_classification/readme.md diff --git a/04_unsupervised_machine_learning/img.png b/04_unsupervised_machine_learning/img.png new file mode 100644 index 0000000..6628034 Binary files /dev/null and b/04_unsupervised_machine_learning/img.png differ diff --git a/04_unsupervised_machine_learning/img_1.png b/04_unsupervised_machine_learning/img_1.png new file mode 100644 index 0000000..b72069a Binary files /dev/null and b/04_unsupervised_machine_learning/img_1.png differ diff --git a/04_unsupervised_machine_learning/img_2.png b/04_unsupervised_machine_learning/img_2.png new file mode 100644 index 0000000..ae922d6 Binary files /dev/null and b/04_unsupervised_machine_learning/img_2.png differ diff --git a/04_unsupervised_machine_learning/img_3.png b/04_unsupervised_machine_learning/img_3.png new file mode 100644 index 0000000..a635955 Binary files /dev/null and b/04_unsupervised_machine_learning/img_3.png differ diff --git a/04_unsupervised_machine_learning/img_4.png b/04_unsupervised_machine_learning/img_4.png new file mode 100644 index 0000000..12e4fcc Binary files /dev/null and b/04_unsupervised_machine_learning/img_4.png differ diff --git a/04_unsupervised_machine_learning/img_5.png b/04_unsupervised_machine_learning/img_5.png new file mode 100644 index 0000000..920071c Binary files /dev/null and b/04_unsupervised_machine_learning/img_5.png differ diff --git a/04_unsupervised_machine_learning/img_6.png b/04_unsupervised_machine_learning/img_6.png new file mode 100644 index 0000000..8b41c23 Binary files /dev/null and b/04_unsupervised_machine_learning/img_6.png differ diff --git a/04_unsupervised_machine_learning/img_7.png b/04_unsupervised_machine_learning/img_7.png new file mode 100644 index 0000000..5ebf8ad Binary files /dev/null and b/04_unsupervised_machine_learning/img_7.png differ diff --git a/04_unsupervised_machine_learning/img_8.png b/04_unsupervised_machine_learning/img_8.png new file mode 100644 index 0000000..aa3ddaa Binary files /dev/null and b/04_unsupervised_machine_learning/img_8.png differ diff --git a/04_unsupervised_machine_learning/interactive_clustering.md b/04_unsupervised_machine_learning/interactive_clustering.md new file mode 100644 index 0000000..0d3fc83 --- /dev/null +++ b/04_unsupervised_machine_learning/interactive_clustering.md @@ -0,0 +1,109 @@ +# Interactive object clustering + +In this exercise we will use the [napari-clusters-plotter](https://www.napari-hub.org/plugins/napari-clusters-plotter) to group objects together based on their measured properties. +For these measurements we will use [napari-skimage-regionprops](). + +## Starting point + +Open a terminal window and activate your conda environment: + +``` +conda activate devbio-napari-env +``` + +Afterwards, start up Napari: + +``` +napari +``` + +In Napari open the "Human mitosis" example dataset from the menu `File > Open Sample > Napari builtins > Human mitosis`. + +![img.png](img.png) + +## Object segmentation + +Segment the nuclei using the menu `Tools > Segmentation / Labeling > Gauss-Otsu Labeling (clesperanto)`. +Keep the default settings and click `Run`. + +![img_1.png](img_1.png) + +Use the small hide icon to close the Gauss-Otsu-Labeling widget. + +## Feature extraction + +Measure shape and intensity features using the menu `Plugins > Measurement Tables > Regionprops (scikit-image, nsr)`. +Make sure that the `intensity`, `size` and `shape` checkboxes are ticked and click `Run`. + +![img_2.png](img_2.png) + +Hide both, the Regionprops widget and the Table widget that just popped up. + +## Dimensionality reduction + +Generate a [UMAP](https://umap-learn.readthedocs.io/) using the menu `Plugins > Measurement post-processing > Dimensionality Reduction > UMAP (nsr)`. +* Make sure the labels layer is selected where you just did your measurements. +* Choose the method `UMAP` and keep its default settings. +* Untick the features `bbox_area`, and `local_centroid1` / `2` using the `CTRL` key. +* Click `Run`. +* Wait a minute. + +![img_3.png](img_3.png) + +Close both, the Dimensionality Reduction widget and the Table widget that just popped up. + +## Plot measurements + +Open the plot widget using the menu `Plugins > Visualization > Plot measurements (ncp)`. +You can play a bit with columns to plot. Eventually select `UMAP_0` and `UMAP_2` as `Axes` and click on `Plot`. + +![img_4.png](img_4.png) + + +## Manual clustering + +Click within the plot and before releasing the mouse button, drag the mouse to select a region of interest. +Repeat this while holding the `CTRL` key to select multiple regions of interest. + +![manual_clustering.gif](manual_clustering.gif) + +The object selection might be related to their shape and size. +To visualize this hypothesis, you can select the `area` and `roundness` as Axes in the plot widget. +Make also sure the clustering `MANUAL_CLUSTER_ID` is selected. +Click on `Plot` again. + +![img_5.png](img_5.png) + +Close the plot widget. + +## Automatic clustering + +You can also cluster the objects automatically using the menu `Plugins > Measurement post-processing > Clustering (nsr)` menu. +Choose the layer of the segmented and measured objects. +Unselect the `bbox_area` and `local_centroid1` / `2` features. +Unselect `aspect_ratio` because it sometimes contains `inf` values which are not supported by the clustering algorithm. +Also unselect `UMAP_0` and `UMAP_1` as these two contain compressed information about all other columns. +Select `K-Means` clustering and activate the `Standardize features` checkbox. +Click on `Run`. + +![img_6.png](img_6.png) + +Close the Clustering widget and the Table widget that just popped up. + +## Visualizing automatic clustering + +To visualize the results of the automated clustering, open the plot widget again using the menu `Plugins > Visualization > Plot measurements (ncp)`. +Select `UMAP_0` and `UMAP_1` as `Axes` and select `KMEANS_CLUSTER_ID` as `Clustering`. + +![img_7.png](img_7.png) + +## Exercise + +Cluster the objects into 5 classes while having only `UMAP_0` and `UMAP_1` selected in the Clustering widget. +Give this clustering result a name. +Visualize the resulting clustering using the plot widget. +The result should approximately look like this: + +![img_8.png](img_8.png) + + diff --git a/04_unsupervised_machine_learning/manual_clustering.gif b/04_unsupervised_machine_learning/manual_clustering.gif new file mode 100644 index 0000000..cada866 Binary files /dev/null and b/04_unsupervised_machine_learning/manual_clustering.gif differ diff --git a/_toc.yml b/_toc.yml index 920661d..59e5299 100644 --- a/_toc.yml +++ b/_toc.yml @@ -11,12 +11,11 @@ parts: - file: 01_scripting/napari_intro - file: 02_notebooks/napari-assistant - file: 02_notebooks/notebook_export - - file: 03_machine_learning/interactive_pixel_classification - - file: 03_machine_learning/interactive_object_classification - # generating notebooks using APOC - -# - file: 02_python_basics/readme -# sections: -# - file: 02_python_basics/01_our_first_juptyer_notebook + + - caption: Optional exercises + chapters: + - file: 03_supervised_machine_learning/interactive_pixel_classification/readme + - file: 03_supervised_machine_learning/interactive_object_classification/readme + - file: 04_unsupervised_machine_learning/interactive_clustering - file: imprint