原理:
实现:
void Erode(Mat& src, Mat& dst, Size size)
{
dst = Mat::zeros(src.size(), src.type());
Mat mid;
int h = (size.height - 1) / 2, w = (size.width - 1) / 2;
copyMakeBorder(src, mid, h, h, w, w, BORDER_DEFAULT);
for (int i = h; i < src.rows + h; ++i)
{
for (int j = w; j < src.cols + w; ++j)
{
Mat kernel = mid(Rect(j - w, i - h, size.width, size.height));
double minValue, maxValue;
Point minIdx, maxIdx;
minMaxLoc(kernel, &minValue, &maxValue, &minIdx, &maxIdx);
dst.at<uchar>(i - h, j - w) = minValue;
}
}
}