Exemplo n.º 1
0
//!  apply k-means classify to volume
void apply_hard_classify(simple_volume<float> & input,
                          minc_byte_volume    &mask,
                          std::vector<double>  mu,
                          minc_byte_volume& cls
                        )
{
  int number_of_classes=mu.size();
  int i,j,k;
  
  if(cls.size()!=mask.size())
    REPORT_ERROR("Mask is wrong size");
  
  //calculate all the classes
  for(j=0;j<input.c_buf_size();j++)
  {
    if(mask.c_buf()[j]) 
    {
      int best_k=0;
      double best_dist=0;
      for(k=0;k<number_of_classes;k++)
      {
        double dist=fabs(input.c_buf()[j]-mu[k]);
        if(dist<best_dist|| best_k==0)
        {
          best_dist=dist;
          best_k=k+1;
        }
      }
      cls.c_buf()[j]=best_k;
    } else {
      cls.c_buf()[j]=0;//unclassified?
    }
  }
}
Exemplo n.º 2
0
 double sum(const minc_byte_volume& v)
 {
   double r=0;
   for(size_t i=0;i<v.c_buf_size();i++)
   {
     double t=v.c_buf()[i];
     r+=t;
   }
   return r;
 }
Exemplo n.º 3
0
 void masked_mul(minc_grid_volume &v2,const minc_grid_volume& v1,const minc_byte_volume &mask)
 {
   if(v1.size()!=v2.size())
     REPORT_ERROR("Volume size mismatch");
   if(v1.size()!=mask.size())
     REPORT_ERROR("Volume size mismatch");
   
   for(int i=0;i<v2.c_buf_size();i++)
     if(mask.c_buf()[i])
       v2.c_buf()[i]*=v1.c_buf()[i];
     else
       v2.c_buf()[i]=IDX<float>(0,0,0);
 }
Exemplo n.º 4
0
 double sum2(const minc_grid_volume& v,const minc_byte_volume& mask)
 {
   if(v.size()!=mask.size())
     REPORT_ERROR("Volume size mismatch");
   
   double r=0;
   for(size_t i=0;i<v.c_buf_size();i++)
     if(mask.c_buf()[i])
   {
     double t=v.c_buf()[i].mod2();
     r+=t;
   }
   return r;
 }