Exemplo n.º 1
0
bool fixWorkingDirectory() {
   std::string executablePath;
   if (!getExecutablePath(executablePath)) {
      return false;
   }

   std::string executableDir;
   if (!getDirectoryFromPath(executablePath, executableDir)) {
      return false;
   }

   return setWorkingDirectory(executableDir);
}
SteerableFilter2DMultiScaleHermite::SteerableFilter2DMultiScaleHermite
(string _filename_image, int _M,
 float _scale_init, float _scale_end, float _scale_step,
 string name_output, string name_output_orientation)
{
    filename_image = _filename_image;
    M = _M;
    scale_init = _scale_init;
    scale_end  = _scale_end;
    scale_step = _scale_step;

    for(float s = scale_init; s <= scale_end; s+=scale_step)
        stf.push_back( new SteerableFilter2DHermite
                       ( filename_image, M, s));

    alphas = gsl_vector_alloc(stf.size()*M*(M+3)/2);

    directory = getDirectoryFromPath(filename_image);
    image = new Image<float>(filename_image,true);
    result = image->create_blank_image_float(directory + name_output);
    orientation = image->create_blank_image_float(directory + name_output_orientation);
}
void _exportNodeCoeffImage(Slice_P* slice, map<sidType, nodeCoeffType>& nodeCoeffs, const char* outputFilename)
{
  if(slice->getType() == SLICEP_SLICE) {
    IplImage* img = cvCreateImage(cvSize(slice->getWidth(), slice->getHeight()),IPL_DEPTH_32F,1);
    node n;
    float* pfData = 0;
    const map<sidType, supernode* >& _supernodes = slice->getSupernodes();
    for(map<sidType, supernode* >::const_iterator it = _supernodes.begin();
        it != _supernodes.end(); it++) {
      supernode* s = it->second;
      nodeIterator ni = s->getIterator();
      ni.goToBegin();
      while(!ni.isAtEnd()) {
        ni.get(n);
        ni.next();
        pfData = (((float*)(img->imageData + n.y*img->widthStep)+n.x*img->nChannels));
        *pfData = nodeCoeffs[it->first];
      }
    }
    //saveFloatImage(outputFilename, img);
    IplImage* u_img = 0;
    float2ucharImage(img, u_img);

    IplImage* c_img = cvLoadImage(slice->getName().c_str(), CV_LOAD_IMAGE_COLOR);
    uchar* puData;
    uchar* pcData;
    for(int y=0;y<c_img->height;y++) {
      for(int x=0;x<c_img->width;x++) {
        pcData = &((uchar*)(c_img->imageData + c_img->widthStep*y))[x*c_img->nChannels];
        puData = &((uchar*)(u_img->imageData + u_img->widthStep*y))[x*u_img->nChannels];
        *pcData = *puData;
      }
    }

    cvSaveImage(outputFilename, c_img);

    string tmp = getDirectoryFromPath(outputFilename) + getNameFromPathWithoutExtension(outputFilename);
    tmp += "_tmp.png";
    printf("tmp %s\n", tmp.c_str());
    cvSaveImage(tmp.c_str(), u_img);

    cvReleaseImage(&img);
    cvReleaseImage(&u_img);
    cvReleaseImage(&c_img);
  } else {
    sizeSliceType width = slice->getWidth();
    sizeSliceType sliceSize = width*slice->getHeight();
    sizeSliceType cubeSize = sliceSize*slice->getDepth();
    labelType* labelCube = new labelType[cubeSize];
    memset(labelCube,0,cubeSize*sizeof(labelType));

    node n;
    sizeSliceType idx;
    const map<sidType, supernode* >& _supernodes = slice->getSupernodes();
    for(map<sidType, supernode* >::const_iterator it = _supernodes.begin();
        it != _supernodes.end(); it++) {
      supernode* s = it->second;
      nodeIterator ni = s->getIterator();
      ni.goToBegin();
      while(!ni.isAtEnd()) {
        ni.get(n);
        ni.next();
        idx = n.z*sliceSize + n.y*width + n.x;
        labelCube[idx] = nodeCoeffs[it->first];
      }
    }

    exportCube(labelCube, outputFilename, slice->getDepth(), slice->getHeight(), slice->getWidth());
    delete[] labelCube;
  }
}
Exemplo n.º 4
0
Cube_C::Cube_C(string filenameParams) : Cube_P()
{
  v_r = 1.0;
  v_g = 1.0;
  v_b = 1.0;

  string extension = getExtension(filenameParams);
  directory = getDirectoryFromPath(filenameParams);
  if(extension=="tiff" || extension=="TIFF" ||
     extension=="tif" || extension=="TIF"){
    loadFromTIFFImage(filenameParams);
  }
  else{
    printf("Loading cube_C\n");
    std::ifstream file(filenameParams.c_str());
    if(!file.good())
      printf("Cube_C::load_parameters: error loading the file %s\n", filenameParams.c_str());

    string name;
    string attribute;
    while(file.good())
      {
        file >> name;
        file >> attribute;
        if(!strcmp(name.c_str(), "filenameVoxelDataR"))
          filenameVoxelDataR = attribute;
        else if(!strcmp(name.c_str(), "filenameVoxelDataG"))
          filenameVoxelDataG = attribute;
        else if(!strcmp(name.c_str(), "filenameVoxelDataB"))
          filenameVoxelDataB = attribute;
        else if(!strcmp(name.c_str(), "type"))
          type = attribute;
        else
          printf("Cube_C::load_parameters: Attribute %s and value %s not known\n",
                 name.c_str(), attribute.c_str());
      }
    if(type != "color"){
      printf("Cube_C called to load an nfo file that is not a Cube_C... exiting\n");
      exit(0);
    }
    if ( (filenameVoxelDataR == "") || (filenameVoxelDataG == "") ||
         (filenameVoxelDataB == "") )
      {
        printf("Cube_C one of the color channels is not defined... exiting\n");
        exit(0);
      }
    data.resize(0);
    if(fileExists(filenameVoxelDataR))
      data.push_back(new Cube<uchar, ulong>(filenameVoxelDataR));
    else if (fileExists(directory + "/" + filenameVoxelDataR))
      data.push_back(new Cube<uchar, ulong>(directory + "/" + filenameVoxelDataR));
    if(fileExists(filenameVoxelDataG))
      data.push_back(new Cube<uchar, ulong>(filenameVoxelDataG));
    else if (fileExists(directory + "/" + filenameVoxelDataG))
      data.push_back(new Cube<uchar, ulong>(directory + "/" + filenameVoxelDataG));
    if(fileExists(filenameVoxelDataB))
      data.push_back(new Cube<uchar, ulong>(filenameVoxelDataB));
    else if (fileExists(directory + "/" + filenameVoxelDataB))
      data.push_back(new Cube<uchar, ulong>(directory + "/" + filenameVoxelDataB));
  } //not .tiff

  printf("Now all the cubes should be loaded -> %i\n", data.size());

  this->cubeHeight  = data[0]->cubeHeight;
  this->cubeDepth   = data[0]->cubeDepth;
  this->cubeWidth   = data[0]->cubeWidth;
  this->voxelHeight = data[0]->voxelHeight;
  this->voxelDepth  = data[0]->voxelDepth;
  this->voxelWidth  = data[0]->voxelWidth;
  // this->r_max       = data[0]->r_max;
  // this->s_max       = data[0]->s_max;
  // this->t_max       = data[0]->t_max;
  // this->nColToDraw  = data[0]->nColToDraw;
  // this->nRowToDraw  = data[0]->nRowToDraw;
  this->filenameVoxelData = "";
  this->directory          = getDirectoryFromPath(filenameParams);
  this->filenameParameters = getNameFromPath(filenameParams);
  this->type               = "color";


  // glGenTextures(1, &wholeTexture);

  // this->x_offset = data[0]->x_offset;
  // this->y_offset = data[0]->y_offset;
  // this->z_offset = data[0]->z_offset;
}
Exemplo n.º 5
0
Cube_T::Cube_T(string filename){

  printf("Cube_T::loading from %s\n", filename.c_str());
  timeStep = 0;
  d_halo = false;
  d_gt = false;

  cubes.resize(0);
  string extension = getExtension(filename);
  if(extension != "cbt"){
    printf("Cube_T::error::the file %s does not end with cbt\n", filename.c_str());
    exit(0);
  }
  std::ifstream in(filename.c_str());
  if(!in.good())
    {
      printf("Cube_T::error::The file %s can not be opened\n",filename.c_str());
      exit(0);
    }
  string s;
  while(getline(in,s)){
    Cube_P* cb;
    if(fileExists(s))
      cb = CubeFactory::load(s);
    else if(fileExists(getDirectoryFromPath(filename) + "/" + getNameFromPath(s)))
      cb = CubeFactory::load(getDirectoryFromPath(filename) +
                             "/" + getNameFromPath(s));
    else{
      printf("Cube_T::The file %s does not exist, exiting\n", s.c_str());
    }
    if(!cb){
      printf("Cube_T::error::The cubee %s can not be loaded\n",s.c_str());
      exit(0);
    }
    cubes.push_back(cb);
  }
  in.close();
  if(cubes.size()==0){
      printf("Cube_T::error::There is no cube loaded from %s\n",s.c_str());
      exit(0);
  }

  // Get all the information from cubes[0] (we assume all the cubes are the same and
  //   do not check for that (check needed if we want to make the code robust)
  this->voxelWidth  = cubes[0]->voxelWidth;
  this->voxelHeight = cubes[0]->voxelHeight;
  this->voxelDepth  = cubes[0]->voxelDepth;
  this->cubeWidth   = cubes[0]->cubeWidth;
  this->cubeHeight  = cubes[0]->cubeHeight;
  this->cubeDepth   = cubes[0]->cubeDepth;
  this->r_max       = cubes[0]->r_max;
  this->s_max       = cubes[0]->s_max;
  this->t_max       = cubes[0]->t_max;
  this->nColToDraw  = cubes[0]->nColToDraw;
  this->nRowToDraw  = cubes[0]->nRowToDraw;
  this->filenameVoxelData = "";
  this->directory          = getDirectoryFromPath(filename);
  this->filenameParameters = getNameFromPath(filename);
  this->type               = cubes[0]->type;

  string noExt = getNameFromPathWithoutExtension(filename);
  string gtName = getDirectoryFromPath(filename) +  noExt + ".gt";
  printf("The ground truth data should be in %s\n", gtName.c_str());
  if(fileExists(gtName)){
    gtData = loadMatrix(gtName);
  }
  printf("ans it's size is %i\n", (int)gtData.size());

}