Ejemplo n.º 1
0
int main(int argc, char**argv)
{

  // parse command line ----------------------------------------------
  po::options_description general_opt ( "Allowed options are: " );
  general_opt.add_options()
    ( "help,h", "display this message." )
    ( "input,i", po::value<std::string>(), "Input vol file." )
    ( "output,o", po::value<string>(),"Output filename." );
  bool parseOK=true;
  po::variables_map vm;
  try{
    po::store(po::parse_command_line(argc, argv, general_opt), vm);  
  }catch(const std::exception& ex){
    parseOK=false;
    trace.info()<< "Error checking program options: "<< ex.what()<< endl;
  }
  po::notify ( vm );
  if ( !parseOK || vm.count ( "help" ) ||argc<=1 )
    {
      trace.info() << "Add a border of one voxel with value 0 around a vol file."<<std::endl
                   << std::endl << "Basic usage: "<<std::endl
                   << "\tvolAddBorder --input <volFileName> --o <volOutputFileName> "<<std::endl
                   << general_opt << "\n";
      return 0;
    }

  //Parse options
  if ( ! ( vm.count ( "input" ) ) ) missingParam ( "--input" );
  std::string filename = vm["input"].as<std::string>();
  if ( ! ( vm.count ( "output" ) ) ) missingParam ( "--output" );
  std::string outputFileName = vm["output"].as<std::string>();

  typedef ImageContainerBySTLVector<Z3i::Domain, unsigned char>  MyImageC;

  MyImageC  imageC = VolReader< MyImageC >::importVol ( filename );
  MyImageC  outputImage( Z3i::Domain( imageC.domain().lowerBound() - Vector().diagonal(1),
                                      imageC.domain().upperBound() + Vector().diagonal(1)));
  
  //Fast Copy
  for(MyImageC::Domain::ConstIterator it = imageC.domain().begin(),
        itend = imageC.domain().end(); it != itend; ++it)
    outputImage.setValue( *it , imageC(*it));
  
  typedef GrayscaleColorMap<unsigned char> Gray;
  bool res =  VolWriter< MyImageC , Gray>::exportVol(outputFileName, outputImage, 0, 255);
  if (res) return 0; else return 1;
}
Ejemplo n.º 2
0
int main(int argc, char**argv)
{

  // parse command line ----------------------------------------------
  po::options_description general_opt ( "Allowed options are: " );
  general_opt.add_options()
    ( "help,h", "display this message." )
    ( "input,i", po::value<std::string>(), "Input vol file." )
    ( "output,o", po::value<string>(),"Output filename." );

  po::variables_map vm;
  po::store ( po::parse_command_line ( argc, argv, general_opt ), vm );
  po::notify ( vm );
  if ( vm.count ( "help" ) ||argc<=1 )
    {
      trace.info() << "Brutally sub sample a vol file (division by 2 in each direction)."<<std::endl
                   << std::endl << "Basic usage: "<<std::endl
                   << "\tvolSubSample --input <volFileName> --o <volOutputFileName> "<<std::endl
                   << general_opt << "\n";
      return 0;
    }

  //Parse options
  if ( ! ( vm.count ( "input" ) ) ) missingParam ( "--input" );
  std::string filename = vm["input"].as<std::string>();
  if ( ! ( vm.count ( "output" ) ) ) missingParam ( "--output" );
  std::string outputFileName = vm["output"].as<std::string>();

  trace.beginBlock("Loading file");
  typedef ImageContainerBySTLVector<Z3i::Domain, unsigned char>  MyImageC;

  MyImageC  imageC = VolReader< MyImageC >::importVol ( filename );
  MyImageC  outputImage( Z3i::Domain( imageC.domain().lowerBound() - Vector().diagonal(1),
                                      (imageC.domain().upperBound()-imageC.domain().lowerBound())/Vector().diagonal(2) + Vector().diagonal(1)));

  trace.endBlock();
  unsigned int cpt=0;
  unsigned int maxS = imageC.domain().size();
  Point subvector = Vector().diagonal(2);

  trace.beginBlock("Down-scaling the volume...");
  //Fast Copy
  for(MyImageC::Domain::ConstIterator it = imageC.domain().begin(),
        itend = imageC.domain().end(); it != itend; ++it)
    {
      trace.info() << cpt; 
      trace.progressBar( cpt, maxS);
      cpt++;
      outputImage.setValue( *it/subvector , imageC(*it));
    }
  trace.endBlock();
  
  
  typedef GrayscaleColorMap<unsigned char> Gray;
  bool res =  VolWriter< MyImageC , Gray>::exportVol(outputFileName, outputImage, 0, 255);
  if (res) return 0; else return 1;
}
Ejemplo n.º 3
0
int main(int argc, char**argv)
{

  // parse command line ----------------------------------------------
  po::options_description general_opt ( "Allowed options are: " );
  general_opt.add_options()
    ( "help,h", "display this message." )
    ( "input,i", po::value<std::string>(), "Input vol file." )
    ( "output,o", po::value<string>(),"Output filename." )
    ("function,f",   po::value<string>()->default_value("mean"), "Function used to the down-sampling: {none,max, min, mean}" );
  

  po::variables_map vm;
  po::store ( po::parse_command_line ( argc, argv, general_opt ), vm );
  po::notify ( vm );
  if ( vm.count ( "help" ) ||argc<=1 )
    {
      trace.info() << "Brutally sub sample a vol file (division by 2 in each direction)."<<std::endl
                   << std::endl << "Basic usage: "<<std::endl
                   << "\tvolSubSample --input <volFileName> --o <volOutputFileName> "<<std::endl
                   << general_opt << "\n";
      return 0;
    }

  //Parse options
  if ( ! ( vm.count ( "input" ) ) ) missingParam ( "--input" );
  std::string filename = vm["input"].as<std::string>();
  std::string function = vm["function"].as<std::string>();
  if ( ! ( vm.count ( "output" ) ) ) missingParam ( "--output" );
  std::string outputFileName = vm["output"].as<std::string>();
  
  
  trace.beginBlock("Loading file");
  typedef ImageContainerBySTLVector<Z3i::Domain, unsigned char>  MyImageC;

  MyImageC  imageC = VolReader< MyImageC >::importVol ( filename );
  MyImageC  outputImage( Z3i::Domain( imageC.domain().lowerBound(),
                                      (imageC.domain().upperBound()-imageC.domain().lowerBound())/Vector().diagonal(2)));

  trace.endBlock();
  Point subvector = Vector().diagonal(2);
  Point p;
  unsigned char val;
  trace.beginBlock("Down-scaling the volume...");
  trace.info()<<"Function= "<<function<<std::endl;
  trace.info() << outputImage.domain() << std::endl;
  //Fast Copy
  if (function == "none")
    for(MyImageC::Domain::ConstIterator it = outputImage.domain().begin(),
	  itend = outputImage.domain().end(); it != itend; ++it)
      {
	p = (*it) * 2;
	outputImage.setValue( *it , imageC( p ));
      }
  else
    if (function == "max")
      for(MyImageC::Domain::ConstIterator it = outputImage.domain().begin(),
	    itend = outputImage.domain().end(); it != itend; ++it)
	{
	  val = maxVal<unsigned char, MyImageC, Point>(imageC, *it, imageC.domain());
	  outputImage.setValue( *it , val );
	}
    else
      if (function == "min")
	for(MyImageC::Domain::ConstIterator it = outputImage.domain().begin(),
	      itend = outputImage.domain().end(); it != itend; ++it)
	  {
	    val = minVal<unsigned char, MyImageC, Point>(imageC, *it, imageC.domain());
	    outputImage.setValue( *it , val);
	  }  
      else
	
      if (function == "mean")
	for(MyImageC::Domain::ConstIterator it = outputImage.domain().begin(),
	      itend = outputImage.domain().end(); it != itend; ++it)
	  {
	    val = meanVal<unsigned char, MyImageC, Point>(imageC, *it, imageC.domain());
	    outputImage.setValue( *it , val );
	  }
      else
	trace.error() << "Bad function !"<<std::endl;


  trace.endBlock();
  
  trace.beginBlock("Exporting...");
  bool res =  VolWriter< MyImageC>::exportVol(outputFileName, outputImage);
  trace.endBlock();
  if (res) return 0; else return 1;
}
int main(int argc, char**argv)
{

  // parse command line ----------------------------------------------
  po::options_description general_opt ( "Allowed options are: " );
  general_opt.add_options()
    ( "help,h", "display this message." )
    ( "input,i", po::value<std::string>(), "Input vol file." )
    ("thresholdMin,m",  po::value<int>()->default_value(0), "threshold min (excluded) to define binary shape" )
    ("thresholdMax,M",  po::value<int>()->default_value(255), "threshold max (included) to define binary shape" );
  bool parseOK=true;
  po::variables_map vm;


  
  try{
    po::store(po::parse_command_line(argc, argv, general_opt), vm);  
  }catch(const std::exception& ex){
    parseOK=false;
    trace.info()<< "Error checking program options: "<< ex.what()<< endl;
  }
  po::notify ( vm );
  if (!parseOK || vm.count ( "help" ) ||argc<=1 )
    {
      trace.info() << "Compute the Euleur Characteristic of  a vol to a 8-bit raw file. The vol file is first binarized using interval [m,M[ thresholds and the Eucler characteristic is given from the cubical complex"<<std::endl
                   << std::endl << "Basic usage: "<<std::endl
                   << "\eulerCharacteristic --input <volFileName> -m <minlevel> -M <maxlevel> "<<std::endl
                   << general_opt << "\n";
      return 0;
    }

  //Parse options
  if ( ! ( vm.count ( "input" ) ) ) missingParam ( "--input" );
  std::string filename = vm["input"].as<std::string>();
  int thresholdMin = vm["thresholdMin"].as<int>();
  int thresholdMax = vm["thresholdMax"].as<int>();
 
  //Importing the Vol
  trace.beginBlock("Loading the vol file");
  typedef ImageContainerBySTLVector<Z3i::Domain, unsigned char>  MyImageC;
  MyImageC  imageC = VolReader< MyImageC >::importVol ( filename );
  trace.info()<<imageC<<std::endl;
  trace.endBlock();  

  //Constructing the cubical complex
  trace.beginBlock("Construting the cubical complex");
  KSpace::CellSet myCellSet;
  KSpace  ks;
  bool space_ok = ks.init( imageC.domain().lowerBound(), imageC.domain().upperBound(), true );
  if (!space_ok)
    {
      trace.error() << "Error in the Khamisky space construction."<<std::endl;
      return 2;
    }
  functors::IntervalForegroundPredicate<MyImageC> interval(imageC, thresholdMin,thresholdMax);  
  for(MyImageC::Domain::ConstIterator it =imageC.domain().begin(), itend= imageC.domain().end();
      it != itend; ++it)
    {
      if (interval( *it ))
        {
          Domain dom( 2*(*it), 2*(*it) + Point::diagonal(2));
          for(Domain::ConstIterator itdom = dom.begin(), itdomend = dom.end(); itdom != itdomend; ++itdom)
            myCellSet.insert( ks.uCell( *itdom) );
        }
    }
  trace.info() << "Got "<< myCellSet.size()<< " cells"<<std::endl;
  trace.endBlock();

  trace.beginBlock("Computing the characteristics");
  std::vector<int> cells(4,0);
  
  for(KSpace::CellSet::const_iterator it = myCellSet.begin(), itend = myCellSet.end(); it !=itend; ++it)
    cells[ ks.uDim(*it) ] ++; 
  
  trace.info() << "Got "<< cells[0]<< " pointels "<<cells[1]<<" linels  "<< cells[2]<<" surfels and "<<cells[3]<<"  bells"<<std::endl;
  trace.endBlock();

  trace.info() << "Volumetric Euler Characteristic = "<<cells[0] - cells[1] + cells[2] - cells[3]<<std::endl;

  return 0;
}