图像处理――去除拍摄电子屏幕时产生的彩色波纹
1.中值滤波
1.
ͼ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.混合均值滤波
混合均值滤波是在均值滤波的基础上改进得来的一种算法,类似于混合中值滤波
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))); } }
混合均值滤波可以将图片的彩色波纹减弱,并对原图产生较小的模糊效果,而中值滤波可以去掉弱彩色波纹,所以两个算法一起使用会达到对彩色波纹取出的效果,但由于中值滤波特性,在将波纹去掉的同时,图片也可能有较大程度的模糊。
文章来源: 图像处理――去除拍摄电子屏幕时产生的彩色波纹