You need to perform the following steps to be able to apply some of the morphological operators to a binary image using the functions from the scipy.ndimage.morphology module:
- Read the input giraffe image and convert it into a binary image using thresholding. Obtain the optimal threshold with Otsu's algorithm and then change the pixels with values above the threshold to white and black:
im = rgb2gray(imread('images/giraffe.jpg'))thres = threshold_otsu(im)im = (im > thres).astype(np.uint8)
- Erode the image with a 2 x 2 square structuring element (SE/kernel) and invert the image:
eroded = binary_erosion(im, structure=np.ones((2,2)), iterations=20)[20:,20:]eroded = 1 - eroded
- Now, dilate the eroded image with an 11 x 11 square ...