邊緣檢測-Prewitt 算子
http://blog.csdn.net/wqvbjhc/article/details/6065497
Prewitt 算子采用以下算子分別計算一階 x 方向和 y 方向的圖像差分:
- #include
-
-
-
-
-
- bool Prewitt(unsigned char *pImageData, int nWidth, int nHeight, int nWidthStep)
- {
- int i = 0;
- int j = 0;
- int dx = 0;
- int dy = 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++)
- {
- dx =
- pLine[0][i+1] - pLine[0][i-1] +
- pLine[1][i+1] - pLine[1][i-1] +
- pLine[2][i+1] - pLine[2][i-1];
- dy =
- pLine[2][i-1] - pLine[0][i-1] +
- pLine[2][i] - pLine[0][i] +
- pLine[2][i+1] - pLine[0][i+1];
- nValue = (int) sqrt((float) (dx * dx + dy * dy));
- if (nValue > 0xFF)
- {
- nValue = 0xFF;
- }
- pLine[0][i-1] = (unsigned char) nValue;
- }
- }
- return true;
- }
沒有留言:
張貼留言