2020-12-26

不打扰是莪最后的温柔 提交于 2020-12-29 13:56:30

数字图像处理(湍流模型,运动模糊噪声的添加及逆滤波)

1.湍流模型噪声的添加及逆滤波

这里是在频域添加的,就是要先进行(快速)傅里叶正变换得到图像的频域,再在频域添加湍流模型噪声,不会快速傅里叶变换的,可以去我上个博客看看,快速傅里叶变换在我上个博客里有写。废话不多说,直接贴代码。
注意:
1.我这里写的函数的参数名是根据我的快速傅里叶变换的频谱函参数名写的,两者要对应上
2.在逆滤波的时候要注意除以噪声的频域的实部跟虚部不能同时为零,要不然就出现“雪花”图
湍流模型噪声的添加:



std::vector<double>real_1, img_1, pfTurbuMatrix;
void CExImage1View::OnFturbu()
{
   
   
	// TODO: 在此添加命令处理程序代码
	OnFuliyekuaiz();
	int iImageWidth = m_Image.GetWidth();
	int iImageHeight = m_Image.GetHeight();
	for (int i = 0; i < iImageWidth * iImageHeight; i++)
	{
   
   
		real_1.push_back(0.0);
		img_1.push_back(0.0);
		pfTurbuMatrix.push_back(0.0);
	}
	double fTurbu = 0.0025;


	for (int v = 0; v < iImageHeight; v++)
	{
   
   
		for (int u = 0; u < iImageWidth; u++)
		{
   
   
			pfTurbuMatrix[(size_t)v * iImageWidth + u] = exp(-fTurbu * pow((pow((double)v -
				iImageHeight / 2.0, 2.0) + pow((double)u - iImageWidth / 2.0, 2.0)), 5.0 / 6.0));
			real_1[(size_t)v * iImageWidth + u] = fRealPart2[(size_t)v * iImageWidth + u] * pfTurbuMatrix[(size_t)v * iImageWidth + u];
			img_1[(size_t)v * iImageWidth + u] = fImgPart2[(size_t)v * iImageWidth + u] * pfTurbuMatrix[(size_t)v * iImageWidth + u];
		}
	}

	for (int v = 0; v < iImageHeight; v++)
	{
   
   
		for (int u = 0; u < iImageWidth; u++)
		{
   
   
			fRealPart2[(size_t)v * iImageWidth + u] = real_1[(size_t)v * iImageWidth + u];
			fImgPart2[(size_t)v * iImageWidth + u] = img_1[(size_t)v * iImageWidth + u];
		}
	}
	MessageBox(_T("添加湍流噪声,完成"));
	OnFuliyekuaif();
}

湍流模型噪声逆滤波:

void CExImage1View::OnFturbuf()
{
   
   
	// TODO: 在此添加命令处理程序代码
	OnFuliyekuaiz();
	int iImageWidth = m_Image.GetWidth();
	int iImageHeight = m_Image.GetHeight();
	real_1.clear();
	img_1.clear();
	for (int i = 0; i < iImageWidth * iImageHeight; i++)
	{
   
   
		real_1.push_back(0.0);
		img_1.push_back(0.0);
	}
	double fTurbu = 0.0025;

	for (int v = 0; v < iImageHeight; v++)
	{
   
   
		for (int u = 0; u < iImageWidth; u++)
		{
   
   
			if ((pow((double)v - iImageHeight / 2.0, 2) + pow((double)u - iImageWidth / 2.0, 2)) < 4900)
			{
   
   
				real_1[(size_t)v * iImageWidth + u] = fRealPart2[(size_t)v * iImageWidth + u] / pfTurbuMatrix[(size_t)v * iImageWidth + u];
				img_1[(size_t)v * iImageWidth + u] = fImgPart2[(size_t)v * iImageWidth + u] / pfTurbuMatrix[(size_t)v * iImageWidth + u];
			}
		}
	}
	for (int v = 0; v < iImageHeight; v++)
	{
   
   
		for (int u = 0; u < iImageWidth; u++)
		{
   
   
			fRealPart2[(size_t)v * iImageWidth + u] = real_1[(size_t)v * iImageWidth + u];
			fImgPart2[(size_t)v * iImageWidth + u] = img_1[(size_t)v * iImageWidth + u];
		}
	}
	MessageBox(_T("湍流噪声逆滤波,完成"));
	OnFuliyekuaif();
}

2.运动模糊的添加及逆滤波

运动模糊的添加:

