OpenCV_9扩散(毛玻璃)

一,原图:

二,代码:

//9扩散(毛玻璃)
void DiffusionGroundGlass()
{
	Mat src = imread("D:\\test\\26.png");
	int width = src.cols;
	int heigh = src.rows;
	RNG rng;
	Mat img(src.size(), CV_8UC3);
	for (int y = 1; y<heigh - 1; y++)
	{
		uchar* P0 = src.ptr<uchar>(y);
		uchar* P1 = img.ptr<uchar>(y);
		for (int x = 1; x<width - 1; x++)
		{
			int tmp = rng.uniform(0, 9);
			P1[3 * x] = src.at<uchar>(y - 1 + tmp / 3, 3 * (x - 1 + tmp % 3));
			P1[3 * x + 1] = src.at<uchar>(y - 1 + tmp / 3, 3 * (x - 1 + tmp % 3) + 1);
			P1[3 * x + 2] = src.at<uchar>(y - 1 + tmp / 3, 3 * (x - 1 + tmp % 3) + 2);
		}

	}
	imshow("扩散", img);
	waitKey();
	imwrite("D:/扩散.jpg", img);
}

//-----开始------
void COpenCVLearningDlg::OnBnClickedStartButton()
{
	DiffusionGroundGlass();
}

三,结果:

 

欢迎扫码关注我的微信公众号

原文地址:https://blog.csdn.net/sangni007/column/info/stylizefliter

猜你喜欢

转载自blog.csdn.net/sxlsxl119/article/details/84863935