Laplace 算子可以卷積模板表示:
| 0 | 1 | 0 |
| 1 | -4 | 1 |
| 0 | 1 | 0 |
- // Laplace 算子
- // 1. pImageData 圖像數據
- // 2. nWidth 圖像寬度
- // 3. nHeight 圖像高度
- // 4. nWidthStep 圖像行大小
- bool Laplace(unsigned char *pImageData, int nWidth, int nHeight, int nWidthStep)
- {
- int i = 0;
- int j = 0;
- int nValue = 0;
- unsigned char *pLine[3] = { NULL, NULL, NULL };
- for (j = 1; j < nHeight - 1; j++)
- {
- pLine[0] = pImageData + nWidthStep * (j - 1);
- pLine[1] = pImageData + nWidthStep * j;
- pLine[2] = pImageData + nWidthStep * (j + 1);
- for (i = 1; i < nWidth - 1; i++)
- {
- nValue =
- pLine[0][i] + pLine[1][i-1] + pLine[1][i+1] + pLine[2][i] -
- pLine[1][i] * 4;
- if (nValue < 0) pLine[0][i-1] = 0;
- else pLine[0][i-1] = (unsigned char) nValue;
- }
- }
- return true;
- }

沒有留言:
張貼留言