import cv2 as cv
import matplotlib.pyplot as plt
import numpy as np
img = cv.imread('sg.png', cv.IMREAD_GRAYSCALE)
kernel = np.ones((3, 3), np.uint8)
imge = img.copy()
imgen = cv.erode(imge, kernel, iterations=3)
imgem = cv.dilate(imge, kernel, iterations=3)
x1, y1 = imge.shape[:2]
x2, y2 = imgen.shape[:2]
x3, y3 = imgem.shape[:2]
cc = cv.resize(imge, ((int(y1 / 2)), (int(x1 / 2))))
dd = cv.resize(imgen, ((int(y2 / 2)), (int(x2 / 2))))
ff = cv.resize(imgem, (int(y3 / 2), int(x3 / 2)))
hello = np.hstack((cc, dd, ff))
cv.imshow('window', hello)
cv.waitKey(0)
输出: