Skip to content

Plugin_Template matching image

Laurent Thomas edited this page Mar 25, 2020 · 3 revisions

Template Matching Image

This plugin version takes as input a single template, and an image (or stack) for the target image.
If a stack is provided, the the search is performed for every slice.
The 2 images must be opened in Fiji before the plugin is called.

Limit the search to a ROI

If some information about the position of the object in the image is known, then the searched can be limited to a rectangular region of interest.
To do so, draw a rectangular region of interest on the image before calling the plugin.
With a stack, the ROI can be drawn on any slice and will be applied to the rest of the slices.

Image with ROI for search region (yellow)
SearchRoi

The macro will return the detected region as a ROI and a result table with the dimensions of the bounding box and score.

Macro-recording

This macro can be recorded using the macro-recorder to be used in custom-made macro scripts.
The macro command looks like the following.

run("Template Matching Image", "template=Head.tif image=Fish.tif rotate=[] matching_method=[Normalised 0-mean cross-correlation] number_of_objects=1 score_threshold=0.50 min_peak_height=0.10 maximal_overlap=0.25 add_roi");

Thus the macro can e.g. be called with other images simply by replacing the fields template and image with the names of other opened images.

A search region can also be defined to limit the search by setting a rectangular ROI on the target images like.

selectImage("Fish.tif");
makeRectangle(0, 0, 50, 50); // x, y, width, height
run("Template Matching Image", "template=Head.tif image=Fish.tif rotate=[] matching_method=[Normalised 0-mean cross-correlation] number_of_objects=1 score_threshold=0.50 min_peak_height=0.10 maximal_overlap=0.25 add_roi");