==============================================
版权所有:小熊不去实验室CSDN博客
==============================================
PhotoShop里的扩散,就相当于毛玻璃的感觉。
原理:用当前点四周一定范围内任意一点的颜色来替代当前点颜色,最常用的是随机的采用相邻点进行替代。
#include <math.h>
#include <opencv/cv.h>
#include <opencv/highgui.h>
using namespace cv;
using namespace std;
int main()
{
Mat src = imread("D:/scene03.jpg",1);
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);
}
原图:
扩散(毛玻璃):