锘??xml version="1.0" encoding="utf-8" standalone="yes"?>
鍥懼儚騫蟲粦鐢ㄤ簬鍘婚櫎鍥懼儚涓殑鍣0銆傞珮鏂鉤婊戯紝灝辨槸灝嗘瘡涓儚绱犵殑鐏板害鍊肩敤鍏墮鍩熺殑鍔犳潈騫沖潎鍊間唬鏇褲傝綆楁硶綆鍗曪紝鑳藉鏈夋晥鍘婚櫎楂樻柉鍣0銆?br />
騫蟲粦妯℃澘錛?br />
1 2 1
2 4 2
1 2 1
// 楂樻柉騫蟲粦
// 1. pImageData 鍥懼儚鏁版嵁
// 2. nWidth 鍥懼儚瀹藉害
// 3. nHeight 鍥懼儚楂樺害
// 4. nWidthStep 鍥懼儚琛屽ぇ灝?/span>
void SmoothGauss(unsigned char *pImageData, int nWidth, int nHeight, int nWidthStep)
{
int i = 0;
int j = 0;
unsigned char *pLine[3] = { NULL, NULL, NULL };
int nTemplate[9] = { 1, 2, 1, 2, 4, 2, 1, 2, 1 };
for (j = 1; j < nHeight - 1; j++)
{
pLine[0] = pImageData + nWidthStep * (j - 1); //涓?琛屽湴鍧
pLine[1] = pImageData + nWidthStep * j; //褰撳墠琛屽湴鍧
pLine[2] = pImageData + nWidthStep * (j + 1); //涓?琛屽湴鍧
int nValue = 0;
for (i = 1; i < nWidth - 1; i++)
{
nValue = (pLine[0][i-1] * nTemplate[0] +
pLine[0][i] * nTemplate[1] +
pLine[0][i+1] * nTemplate[2] +
pLine[1][i-1] * nTemplate[3] +
pLine[1][i] * nTemplate[4] +
pLine[1][i+1] * nTemplate[5] +
pLine[2][i-1] * nTemplate[6] +
pLine[2][i] * nTemplate[7] +
pLine[2][i+1] * nTemplate[8]) / 16;
pLine[0][i-1] = (unsigned char) nValue;
}
}
}
鏉ユ簮:http://blog.csdn.net/wqvbjhc/article/details/6065526
/*
nR:紿楀彛澶у皬
*/
void GaussianSmooth2(uchar *pSrcImg, int nW, int nH,int nR, float sigma, uchar* pDstImg)
{
if(NULL==pSrcImg)
return;
int i,j,x,y;
// 楂樻柉婊ゆ嘗鍣ㄧ殑鏁扮粍闀垮害
// 涓緇撮珮鏂暟鎹護娉㈠櫒
int nSize = nR*nR;
int nHalfLen = nR/2; // 紿楀彛闀垮害鐨?/2
float *pdKernel = new float[nSize];
// 楂樻柉緋繪暟涓庡浘璞℃暟鎹殑鐐逛箻
float dDotMul = 0.0 ;
// 楂樻柉婊ゆ嘗緋繪暟鐨勬誨拰
float dWeightSum = 0.0;
float t = 0.0;
for (i=0;i<nSize;i++)
{
t = exp(-((i-nHalfLen)*(i-nHalfLen))/(2*sigma*sigma));
pdKernel[i] = t;
dWeightSum += t;
}
for (i=0;i<nSize;i++)
{
pdKernel[i]/=dWeightSum;
}
memcpy(pDstImg,pSrcImg,nW*nH);
for(y=nHalfLen; y<nH-nHalfLen; y++)
{
for(x=nHalfLen; x<nW-nHalfLen; x++)
{
dDotMul = 0.0;
for(i=-nHalfLen; i<=nHalfLen; i++)
{
for (j=-nHalfLen; j<=nHalfLen; j++)
{
dDotMul += (pdKernel[(nHalfLen+i)*3 +j+nHalfLen]*(float(pSrcImg[(y+i)*nW+ (j+x)])));
}
}
pDstImg[y*nW + x] = (int) (dDotMul);
}
}
delete [] pdKernel;
}
]]>
{
CString InputImagePath = "D:\\Images\\1.jpg";
CString OutputImagePath("D:\\Images\\8.jpg");
IplImage * image= cvLoadImage(InputImagePath);
IplImage* eqlimage=cvCreateImage(cvGetSize(image),image->depth,3);
//鍒嗗埆鍧囪 鍖栨瘡涓俊閬?/span>
IplImage* redImage =cvCreateImage(cvGetSize(image),image->depth,1);
IplImage* greenImage=cvCreateImage(cvGetSize(image),image->depth,1);
IplImage* blueImage =cvCreateImage(cvGetSize(image),image->depth,1);
cvSplit(image,blueImage,greenImage,redImage,NULL);
cvEqualizeHist(redImage,redImage);
cvEqualizeHist(greenImage,greenImage);
cvEqualizeHist(blueImage,blueImage);
//鍧囪 鍖栧悗鐨勫浘鍍?/span>
cvMerge(blueImage,greenImage,redImage,NULL,eqlimage);
//淇濆瓨鍥劇墖
cvSaveImage(OutputImagePath, eqlimage);
}
]]>
Sobel鍗風Н鍥犲瓙涓猴細
http://blog.csdn.net/goodshot/article/details/10170073
http://blog.csdn.net/yanmy2012/article/details/8110316
涓轟簡鍔犲揩綆楁硶閫熷害:
鍏堢緝灝忓浘鍍?姝ラ暱涓?,鐒跺悗璁$畻姊害,
void getGrads(unsigned char* g_lpTemp, unsigned char* g_lpDivide, int IMGW, int IMGH, long r)
{
long x, y, i, j;
long vx, vy, lvx, lvy;
unsigned char *lpSrc = NULL;
unsigned char *lpDiv = NULL;
long num;
int gradSum;
int grad;
r=6;
for(y = 0; y < IMGH/2; y++)
{
for(x = 0; x < IMGW/2; x++)
{
lpDiv = g_lpDivide + 2*y*IMGW + 2*x;
lvx = 0;
lvy = 0;
num = 0;
gradSum = 0;
for(i = -r; i <= r; i++) // 涓烘彁楂橀熷害錛屾闀夸負2
{
if(y+i<1 || y+i>=IMGH/2-1) continue;
for(j = -r; j <= r; j++) // 涓烘彁楂橀熷害錛屾闀夸負2
{
if(x+j<1 || x+j>=IMGW/2-1) continue;
lpSrc = g_lpTemp + (y+i)*(IMGW/2) + x+j;
//姹倄鏂瑰悜鍋忓
vx = *(lpSrc + IMGW/2 + 1) - *(lpSrc + IMGW/2 - 1) +
*(lpSrc + 1)*2 - *(lpSrc - 1)*2 +
*(lpSrc - IMGW/2 + 1) - *(lpSrc - IMGW/2 - 1);
//姹倅鏂瑰悜鍋忓
vy = *(lpSrc + IMGW/2 - 1) - *(lpSrc - IMGW/2 - 1) +
*(lpSrc + IMGW/2)*2 - *(lpSrc - IMGW/2)*2 +
*(lpSrc + IMGW/2 + 1) - *(lpSrc - IMGW/2 + 1);
gradSum += (labs(vx)+labs(vy));
//gradSum += vx*vx+vy*vy;
num++;
}
}
if(num == 0)
num = 1;
// 姹傚箙鍊鹼紝淇濆瓨鍒癵_lpDivide涓紝鐢ㄤ簬鍒嗗壊鍓嶆櫙鑳屾櫙
grad = gradSum/num;
if(grad > 255)
grad = 255;
*lpDiv = (BYTE)grad;
*(lpDiv + 1) = (BYTE)grad;
*(lpDiv + IMGW) = (BYTE)grad;
*(lpDiv + IMGW + 1) = (BYTE)grad;
}
}
}
]]>