void CWvltDoc::OnFilterSmoothmean()//均值滤波
{
LPBITMAPFILEHEADER lpBitmapFileHeader = (LPBITMAPFILEHEADER)m_pBitmap;
LPBITMAPINFOHEADER lpBitmapInfoHeader = (LPBITMAPINFOHEADER)(m_pBitmap + 14);
unsigned char *lpData = m_pBitmap + lpBitmapFileHeader->bfOffBits;
unsigned long biHeight = lpBitmapInfoHeader->biHeight;
unsigned long biWidth = lpBitmapInfoHeader->biWidth;
unsigned long biAlign = (biWidth * 3 + 3) / 4 * 4;
unsigned long bmSize = biHeight * biAlign;
if (m_pTransfered == NULL)
m_pTransfered = (unsigned char*)malloc(bmSize);
if (m_pTransfered == NULL)
return;
//Add the processing code here, which reverses the color of each pixel.
int x, y, cur;
for (y = 1; y < (int)biHeight-1; y++)
{
for (x = 1; x < (int)biWidth-1; x++)
{
cur = y*biAlign + 3 * x;
int i,j,sum;
int data[9];
for (i = 0; i < 3; i++)//选择G、B、R分量
{
sum = 0;
for (j = 0; j < 9; j++)//3*3模板
{
data[j] = lpData[(cur+i)-3*(4-j)];
sum = sum + data[j];
}
m_pTransfered[cur+i] = (int)(sum/9);
}
}
}
UpdateAllViews(NULL);//文档被修改后可调用此函数,把文档被修改的信息通知给每个视图.
}
效果图:
处理前
<img src="https://img-blog.csdn.net/20161106112612353?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="" />
处理后
<img src="https://img-blog.csdn.net/20161106112624588?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="" />