Skip to content

Commit c7a97ed

Browse files
committed
Update tutorials
1 parent 30db71b commit c7a97ed

File tree

3 files changed

+64
-51
lines changed

3 files changed

+64
-51
lines changed

tutorials/SpeedingUp.ipynb

Lines changed: 19 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,20 @@
44
"cell_type": "markdown",
55
"metadata": {},
66
"source": [
7-
"# Speed up the execution !\n",
7+
"# Multi-Template Matching\n",
8+
"## Tutorial 3 : Speed up the execution !\n",
89
"\n",
910
"This tutorial shows 2 simple ways to increase the speed of execution with template matching. \n",
1011
"This is especially interesting if you need to run the detection on many images !\n",
1112
"\n",
1213
"## Citations\n",
13-
"If you use this implementation for your research, please cite:\n",
14+
"<a rel=\"license\" href=\"http://creativecommons.org/licenses/by/4.0/\"><img alt=\"Creative Commons License\" style=\"border-width:0\" src=\"https://i.creativecommons.org/l/by/4.0/88x31.png\" /></a><br />This tutorial is licensed under a <a rel=\"license\" href=\"http://creativecommons.org/licenses/by/4.0/\">Creative Commons Attribution 4.0 International License</a>. \n",
15+
"You are free to distribute and/or modify this tutorial, provided you attribute the author: \n",
16+
"\n",
17+
"Multi-Template Matching python package online tutorial - _III - Speed-up execution_ \n",
18+
"Laurent Thomas - 2019 \n",
19+
"https://github.com/multi-template-matching/MultiTemplateMatching-Python/blob/master/tutorials/SpeedingUp.ipynb\n",
1420
"\n",
15-
"*Multi-Template Matching: a versatile tool for object-localization in microscopy images;* \n",
16-
"Laurent SV Thomas, Jochen Gehrig\n",
17-
"bioRxiv 619338; doi: https://doi.org/10.1101/619338\n",
1821
"\n",
1922
"## Let's code !"
2023
]
@@ -55,25 +58,11 @@
5558
"cell_type": "markdown",
5659
"metadata": {},
5760
"source": [
58-
"The key function of the package is `matchTemplates`. \n",
59-
"We can check its documentation within a jupyter notebook using ?, or in usual python using help()"
60-
]
61-
},
62-
{
63-
"cell_type": "code",
64-
"execution_count": 37,
65-
"metadata": {},
66-
"outputs": [],
67-
"source": [
68-
"# This opens a documentation panel at the bottom\n",
69-
"matchTemplates?"
70-
]
71-
},
72-
{
73-
"cell_type": "markdown",
74-
"metadata": {},
75-
"source": [
76-
"Let's open some test image (from the GitHub repository)."
61+
"Let's open some test image (from the GitHub repository). \n",
62+
"This is a widefield microscopy image of a zebrafish larvae, mounted in a 96 well plate using agar. \n",
63+
"We will use Multi-Template-Matching for the detection of the head. \n",
64+
"This is useful since the larvae are not positioned exactly at the same spot in every well. \n",
65+
"For this tutorial we will use the same image though, as the goal is to compare the performance for different parameters. "
7766
]
7867
},
7968
{
@@ -105,7 +94,7 @@
10594
}
10695
],
10796
"source": [
108-
"image = cv2.imread(r\"../images/Fish.tif\", -1)\n",
97+
"image = cv2.imread(r\"../images/Fish.tif\", -1) # this assume you cloned the repo, you can also download the image separatly\n",
10998
"plt.figure(figsize = (10,10))\n",
11099
"plt.axis(\"off\")\n",
111100
"plt.imshow(image, cmap=\"gray\")"
@@ -115,9 +104,9 @@
115104
"cell_type": "markdown",
116105
"metadata": {},
117106
"source": [
118-
"As usually we define a template to search.\n",
119-
"Here we will crop the template from the image to be searched, in practice it is not a realistic scenario, one would would usually have a generic template different from the searched image. \n",
120-
"But here the point is to show the difference in compoutation time."
107+
"As usually we define a template to search. \n",
108+
"Here we will crop the template from the image to be searched, in practice it is not a realistic scenario, one would would usually have a generic template different from the searched image. \n",
109+
"But here the point is to show the difference in computation time."
121110
]
122111
},
123112
{
@@ -433,7 +422,8 @@
433422
"source": [
434423
"And now comes the major trick: because we performed the detection on downscale images, __we have to scale up the detected bounding-boxes__. \n",
435424
"Fortunately, there are such utilitary functions for bounding boxes in the gluoncv library. \n",
436-
"To install gluoncv, open a terminal in your active python environment and type `pip install gluoncv`."
425+
"To install gluoncv, open a terminal in your active python environment and type `pip install gluoncv`. \n",
426+
"For this tutorial I'm using version 0.5.0."
437427
]
438428
},
439429
{

tutorials/Tutorial1.ipynb

Lines changed: 34 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55
"metadata": {},
66
"source": [
77
"# Multi-Template-Matching\n",
8+
"## Tutorial 1 - Introduction\n",
89
"\n",
9-
"This tutorial gives an overview of the different ways to use multiple template matching for object recognition.\n",
10+
"This tutorial gives an overview of the different ways to use multiple template matching for object recognition. \n",
1011
"More documentation is available in the [wiki](https://github.com/LauLauThom/MultiTemplateMatching/wiki) section of the repository.\n",
1112
"\n",
1213
"## Citations\n",
@@ -16,6 +17,15 @@
1617
"Laurent SV Thomas, Jochen Gehrig\n",
1718
"bioRxiv 619338; doi: https://doi.org/10.1101/619338\n",
1819
"\n",
20+
"-------------------------\n",
21+
"\n",
22+
"<a rel=\"license\" href=\"http://creativecommons.org/licenses/by/4.0/\"><img alt=\"Creative Commons License\" style=\"border-width:0\" src=\"https://i.creativecommons.org/l/by/4.0/88x31.png\" /></a><br />This tutorial is licensed under a <a rel=\"license\" href=\"http://creativecommons.org/licenses/by/4.0/\">Creative Commons Attribution 4.0 International License</a>. \n",
23+
"You are free to distribute and/or modify this tutorial, provided you attribute the author: \n",
24+
"\n",
25+
"Multi-Template Matching python package online - _Tutorial 1: Introduction_ \n",
26+
"Laurent Thomas - 2019 \n",
27+
"https://github.com/multi-template-matching/MultiTemplateMatching-Python/blob/master/tutorials/Tutorial1.ipynb\n",
28+
"\n",
1929
"## Let's code !"
2030
]
2131
},
@@ -24,14 +34,6 @@
2434
"execution_count": 2,
2535
"metadata": {},
2636
"outputs": [
27-
{
28-
"name": "stderr",
29-
"output_type": "stream",
30-
"text": [
31-
"C:\\Anaconda3\\lib\\site-packages\\dask\\config.py:168: YAMLLoadWarning: calling yaml.load() without Loader=... is deprecated, as the default Loader is unsafe. Please read https://msg.pyyaml.org/load for full details.\n",
32-
" data = yaml.load(f.read()) or {}\n"
33-
]
34-
},
3537
{
3638
"name": "stdout",
3739
"output_type": "stream",
@@ -56,6 +58,27 @@
5658
"cell_type": "markdown",
5759
"metadata": {},
5860
"source": [
61+
"The main function in MTM is `matchTemplates`. \n",
62+
"Let's have a look at its docstring."
63+
]
64+
},
65+
{
66+
"cell_type": "code",
67+
"execution_count": 4,
68+
"metadata": {},
69+
"outputs": [],
70+
"source": [
71+
"matchTemplates?"
72+
]
73+
},
74+
{
75+
"cell_type": "markdown",
76+
"metadata": {},
77+
"source": [
78+
"As you can read from the doc, the function have 2 main image arguments :\n",
79+
"- a list of template images to search\n",
80+
"- an image in which to search for objects using the templates\n",
81+
"\n",
5982
"Let's open some image of coins from scikit-image, we will showcase the multi-template matching for the detection of the coin locations"
6083
]
6184
},
@@ -138,16 +161,7 @@
138161
"cell_type": "markdown",
139162
"metadata": {},
140163
"source": [
141-
"We will now use the `matchTemplates` function of the package MultiTemplateMatching.\n",
142-
"The function has the following signature\n",
143-
"`matchTemplates(listTemplates, image, method=cv2.TM_CCOEFF_NORMED, N_object=float(\"inf\"), score_threshold=0.5, maxOverlap=0.25)`\n",
144-
"\n",
145-
"- __listTemplates__ : list containing tuples like (\"label\", image) for each template that should be searched\n",
146-
"- __image__ : this is the image in which the search is performed, in this case the image with the coins\n",
147-
"- __method__ : one of OpenCV method for the computation of the correlation map (normalised difference, correlation...)\n",
148-
"- __N_object__ : optionnal parameter, if set the function returns the N_object detections of highest score that do not overlap above the threshold\n",
149-
"- __score_threshold__ : when performing multiple object detections, this is the minimal/maximal score for each detection when using respectively correlation/difference score\n",
150-
"- __maxOverlap__ : Maximal ratio for the Intersection Over Union between overlapping detections. If above the threshold, the lower score bounding box is discarded. "
164+
"We will now use the `matchTemplates` that we have seen above."
151165
]
152166
},
153167
{
@@ -427,7 +441,7 @@
427441
"name": "python",
428442
"nbconvert_exporter": "python",
429443
"pygments_lexer": "ipython3",
430-
"version": "3.7.3"
444+
"version": "3.7.4"
431445
}
432446
},
433447
"nbformat": 4,

