Skip to main content

Binder Twitter Follow Say Thanks!

Multi-Template-Matching

Multi-Template-Matching is a python package to perform object-recognition in images using one or several smaller template images.
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.

The branch opencl contains some test using the UMat object to run on GPU, but it is actually slow, which can be expected for small dataset as the transfer of the data between the CPU and GPU is slow.

News

  • Version 2.0.0 got rid of the dependency on pandas, the list of hit is simply a python list. The new version also features extensive type hints in functions
  • 03/03/2023 : Version 1.6.4 contributed by @bartleboeuf comes with speed enhancement thanks to parallelizing of the individual template searches. Thanks for this first PR !!
  • 10/11/2021 : You might be interested to test the newer python implementation which is more object-oriented and only relying on scikit-image and shapely.* https://github.com/multi-template-matching/mtm-python-oop

Installation

Using pip in a python environment, pip install Multi-Template-Matching
Once installed, import MTMshould work.
Example jupyter notebooks can be downloaded from the tutorial folder of the github repository and executed in the newly configured python environement.

Install in dev mode

If you want to contribute or experiment with the source code, you can install the package "from source", by first downloading or cloning the repo.
Then opening a command prompt in the repo's root directory (the one containing this README) and calling pip install -e . (mind the final dot).

  • the -e flag stands for editable and make sure that any change to the source code will be directly reflected when you import the package in your script
  • the . just tell pip to look for the package to install in the current directory

Documentation

The wiki section of the repo contains a mini API documentation with description of the key functions of the package.
The website of the project contains some more general documentation.

Tips and tricks

  • matchTemplates expects for the template a list of tuples with one tuple per template in the form (a string identifier for the template, array for the template image). You can generate such list of tuples, from separate lists of the label and template images as following
listLabel    = []  # this one should have the string identifier for each template
listTemplate = [] # this one should have the image array for each template, both lists should have the same length
listTemplateTuple = zip(listLabel, listTemplate)

Similarly, from the list of hits returned by matchTemplates (or NMS), you can get individual lists for the label, bounding-boxes and scores, using listLabel, listBbox, listScore = zip(*listHit)

  • To have a nicer formatting (one list item per row) when printing the list of detected hits, you can use the pprint function from the pprint module (for pretty print).
    It's usually not needed in notebooks (see the example notebooks).
from pprint import pprint
pprint(listHit)
  • Before version 2.0.0, most functions were returning or accepting pandas DataFrame for the list of hit. You can still get such DataFrame from the list of hits returned by MTM v2.0.0 and later, using the command below
import pandas as pd

listLabel, listBbox, listScore = zip(*listHit)

df = pd.DataFrame({"Label":listLabel,
				   "bounding box":listBbox,
				   "Score":listScore})

print(df)

You can also stick to previous version of MTM by specifying the version to pip install, or in a requirements.txt or environment.yml `pip install "Multi-Template-Matching < 2.0.0"

Examples

Check out the jupyter notebook tutorial for some example of how to use the package.
You can run the tutorials online using Binder, no configuration needed ! (click the Binder banner on top of this page).
To run the tutorials locally, install the package using pip as described above, then clone the repository and unzip it.
Finally open a jupyter-notebook session in the unzipped folder to be able to open and execute the notebook.
The wiki section of this related repository also provides some information about the implementation.

Citation

If you use this implementation for your research, please cite:

Thomas, L.S.V., Gehrig, J. Multi-template matching: a versatile tool for object-localization in microscopy images.
BMC Bioinformatics 21, 44 (2020). https://doi.org/10.1186/s12859-020-3363-7

Download the citation as a .ris file from the journal website, here.

Releases

Previous github releases were archived to Zenodo, but the best is to use pip to install specific versions.
DOI

Related projects

See this repo for the implementation as a Fiji plugin.
Here for a KNIME workflow using Multi-Template-Matching.

Origin of the work

This work has been part of the PhD project of Laurent Thomas under supervision of Dr. Jochen Gehrig at ACQUIFER.

ACQUIFER

Funding

This project has received funding from the European Union’s Horizon 2020 research and innovation program under the Marie Sklodowska-Curie grant agreement No 721537 ImageInLife.

ImageInLife MarieCurie

Release files for Multi-Template-Matching 2.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for Multi-Template-Matching 2.0.1
File Size Uploaded
multi_template_matching-2.0.1.tar.gz 11.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for Multi-Template-Matching 2.0.1
File Interpreter ABI Platform
Multi_Template_Matching-2.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 23.5 kB

Release files / multi_template_matching-2.0.1.tar.gz

Download URL multi_template_matching-2.0.1.tar.gz
Size 11.4 kB
Tags Source
SHA-256 checksum
How to use checksums
2eef0628d57b29eb6192abd079553b8555ed30b948d42a13e3fe36ff1a620967
BLAKE2b-256 checksum
How to use checksums
880927aaed7f0948355bef1f456d61daa678429b38cf30c3048f5d3c501cf8c1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.10.11

Release files / Multi_Template_Matching-2.0.1-py3-none-any.whl

Download URL Multi_Template_Matching-2.0.1-py3-none-any.whl
Size 12.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
36498029b13870d19256fba25de7c8cc1ff67946481ac0484dac9eaa5e26c10f
BLAKE2b-256 checksum
How to use checksums
19095f82526b58288f1f3e0ac4407322a2845ada6d18bad803c60738fbd46a5b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.10.11

Release history Release notifications | RSS feed

This release

2.0.1 This release

2 release files

2.0.0

2 release files

1.6.6

2 release files

1.6.5

2 release files

1.6.4

2 release files

1.6.3

2 release files

1.6.2

2 release files

1.6.1

2 release files

1.6.0

2 release files

1.5.3

2 release files

1.5.2

2 release files

1.5.1

2 release files

1.4

2 release files

1.3

2 release files

1.2

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page