wbc特征提取


  /* CvBox2D skin_rect;
  CvMemStorage* storage = cvCreateMemStorage(0);
  CvSeq* contour = 0;
  CvMemStorage* storage2 = cvCreateMemStorage(0);
  CvSeq* contour2 = 0;
  cvFindContours( fore, storage, &contour, sizeof(CvContour),CV_RETR_LIST, CV_CHAIN_APPROX_NONE, cvPoint(0,0)); 
  CvSeq* contour_max=0;
  for( ; contour != 0; contour = contour->h_next )
  {
  int tmparea=abs(cvContourArea(contour,CV_WHOLE_SEQ));/ /轮廓区域的面积
  if (tmparea maxarea)
  {
  maxarea = tmparea;//最大面积连通区域
  contour_max=cvCloneSeq(contour);
  }
  if(tmpcount > count)
  {
  count = tmpcount;//最大轮廓的像素数
  }
  if(tmpbox > axisratio)
  {
  axisratio = tmpbox;//最大长短轴的比值
  }
  }
  if (contour_max!=0)
  {
  CvScalar color = CV_RGB( rand()&255, 0, 0 );
  cvDrawContours(dst, contour_max, color, color, -1, -1, ;
  ConcavityRepair(dst,3);//对fore图像进行修补
  cvFindContours( dst, storage2, &contour2, sizeof(CvContour),CV_RETR_LIST, CV_CHAIN_APPROX_NONE, cvPoint(0,0)); 
  cvDrawContours(src, contour2, color, color, -1, 1, ;/*
  /************************************************* ***********************/
  /*                            图像轮廓的HU矩                            */
  /************************************************* ***********************/
  /*
  CvMoments m;
  CvHuMoments hu;
  //cvMoments(cvGetSubRect(fore,&mat,rct),&m,0);
  cvMoments(contour2,&m,0);
  cvGetHuMoments(&m,&hu);
  huju[0]=(float)fabs(log10(fabs(hu.hu1)));
  huju[1]=(float)fabs(log10(fabs(hu.hu2)));
  huju[2]=(float)fabs(log10(fabs(hu.hu3)));
  huju[3]=(float)fabs(log10(fabs(hu.hu4)));
  huju[4]=(float)fabs(log10(fabs(hu.hu5)));
  huju[5]=(float)fabs(log10(fabs(hu.hu6)));
  huju[6]=(float)fabs(log10(fabs(hu.hu7)));*/
  /************************************************* ***********************/
  /*                            图像重心及半径分布                        */
  /************************************************* ***********************/
  /*  double m00,x,y;
  double r_long=0;
  double r_short=100;
  int num_long,num_short;//长、短轴对应的弧度
  float dist_sum=0;//距离和
  m00=cvGetSpatialMoment(&m,0,0);
  x=cvGetSpatialMoment(&m,1,0)/m00;  //重心坐标
  y=cvGetSpatialMoment(&m,0,1)/m00;
  int contour_max_count=contour2->total;   //this is number point in contour
  CvPoint* pointarray;
  float* dist_center=new float[contour_max_count];
  pointarray=(CvPoint*)malloc(contour_max_count*size of(CvPoint));
  cvCvtSeqToArray(contour2,pointarray,CV_WHOLE_SEQ);
  //查找最长和最短轴
  for (i=0;idist_center[i])
  {
  r_short=dist_center[i];
  num_short=i;
  }
  }
  axisratio=r_long/r_short;//计算长短轴的比值
  axis_angle=(float)abs(num_long-num_short)/contour_ max_count;//计算长短轴对应的角度
  dist_avar=dist_sum/contour_max_count;//均值
  float vari_temp=0;
  for (i=0;iheight;i++)
  {
  for (int j=0;jwidth;j++)
  {
  if (((uchar*)(dst->imageData+i*dst->widthStep))[j]==255 )
  {
  sum_pix++;
  int temp=((uchar*)(src->imageData+i*src->widthStep))[j];
  sum_gray+=temp;
  ffreq[temp]++;
  }
  }
  }
  for (i=0;i 0)
  {
  // 计算图像熵
  shan_maxcontour -= ffreq[i] * log(ffreq[i]) / log(2.0);
  }
  }
  averagegray=(double)sum_gray/sum_pix;//均值
  int grey_s=0;
  for (i=0;iheight;i++)
  {
  for (int j=0;jwidth;j++)
  {
  if (((uchar*)(dst->imageData+i*dst->widthStep))[j]==255 )
  {
  grey_s+=(((uchar*)(src->imageData+i*src->widthStep)) [j]-averagegray)*(((uchar*)(src->imageData+i*src->wid thStep))[j]-averagegray);
  }
  }
  }
  variance_gray=sqrt(grey_s/(sum_pix+eps)); //方差
  }
  else
  {
  return 0;
  }
  CString aa(Path);
  aa+="-1.jpg";//保存图像为新的路径,但不影响原先的bmp图像
  cvSaveImage(aa,src);
  cvReleaseMemStorage(&storage2);
  cvReleaseMemStorage(&storage);*/

你可能感兴趣的:(bc)