Prewitt 算子采用以下算子分别计算一阶 x 方向和 y 方向的图像差分:
#include <math.h>
// Prewitt 算子
// 1. pImageData 图像数据
// 2. nWidth 图像宽度
// 3. nHeight 图像高度
// 4. nWidthStep 图像行大小
BOOL Prewitt(unsigned char *pImageData, int nWidth, int nHeight, int nWidthStep)
{
int i = 0;
int j = 0;
int nDx = 0;
int nDy = 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);
#include <math.h>
// Prewitt 算子
// 1. pImageData 图像数据
// 2. nWidth 图像宽度
// 3. nHeight 图像高度
// 4. nWidthStep 图像行大小
BOOL Prewitt(unsigned char *pImageData, int nWidth, int nHeight, int nWidthStep)
{
int i = 0;
int j = 0;
int nDx = 0;
int nDy = 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);