std::vector<double>real_2, img_2, Movingreal, Movingimg;
void CExImage1View::OnFmohu()
{
   
   
	// TODO: 在此添加命令处理程序代码
	OnFuliyekuaiz();
	//运动估计参数
	int iImageWidth = m_Image.GetWidth();
	int iImageHeight = m_Image.GetHeight();

	for (int i = 0; i < iImageWidth * iImageHeight; i++)
	{
   
   
		Movingreal.push_back(0.0);
		Movingimg.push_back(0.0);
	}
	double fA, fB, fT;
	fA = 0.1;
	fB = 0.1;
	fT = 1.0;
	for (int i = 0; i < iImageWidth * iImageHeight; i++)
	{
   
   
		real_2.push_back(0.0);
		img_2.push_back(0.0);

	}
	for (int v = 0; v < iImageHeight; v++)
	{
   
   
		for (int u = 0; u < iImageWidth; u++)
		{
   
   
			//获取运动估计模型
			double fCenterX = (double)u - iImageWidth / 2.0;
			double fCenterY = (double)v - iImageHeight / 2.0;
			double fScale = PI * (fCenterX * fA + fCenterY * fB);
			if (fScale == 0)
			{
   
   
				Movingreal[(size_t)v * iImageWidth + u] = 1.0;
				Movingimg[(size_t)v * iImageWidth + u] = 0;
			}
			else
			{
   
   
				Movingreal[(size_t)v * iImageWidth + u] = fT * sin(fScale) / (fScale) * (cos(fScale));
				Movingimg[(size_t)v * iImageWidth + u] = fT * sin(fScale) / (fScale) * (-sin(fScale));
			}
			real_2[(size_t)v * iImageWidth + u] = fRealPart2[(size_t)v * iImageWidth + u] * Movingreal[(size_t)v * iImageWidth + u]
				- fImgPart2[(size_t)v * iImageWidth + u] * Movingimg[(size_t)v * iImageWidth + u];
			img_2[(size_t)v * iImageWidth + u] = fRealPart2[(size_t)v * iImageWidth + u] * Movingimg[(size_t)v * iImageWidth + u]
				+ fImgPart2[(size_t)v * iImageWidth + u] * Movingreal[(size_t)v * iImageWidth + u];
		}
	}
	for (int v = 0; v < iImageHeight; v++)
	{
   
   
		for (int u = 0; u < iImageWidth; u++)
		{
   
   
			fRealPart2[(size_t)v * iImageWidth + u] = real_2[(size_t)v * iImageWidth + u];
			fImgPart2[(size_t)v * iImageWidth + u] = img_2[(size_t)v * iImageWidth + u];
		}
	}
	MessageBox(_T("添加运动模糊,完成"));
	OnFuliyekuaif();
}

运动模糊逆滤波:

void CExImage1View::OnFmohuf()
{
   
   
	// TODO: 在此添加命令处理程序代码
	OnFuliyekuaiz();
	int iImageWidth = m_Image.GetWidth();
	int iImageHeight = m_Image.GetHeight();
	std::vector<double>real_3, img_3, Movingreal1, Movingimg1;
	for (int i = 0; i < iImageWidth * iImageHeight; i++)
	{
   
   
		real_3.push_back(0.0);
		img_3.push_back(0.0);
		Movingreal1.push_back(0.0);
		Movingimg1.push_back(0.0);
	}
	double fA, fB, fT;
	fA = 0.1;
	fB = 0.1;
	fT = 1.0;
	for (int v = 0; v < iImageHeight; v++)
	{
   
   
		for (int u = 0; u < iImageWidth; u++)
		{
   
   
			//获取运动估计模型
			double fCenterX = (double)u - iImageWidth / 2.0;
			double fCenterY = (double)v - iImageHeight / 2.0;
			double fScale = PI * (fCenterX * fA + fCenterY * fB);
			if ((pow((double)v - iImageHeight / 2.0, 2) + pow((double)u - iImageWidth / 2.0, 2)) < 4900)
			{
   
   
				if (fScale == 0)
				{
   
   
					Movingreal1[(size_t)v * iImageWidth + u] = fT;
					Movingimg1[(size_t)v * iImageWidth + u] = 0;
				}
				else
				{
   
   
					Movingreal1[(size_t)v * iImageWidth + u] = fT * sin(fScale) / (fScale) * (cos(fScale));
					Movingimg1[(size_t)v * iImageWidth + u] = -fT * sin(fScale) / (fScale) * (-sin(fScale));
					if (sqrt(pow(Movingreal1[(size_t)v * iImageWidth + u], 2) + pow(Movingimg1[(size_t)v * iImageWidth + u], 2)) < 0.001)
					{
   
   
						Movingreal1[(size_t)v * iImageWidth + u] = 1.0;
						Movingimg1[(size_t)v * iImageWidth + u] = 0;
					}
				}

				real_3[(size_t)v * iImageWidth + u] = (fRealPart2[(size_t)v * iImageWidth + u] * Movingreal1[(size_t)v * iImageWidth + u]
					- fImgPart2[(size_t)v * iImageWidth + u] * Movingimg1[(size_t)v * iImageWidth + u]) / (double)(pow(Movingreal1[(size_t)v * iImageWidth + u], 2)
						+ pow(Movingimg1[(size_t)v * iImageWidth + u], 2));
				img_3[(size_t)v * iImageWidth + u] = (fRealPart2[(size_t)v * iImageWidth + u] * Movingimg1[(size_t)v * iImageWidth + u]
					+ fImgPart2[(size_t)v * iImageWidth + u] * Movingreal1[(size_t)v * iImageWidth + u]) / (double)(pow(Movingreal1[(size_t)v * iImageWidth + u], 2)
						+ pow(Movingimg1[(size_t)v * iImageWidth + u], 2));
				fRealPart2[(size_t)v * iImageWidth + u] = real_3[(size_t)v * iImageWidth + u];
				fImgPart2[(size_t)v * iImageWidth + u] = img_3[(size_t)v * iImageWidth + u];
			}
		}
	}
	MessageBox(_T("运动模糊逆滤波,完成"));
	OnFuliyekuaif();
}
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!