How to do it...

Perform the following steps to implement morphological pattern matching with hit-or-miss-transform:

  1. Define the hit_or_miss_transform() function that accepts the filenames corresponding to the input image and two SEs (the first one for hit and the second one for miss) as input:
def hit_or_miss_transform(im, s1, s2):
  1. Inside the function, read the input image and structuring elements, consequently converting them into grayscale:
  im = rgb2gray(imread(im))  m, n = im.shape  s1 = rgb2gray(imread(s1))  s2 = rgb2gray(imread(s2))
  1. Apply the hit-or-miss transform using corresponding functions from the scipy.ndimage module, which returns a Boolean NumPy ndarray where the elements corresponding to the match position are set to True ...

Get Python Image Processing Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.