銳化(sharpening)和平滑恰恰相反,它是通過增強高頻分量來減少圖象中的模糊,是以又稱為高通濾波(high passfilter)。銳化處理在增強圖象邊緣的同時增加了圖象的噪聲。
常用的銳化模闆是拉普拉斯(Laplacian)模闆(見(3.4)式),又是個數學家的名字,可見學好數學,走遍天下都不怕。

(3.4)
容易看出拉普拉斯模闆的作法:先将自身與周圍的8個象素相減,表示自身與周圍象素的差别;再将這個差别加上自身作為新象素的灰階。可見,如果一片暗區出現了一個亮點,那麼銳化處理的結果是這個亮點變得更亮,增加了圖象的噪聲。
因為圖象中的邊緣就是那些灰階發生跳變的區域,是以銳化模闆在邊緣檢測中很有用,這一點将在後面詳細介紹。
功能實作code:
/**
* 函數名: sharpening
* 功 能: 對圖像進行銳化處理
*/
void Laplacian()
{
int temp[9] = {-1,-1,-1,-1,9,-1,-1,-1,-1}; //Laplacian 模版
int height = bmpInfoHeader.biHeight;
int width = bmpInfoHeader.biWidth;
int imgSize = bmpInfoHeader.biSizeImage;
int lineByte = (width * 8 +31) / 32 * 4; //每行像素所占位元組數
//處理是基于原圖的,是以原圖的資料不能改變,用pNewBmpData存儲改變之後的資料
memcpy(pNewBmpData,pBmpData,imgSize); //把原圖資料複制給pNewBmpData
//注意邊界點不處理,是以i從1到高度-2,j類似
double temResult; //中間結果
for(int i = 1; i < height - 1; i++ )
{
for(int j = 1; j < width - 1; j++ )
{
temResult = (double)(*(pBmpData + (i-1) * lineByte + j - 1) * temp[0]);
temResult += (double)(*(pBmpData + (i-1) * lineByte + j) * temp[1]);
temResult += (double)(*(pBmpData + (i-1) * lineByte + j + 1) * temp[2]);
temResult += (double)(*(pBmpData + (i) * lineByte + j - 1) * temp[3]);
temResult += (double)(*(pBmpData + (i) * lineByte + j) * temp[4]);
temResult += (double)(*(pBmpData + (i) * lineByte + j + 1) * temp[5]);
temResult += (double)(*(pBmpData + (i+1) * lineByte + j - 1) * temp[6]);
temResult += (double)(*(pBmpData + (i+1) * lineByte + j) * temp[7]);
temResult += (double)(*(pBmpData + (i+1) * lineByte + j + 1) * temp[8]);
*(pNewBmpData + i * lineByte + j) = temResult;
}
}
}