erode腐蚀实现

原理:
erode腐蚀实现
实现:

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;
		}
	}
}
上一篇:激活函数之tanh介绍及C++/PyTorch实现


下一篇:利用python实现windows下文件名批量修改