void CGainOffsetTestDlg::FilterImage(int *pDst, WORD *pSrc, int nWidth, int nHeight, UINT nMode)
{
//template array
float Template_Smooth_Box[9]={1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f};
float Template_Smooth_Gauss[9]={1.0f,2.0f,1.0f,2.0f,4.0f,2.0f,1.0f,2.0f,1.0f};
float Template_Sharpen_Laplacian[9]={-1.0f,-1.0f,-1.0f,-1.0f,9.0f,-1.0f,-1.0f,-1.0f,-1.0f};
float Template_HSobel[9]={ -1.0f, 0.0f, 1.0f,
-2.0f, 0.0f, 2.0f,
-1.0f, 0.0f, 1.0f};
float Template_VSobel[9]={ -1.0f, -2.0f, -1.0f,
0.0f, 0.0f, 0.0f,
1.0f, 2.0f, 1.0f};
float Template_HIsoSobel[9]={ -1.0f, 0.0f, 1.0f,
-1.4142f, 0.0f, 1.4142f,
-1.0f, 0.0f, 1.0f};
float Template_VIsoSobel[9]={ -1.0f, -1.4142f, -1.0f,
0.0f, 0.0f, 0.0f,
1.0f, 1.4142f, 1.0f};
// float Template_Log[25]={ -2.0f, -4.0f, -4.0f, -4.0f, -2.0f,
// -4.0f, 0.0f, 8.0f, 0.0f, -4.0f,
// -4.0f, 8.0f, 24.0f, 8.0f, -4.0f,
// -4.0f, 0.0f, 8.0f, 0.0f, -4.0f,
// -2.0f, -4.0f, -4.0f, -4.0f, -2.0f};
float Template_Diagonal[9]={ -1.0f, -1.4142f, 0.0f,
-1.414f, 0.0f, 1.4142f,
0.0f, 1.4142f, 1.0f};
float Template_DSobel[9]={ -1.0f, -2.0f, 0.0f,
-2.0f, 0.0f, 2.0f,
0.0f, 2.0f, 1.0f};
float Template_DXSobel[9]={ 0.0f, 2.0f, 1.0f,
-2.0f, 0.0f, 2.0f,
-1.0f, -2.0f, 0.0f};
int x=0,y=0;
float coef=0,TempNum=0;
float CoefArray[9];
switch(nMode)
{
case TEMPLATE_SMOOTH_BOX:
coef=(float)(1.0/9.0);
memcpy(CoefArray,Template_Smooth_Box,9*sizeof(float));
break;
case TEMPLATE_SMOOTH_GAUSS:
coef=(float)(1.0/16.0);
memcpy(CoefArray,Template_Smooth_Gauss,9*sizeof(float));
break;
case TEMPLATE_SHARPEN_LAPLACIAN:
coef=(float)1.0;
memcpy(CoefArray,Template_Sharpen_Laplacian,9*sizeof(float));
break;
case TEMPLATE_SOBEL_H:
coef=(float)1.0;
memcpy(CoefArray,Template_HSobel,9*sizeof(float));
break;
case TEMPLATE_SOBEL_V:
coef=(float)1.0;
memcpy(CoefArray,Template_VSobel,9*sizeof(float));
break;
case TEMPLATE_SOBEL_D:
coef=(float)1.0;
memcpy(CoefArray,Template_DSobel,9*sizeof(float));
break;
case TEMPLATE_SOBEL_DX:
coef=(float)1.0;
memcpy(CoefArray,Template_DXSobel,9*sizeof(float));
break;
case TEMPLATE_ISOSOBEL_H:
coef=(float)1.0;
memcpy(CoefArray,Template_HIsoSobel,9*sizeof(float));
break;
case TEMPLATE_ISOSOBEL_V:
coef=(float)1.0;
memcpy(CoefArray,Template_VIsoSobel,9*sizeof(float));
break;
case TEMPLATE_DIAGONAL_S:
coef=(float)1.0f;
memcpy (CoefArray,Template_Diagonal,9*sizeof(float));
break;
}
// memcpy (pDst,pSrc,nWidth*nHeight);
for(y=1;y {
for(x=1;x {
int temp=(y)*nWidth+x;
TempNum =((float)pSrc[temp+nWidth-1])* CoefArray[0];
TempNum+=((float)pSrc[temp+nWidth]) * CoefArray[1];
TempNum+=((float)pSrc[temp+nWidth+1])* CoefArray[2];
TempNum+=((float)pSrc[temp-1]) * CoefArray[3];
TempNum+=( float)pSrc[temp] * CoefArray[4];
TempNum+=((float)pSrc[temp+1]) * CoefArray[5];
TempNum+=((float)pSrc[temp-nWidth-1])* CoefArray[6];
TempNum+=((float)pSrc[temp-nWidth]) * CoefArray[7];
TempNum+=((float)pSrc[temp-nWidth+1])* CoefArray[8];
TempNum*=coef;
pDst[temp] = (int) (TempNum);
}
}
}
void FilterImage(int *pDst, int *pSrc, int nWidth, int nHeight, UINT nMode)
{
//template array
float Template_Smooth_Box[9]={1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f};
float Template_Smooth_Gauss[9]={1.0f,2.0f,1.0f,2.0f,4.0f,2.0f,1.0f,2.0f,1.0f};
float Template_Sharpen_Laplacian[9]={-1.0f,-1.0f,-1.0f,-1.0f,9.0f,-1.0f,-1.0f,-1.0f,-1.0f};
float Template_HSobel[9]={ -1.0f, 0.0f, 1.0f,
-2.0f, 0.0f, 2.0f,
-1.0f, 0.0f, 1.0f};
float Template_VSobel[9]={ -1.0f, -2.0f, -1.0f,
0.0f, 0.0f, 0.0f,
1.0f, 2.0f, 1.0f};
float Template_HIsoSobel[9]={ -1.0f, 0.0f, 1.0f,
-1.4142f, 0.0f, 1.4142f,
-1.0f, 0.0f, 1.0f};
float Template_VIsoSobel[9]={ -1.0f, -1.4142f, -1.0f,
0.0f, 0.0f, 0.0f,
1.0f, 1.4142f, 1.0f};
// float Template_Log[25]={ -2.0f, -4.0f, -4.0f, -4.0f, -2.0f,
// -4.0f, 0.0f, 8.0f, 0.0f, -4.0f,
// -4.0f, 8.0f, 24.0f, 8.0f, -4.0f,
// -4.0f, 0.0f, 8.0f, 0.0f, -4.0f,
// -2.0f, -4.0f, -4.0f, -4.0f, -2.0f};
float Template_Diagonal[9]={ -1.0f, -1.4142f, 0.0f,
-1.414f, 0.0f, 1.4142f,
0.0f, 1.4142f, 1.0f};
float Template_DSobel[9]={ -1.0f, -2.0f, 0.0f,
-2.0f, 0.0f, 2.0f,
0.0f, 2.0f, 1.0f};
float Template_DXSobel[9]={ 0.0f, 2.0f, 1.0f,
-2.0f, 0.0f, 2.0f,
-1.0f, -2.0f, 0.0f};
int x=0,y=0;
float coef=0,TempNum=0;
float CoefArray[9];
switch(nMode)
{
case TEMPLATE_SMOOTH_BOX:
coef=(float)(1.0/9.0);
memcpy(CoefArray,Template_Smooth_Box,9*sizeof(float));
break;
case TEMPLATE_SMOOTH_GAUSS:
coef=(float)(1.0/16.0);
memcpy(CoefArray,Template_Smooth_Gauss,9*sizeof(float));
break;
case TEMPLATE_SHARPEN_LAPLACIAN:
coef=(float)1.0;
memcpy(CoefArray,Template_Sharpen_Laplacian,9*sizeof(float));
break;
case TEMPLATE_SOBEL_H:
coef=(float)1.0;
memcpy(CoefArray,Template_HSobel,9*sizeof(float));
break;
case TEMPLATE_SOBEL_V:
coef=(float)1.0;
memcpy(CoefArray,Template_VSobel,9*sizeof(float));
break;
case TEMPLATE_SOBEL_DX:
coef=(float)1.0;
memcpy(CoefArray,Template_DXSobel,9*sizeof(float));
break;
case TEMPLATE_SOBEL_D:
coef=(float)1.0;
memcpy(CoefArray,Template_DSobel,9*sizeof(float));
break;
case TEMPLATE_ISOSOBEL_H:
coef=(float)1.0;
memcpy(CoefArray,Template_HIsoSobel,9*sizeof(float));
break;
case TEMPLATE_ISOSOBEL_V:
coef=(float)1.0;
memcpy(CoefArray,Template_VIsoSobel,9*sizeof(float));
break;
case TEMPLATE_DIAGONAL_S:
coef=(float)1.0f;
memcpy (CoefArray,Template_Diagonal,9*sizeof(float));
break;
}
// memcpy (pDst,pSrc,nWidth*nHeight);
for(y=1;y {
for(x=1;x {
int temp=(y)*nWidth+x;
TempNum =((float)pSrc[temp+nWidth-1])*CoefArray[0];
TempNum+=((float)pSrc[temp+nWidth])*CoefArray[1];
TempNum+=((float)pSrc[temp+nWidth+1])*CoefArray[2];
TempNum+=((float)pSrc[temp-1])*CoefArray[3];
TempNum+=( float)pSrc[temp]*CoefArray[4];
TempNum+=((float)pSrc[temp+1])*CoefArray[5];
TempNum+=((float)pSrc[temp-nWidth-1])*CoefArray[6];
TempNum+=((float)pSrc[temp-nWidth])*CoefArray[7];
TempNum+=((float)pSrc[temp-nWidth+1])*CoefArray[8];
TempNum*=coef;
pDst[temp] = (int) (TempNum);
}
}
}