c++灰度共生矩阵
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
void CFeatureExtraction::TextureSpectrum256(CVisImage &vimg, float *fptrHistogram,TEXTURE_METHOD method, bool bNormalize)
{
memset(fptrHistogram,0,256*sizeof(float));//清零
int i,j,k;
//int x,y,m,n;
unsigned char V[9],tmp;
unsigned char E[8];
unsigned char NTU;
unsigned char *graydata;
CVisImage grayimage;//textureimage;
grayimage.CopyOf(vimg,0);//to gray
int widthbytes,height,widthpixels;
widthbytes=grayimage.GetWidthByBytes();
widthpixels=grayimage.Width();
height=grayimage.Height();
graydata=(unsigned char*)grayimage.GetImageData();
//textureimage.CloneImage(grayimage);
//texturedata=(unsigned char*)textureimage.GetImageData();
int iwidth,i1width,i_1width;
for(i=1;i iwidth=i*widthbytes;i1width=iwidth+widthbytes;i_1width=iwidth-widthbytes;// for speed up for(j=1;j { V[0]=graydata[iwidth+j];//grayimage.GetPixel(j,i,&V[0]);ASSERT(V[0]==graydata[iwidth+ j]);// for test V[1]=graydata[iwidth+j+1];//grayimage.GetPixel(j+1,i,&V[1]); V[2]=graydata[i1width+j+1];//grayimage.GetPixel(j+1,i+1,&V[2]); V[3]=graydata[i1width+j];//grayimage.GetPixel(j,i+1,&V[3]); V[4]=graydata[i1width+j-1];//grayimage.GetPixel(j-1,i+1,&V[4]); V[5]=graydata[iwidth+j-1];//grayimage.GetPixel(j-1,i,&V[5]); V[6]=graydata[i_1width+j-1];//grayimage.GetPixel(j-1,i-1,&V[6]); V[7]=graydata[i_1width+j];//grayimage.GetPixel(j,i-1,&V[7]); V[8]=graydata[i_1width+j+1];//grayimage.GetPixel(j+1,i-1,&V[8]); //calcute E[i] from V[i]] tmp=V[0]; NTU=0;//NTU less than 256 int pow2=1; switch(method){ case SUBTRACT_CENTER: for(k=0;k<8;k++) { /*if(V[k+1]<=tmp) E[k]=0; else{ E[k]=1; NTU+=(E[k]*pow2); }*/ if(V[k+1]<=tmp) NTU+=pow2; pow2*=2; } break; case SUBTRACT_NEXT: for(k=0;k<8;k++){ E[k]=V[k]>V[k+1]?1:0; NTU+=E[k]*pow2; pow2*=2; } break; case GAP_CENTER: for(k=0;k<8;k++) { if(abs(V[k+1]-tmp) else{ E[k]=1; NTU+=(E[k]*pow2); } pow2*=2; } break; case GAP_NEXT: for(k=0;k<8;k++) { if(abs(V[k]-V[k+1]) else{ E[k]=1; NTU+=(E[k]*pow2); } pow2*=2; } break; }//end of switch //texturedata[iwidth+j]=NTU; ++fptrHistogram[NTU]; }//end for j }//end for i if(bNormalize){ float total=(float)((height-2)*(widthpixels-2));//neglect pixels at 4 sides float inv=(float)1.0/total; for(i=0;i<256;++i) fptrHistogram[i]*=inv; } #ifdef _DEBUG { float sum=0.0; for(i=0;i<256;i++) { sum+=fptrHistogram[i]; } TRACE("SUM of hist is %f",sum);ASSERT(sum-1.0<0.00001); } #endif }