tutorials/Tutorial2-FishEgg.ipynb

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,24 @@
44
"cell_type": "markdown",
55
"metadata": {},
66
"source": [
7-
"# Multi-Template matching for object-detection in microscopy images\n",
7+
"# Multi-Template matching \n",
8+
"## Tutorial 2 : template \"augmentation\"\n",
89
"\n",
910
"In this tutorial we will use the multi-template matching to localize fish embryos in wells of a 96 well plate.\n",
1011
"The embryos are circular and thus their position and orientation is completely random. We could possibly use segmentation to localize them but template matching is a possible option too.\n",
1112
"\n",
1213
"We are going to use a published dataset available on Zenodo (thanks Jakob ;) ) \n",
1314
"Just click the DOI badge below.\n",
1415
" [![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.2650147.svg)](https://doi.org/10.5281/zenodo.2650147)\n",
16+
" \n",
17+
" ----------------------------------------\n",
18+
" \n",
19+
"<a rel=\"license\" href=\"http://creativecommons.org/licenses/by/4.0/\"><img alt=\"Creative Commons License\" style=\"border-width:0\" src=\"https://i.creativecommons.org/l/by/4.0/88x31.png\" /></a><br />This tutorial is licensed under a <a rel=\"license\" href=\"http://creativecommons.org/licenses/by/4.0/\">Creative Commons Attribution 4.0 International License</a>. \n",
20+
"You are free to distribute and/or modify this tutorial, provided you attribute the author: \n",
1521
"\n",
22+
"Multi-Template Matching python package online tutorial - _Tutorial 2: FishEgg_ \n",
23+
"Laurent Thomas - 2019 \n",
24+
"https://github.com/multi-template-matching/MultiTemplateMatching-Python/blob/master/tutorials/Tutorial2-FishEgg.ipynb\n",
1625
"\n",
1726
"## Let's code !"
1827
]
@@ -352,7 +361,7 @@
352361
"name": "python",
353362
"nbconvert_exporter": "python",
354363
"pygments_lexer": "ipython3",
355-
"version": "3.7.3"
364+
"version": "3.7.4"
356365
}
357366
},
358367
"nbformat": 4,

0 commit comments

Comments
 (0)