图像处理——去除拍摄电子屏幕时产生的彩色波纹



图像处理——去除拍摄电子屏幕时产生的彩色波纹

1.中值滤波

1.将所求像素点周围的8个像素点以及本身存于一个数组中,再分别建立三个数组,分别是numR[9]numG[9],numB[9]。用于分别存储前九个像素点的R,G,B值,再依次对numR[9]numG[9],numB[9]进行快速排序,取三个数组的中值作为所求像素点的新的RGB值。如图1.1,图1.2。

                                         图1.1 

均值滤波运算过程如下


                      图1.2

中值滤波GDI+代码如下

for (int x = 0; x < w - 1; x++)
	{
		for (int y = 0; y < h - 1; y++)
		{
int n = 0;
			for (int col = -2; col <= 2; col++)
			{
				for (int row = -2; row <= 2; row++)
				{
					src->GetPixel(x + col, y + row, &color[n]);
					numR[n] = color[n].GetR();
					numG[n] = color[n].GetG();
					numB[n] = color[n].GetB();
					n++;
				}
			}
			qsort(numR, 25, sizeof(numR[0]), cmp);
			qsort(numG, 25, sizeof(numG[0]), cmp);
			qsort(numB, 25, sizeof(numB[0]), cmp);
dest->SetPixel(x,y,Color(BYTE(numR[12]),BYTE(numG[12]),BYTE(numB[1])));
		}
	}
	graph->DrawImage(dest, w+2, 0, w, h);
int cmp(const void*a, const void*b)
{
	return*(int*)a - *(int*)b;
}

2.混合均值滤波

混合均值滤波是在均值滤波的基础上改进得来的一种算法,类似于混合中值滤波

 图2.1

 混合均值滤波GDI+算法如下

for (int x = 0; x < w - 1; x++)
	{
		for (int y = 0; y < h - 1; y++)
		{
			int n = 0;
			for (int col = -1; col <= 1; col++)
			{
				for (int row = -1; row <= 1; row++)
				{
					src->GetPixel(x + col, y + row, &color[n]);
					n++;
				}
			}
			total_numR[0] = (color[1].GetR() + color[3].GetR() + color[4].GetR() + color[5].GetR() + color[7].GetR()) / 5;
			total_numR[1] = (color[0].GetR() + color[2].GetR() + color[4].GetR() + color[6].GetR() + color[8].GetR()) / 5;
			total_numR[2] = (total_numR[0] + total_numR[1] + color[4].GetR()) / 3;
			total_numG[0] = (color[1].GetG() + color[3].GetG() + color[4].GetG() + color[5].GetG() + color[7].GetG()) / 5;
			total_numG[1] = (color[0].GetG() + color[2].GetG() + color[4].GetG() + color[6].GetG() + color[8].GetG()) / 5;
			total_numG[2] = (total_numG[0] + total_numG[1] + color[4].GetG()) / 3;
			total_numB[0] = (color[1].GetB() + color[3].GetB() + color[4].GetB() + color[5].GetB() + color[7].GetB()) / 5;
			total_numB[1] = (color[0].GetB() + color[2].GetB() + color[4].GetB() + color[6].GetB() + color[8].GetB()) / 5;
			total_numB[2] = (total_numB[0] + total_numB[1] + color[4].GetB()) / 3;
			dest->SetPixel(x, y, Color(BYTE(total_numR[2]+20), BYTE(total_numG[2]+20), BYTE(total_numB[2]+20)));
		}
}

混合均值滤波可以将图片的彩色波纹减弱,并对原图产生较小的模糊效果,而中值滤波可以去掉弱彩色波纹,所以两个算法一起使用会达到对彩色波纹取出的效果,但由于中值滤波特性,在将波纹去掉的同时,图片也可能有较大程度的模糊。



  • 2
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值