Skip to content

Commit 97fbda8

Browse files
committed
Add drawBoxesOnRGB to examples
1 parent de5ca99 commit 97fbda8

File tree

4 files changed

+53
-205
lines changed

4 files changed

+53
-205
lines changed

MTM/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,6 @@ def drawBoxesOnGray(image, listHit, boxThickness=2, boxColor=255, showLabel=Fals
240240

241241

242242
if __name__ == '__main__':
243-
244243
from skimage.data import coins
245244
import matplotlib.pyplot as plt
246245

@@ -259,5 +258,5 @@ def drawBoxesOnGray(image, listHit, boxThickness=2, boxColor=255, showLabel=Fals
259258
print(hit)
260259

261260
## Display matches
262-
Overlay = drawBoxes(image, listHit)
261+
Overlay = drawBoxesOnRGB(image, listHit, showLabel=True)
263262
plt.imshow(Overlay)

README.md

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Multi-Template-Matching
1+
# Multi-Template-Matching
22
Multi-Template-Matching is a package to perform object-recognition in images using one or several smaller template images.
33
The template and images should have the same bitdepth (8,16,32-bit) and number of channels (single/Grayscale or RGB).
44
The main function `MTM.matchTemplates` returns the best predicted locations provided either a score_threshold and/or the expected number of objects in the image.
@@ -47,9 +47,11 @@ __Returns__
4747

4848
The function `findMatches` performs the same detection without the Non-Maxima Supression.
4949

50-
## drawBoxes
51-
The 2nd important function is `drawBoxes` to display the detections as rectangular bounding boxes on the initial image.
52-
`drawBoxes(image, listHit, boxThickness=2, boxColor=(255, 255, 00), showLabel=True, labelColor=(255, 255, 0)`
50+
## drawBoxesOnRGB
51+
The 2nd important function is `drawBoxesOnRGB` to display the detections as rectangular bounding boxes on the initial image.
52+
To be able to visualise the detection as colored bounding boxes, the function return a RGB copy of the image if a grayscale image is provided.
53+
It is also possible to draw the detection bounding boxes on the grayscale image using drawBoxesOnGray (for instance to generate a mask of the detections).
54+
`drawBoxesOnRGB(image, listHit, boxThickness=2, boxColor=(255, 255, 00), showLabel=True, labelColor=(255, 255, 0), labelScale=0.5 )`
5355

5456
This function returns a copy of the image with predicted template locations as bounding boxes overlaid on the image
5557
The name of the template can also be displayed on top of the bounding boxes with showLabel=True.
@@ -73,6 +75,9 @@ __Parameters__
7375
- _labelColor_: (int, int, int)
7476
RGB color for the label
7577

78+
- _labelScale_: float, default=0.5
79+
scale for the label sizes
80+
7681
__Returns__
7782
- _outImage_: RGB image
7883
original image with predicted template locations depicted as bounding boxes

tutorials/Tutorial1.ipynb

Lines changed: 40 additions & 196 deletions
Large diffs are not rendered by default.

tutorials/Tutorial2-FishEgg.ipynb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"outputs": [],
2525
"source": [
2626
"# 1st import the package\n",
27-
"from MTM import matchTemplates, drawBoxes\n",
27+
"from MTM import matchTemplates, drawBoxesOnRGB\n",
2828
"\n",
2929
"import cv2\n",
3030
"from skimage import io\n",
@@ -213,7 +213,7 @@
213213
}
214214
],
215215
"source": [
216-
"Overlay = drawBoxes(image, listHit, boxThickness=5)\n",
216+
"Overlay = drawBoxesOnRGB(image, listHit, boxThickness=5)\n",
217217
"plt.figure(figsize = (10,10))\n",
218218
"plt.axis(\"off\")\n",
219219
"plt.imshow(Overlay)"
@@ -303,7 +303,7 @@
303303
"source": [
304304
"listHit = matchTemplates(listTemplate, image, N_object=4, score_threshold=0.4, method=cv2.TM_CCOEFF_NORMED, maxOverlap=0.3)\n",
305305
" \n",
306-
"Overlay = drawBoxes(image, listHit, boxThickness=5)\n",
306+
"Overlay = drawBoxesOnRGB(image, listHit, boxThickness=5)\n",
307307
"plt.figure(figsize = (10,10))\n",
308308
"plt.axis(\"off\")\n",
309309
"plt.imshow(Overlay)\n",

0 commit comments

Comments
 (0)