How it works...
In step 1, the threshold_otsu() function from the scikit-image.filters module was used to find the optimal threshold for creating the binary image (by thresholding the grayscale image).
In step 2, the binary_erosion() and binary_dilation() functions from scipy.ndimage were used to apply erosion and dilation operations to a binary image, respectively. These functions accept the binary image to be eroded/dilated, the structuring element to be used (the default SE is a square with connectivity 1), and the number of times the operation is to be repeated (default 1). Non-zero elements are considered True.
As you can observe, np.ones((2,2) was used to create a square SE of size 2, whereas morph.disk(radius=2) was used to generate ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access