/* 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<14)//大量数据得到-----------同时整个区域的样本数量为0 样本可以分到杂质
{
cvSeqRemove(contour,0);
continue;
}
num_connect++;
double tmpcount=cvArcLength(contour,CV_WHOLE_SEQ,-1);
skin_rect = cvMinAreaRect2(contour, 0);//最小外界矩形
float tmpbox=(float)skin_rect.size.height/skin_rect.size.width;//长宽比
//h_axis=skin_rect.size.height;
//w_axis=skin_rect.size.width;
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, 8);
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, 8);/*
/************************************************************************/
/* 图像轮廓的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*sizeof(CvPoint));
cvCvtSeqToArray(contour2,pointarray,CV_WHOLE_SEQ);
//查找最长和最短轴
for (i=0;i<contour_max_count;i++)
{
dist_center[i]=sqrt(((float)pointarray[i].x-x)*((float)pointarray[i].x-x)+((float)pointarray[i].y-y)*((float)pointarray[i].y-y));
//fprintf(stream,"%f ",dist_center[i]);
dist_sum+=dist_center[i];
if (r_long<dist_center[i])
{
r_long=dist_center[i];
num_long=i;
}
if (r_short>dist_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;i<contour_max_count;i++)
{
vari_temp+=(dist_center[i]-dist_vari)*(dist_center[i]-dist_vari);
}
dist_vari=sqrt(vari_temp/contour_max_count);
free(pointarray);
delete[] dist_center;*/
/************************************************************************/
/* 细胞核灰度均值、方差、图像熵 */
/*注意:找轮廓的时候已经删除了一部分小面积的区域,这部分是否参与计算 */
/************************************************************************/
/* int sum_gray=0;//灰度和
int sum_pix=0;//像素和
float ffreq[256]={0};
for (i=0;i<dst->height;i++)
{
for (int j=0;j<dst->width;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<256;i++)
{
ffreq[i]/=(float)sum_pix;
}
// 计算图像熵
for (i = 0; i < 256; i ++)
{
// 判断概率是否大于0
if (ffreq[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;i<dst->height;i++)
{
for (int j=0;j<dst->width;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->widthStep))[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);*/