Python Automation and Machine Learning for EM and ICs

An Online Book, Second Edition by Dr. Yougui Liao (2019)

Python Automation and Machine Learning for EM and ICs - An Online Book

Chapter/Index: Introduction | A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R | S | T | U | V | W | X | Y | Z | Appendix

Match on images to find and to highlight unsimilar (threshold=0) to identical (threshold=1) regions of an image that match a template with a cross-correlation method

This Python script (code) uses OpenCV and EasyGUI to perform template matching on images. First, it prompts the user to select an image (referred to as the ImagePool) and a template image. Both images are read, and the main image is converted to grayscale. The script then uses the cv2.matchTemplate() function with the cv2.TM_CCOEFF_NORMED method to find regions in the main image that closely resemble the template. The user is prompted to input a matching threshold (e.g., 0.95), which determines how closely a region must match the template to be considered a valid match. All regions in the main image that meet or exceed this threshold are highlighted with yellow rectangles. Finally, the script displays the result and saves the output image with annotations as Analyzed.tif in the specified directory. This tool is useful for detecting repeated patterns or objects in images, such as coins, symbols, or features.