摩尔纹
用数码相机拍摄景物中,如果有密纹的纹理,常常会出现莫名其妙的水波样条纹。这就是摩尔纹。简单的说,摩尔纹是差拍原理的一种表现。从数学上讲,两个频率接近的等幅正弦波叠加,合成信号的幅度将按照两个频率之差变化。差拍原理广泛应用到广播电视和通信中,用来变频、调制等。同样,差拍原理也适用于空间频率。空间频率略有差异的条纹叠加,由于条纹间隔的差异、重合位置会逐渐偏移,也会形成差拍。
摩尔纹的实现
源码:
void add_moire_noise(Mat& src,Mat& dst,Point center,int degree)
{
int width = src.cols;
int heigh = dst.rows;
for (int y = 0; y < heigh; y++)
{
uchar* data = dst.ptr<uchar>(y);
uchar* data0 = src.ptr<uchar>(y);
for (int x = 0; x < width; x++)
{
Point offset(x - center.x, y - center.y);
double theta = atan2((double)offset.y, (double)offset.x);
double rou = sqrt(pow((double)offset.x, 2) + pow((double)offset.y, 2));
int newX = center.x + rou * cos(theta + degree * rou);
int newY = center.y + rou * sin(theta + degree * rou);
if (newX < 0)
newX = 0;
else if (newX >= width)
newX = width - 1;
if (newY < 0)
newY = 0;
else if (newY >= heigh)
newY = heigh - 1;
data[3 * x] = 0.8 * data0[3 * x]+ 0.2 * src.at<uchar>(newY, newX * 3);
data[3 * x + 1] = 0.8 * data0[3 * x + 1]+ 0.2 * src.at<uchar>(newY, newX * 3 + 1);
data[3 * x + 2] = 0.8 * data0[3 * x + 2]+ 0.2 * src.at<uchar>(newY, newX * 3 + 2);
}
}
}
原图:
摩尔纹: