Exemplo n.º 1
0
int mergecb(float *B,float **cb,unsigned char *P,int npt,int N,float thresh,int dim)
{
  int i,j,newN,*count,l,ei,debug=0;
  float **dist;

  if (N==1) return N;

  count=(int *)malloc(sizeof(int)*N);
  for (l=0;l<npt;l++) count[P[l]]++;

  dist=(float **)fmatrix(N,N);
  ei = N-1;
  for (i=0;i<ei;i++)
  {
    for (j=i+1;j<N;j++)
    {
      dist[i][j] = distance2(cb[i],cb[j],dim);
      dist[j][i] = dist[i][j];
    }
  }

  if (debug) printf("thresh %f ",thresh);
  newN=mergecb1(dist,B,cb,N,thresh,dim,count);

  free_fmatrix(dist,N);
  free(count);
  return newN;
}
Exemplo n.º 2
0
int mergecb(float *B,float **cb,unsigned char *P,int npt,int N,float thresh,int dim)
{
  int i,j,newN,*count,l,ei,*count2;
  float **dist,**dist2,**cb2;

  if (N==1) return 1;

  count=(int *)calloc(N,sizeof(int));
  for (l=0;l<npt;l++) count[P[l]]++;

  dist=(float **)fmatrix(N,N);
  ei = N-1;
  for (i=0;i<ei;i++)
  {
    for (j=i+1;j<N;j++)
    {
      dist[i][j] = distance2(cb[i],cb[j],dim);
      dist[j][i] = dist[i][j];
    }
  }

  if (thresh<0)
  {
    cb2 = (float **)fmatrix(N,dim);
    for (i=0;i<N;i++) 
      for (j=0;j<dim;j++) cb2[i][j]=cb[i][j];
    count2=(int *)calloc(N,sizeof(int));
    for (i=0;i<N;i++) count2[i]=count[i];
    dist2=(float **)fmatrix(N,N);
    for (i=0;i<N;i++)
      for (j=0;j<N;j++) dist2[i][j]=dist[i][j];
    if (dim==3) thresh=400;
    else if (dim==1) thresh=800;
    mergecb1(dist2,B,cb2,P,npt,N,&thresh,dim,count2,1);
    free_fmatrix(cb2,N);
    free(count2);
    free_fmatrix(dist2,N);
  }
  printf("thresh %f ",thresh);
  newN=mergecb1(dist,B,cb,P,npt,N,&thresh,dim,count,0);

  free_fmatrix(dist,N);
  free(count);
  return newN;
}