为什么我的opencv的腐蚀和膨胀操作是反的?

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)

输出:

你的理解有问题,腐蚀是指白色部分被黑色腐蚀了(白色变小),膨胀是指白色部分变大了。腐蚀和膨胀是看白色(灰度大于0)部分而不是黑色(灰度0)