Пример #1
0
void
IoParams::parse(int ac,
                char* av[])
{
  namespace po = boost::program_options;
  typedef std::vector<std::string> StringVectorType;
  StringVectorType vItems;
  po::options_description desc("Allowed Options");

  desc.add_options()
  ("help", " produce help message")
  ("out", po::value(&strOut), " output transform file (.tm3d)")
  ("template", po::value(&strTemplate), " template volume (only for geometry) - if a gcam is present, it needs to be specified")
  ("subject", po::value(&strSubject), " subject volume (only for geometry)" )
  ("in", po::value(&vItems)->multitoken(), " input transforms - affine|volume|morph|mesh|gcam + fname")
  ("dbg", po::value(&vDbgCoords)->multitoken(), " enter debug coordinates ")
  ;

  po::variables_map vm;
  po::store( po::parse_command_line(ac,av,desc), vm);
  po::notify(vm);

  if ( vm.count("help") )
  {
    std::cout << desc << std::endl;
    exit(0);
  }

  if ( strOut.empty() )
  {
    std::cerr << " Empty output file name\n";
    exit(1);
  }

  // parse input terms
  if ( vItems.empty() )
  {
    std::cout << " nothing to do - no transforms specified\n";
    exit(0);
  }

  if (  vItems.size() % 2 )
  {
    std::cerr << " odd number of transform tokens\n";
    exit(1);
  }

  for ( StringVectorType::iterator it = vItems.begin();
        it != vItems.end(); )
  {
    MorphItem item;
    item.type = *it++;
    item.file = *it++;
    this->items.push_back(item);
  } // next it
}
void buildImageIntensityModelOnROI(const char* referenceFilename, const char* maskFilename, const char* dir, const char* outputImageFilename) {


	typedef itk::PCAModelBuilder<RepresenterType> ModelBuilderType;
	typedef itk::StatisticalModel<RepresenterType> StatisticalModelType;
    typedef std::vector<std::string> StringVectorType;
    typedef itk::DataManager<RepresenterType> DataManagerType;

    RepresenterType::Pointer representer = RepresenterType::New();

	typedef itk::ImageFileReader< ImageType > MaskReaderType;
	MaskReaderType::Pointer maskReader = MaskReaderType::New();
	maskReader->SetFileName( maskFilename );
    maskReader->Update();

	representer->SetReference( ReadImageFromFile(referenceFilename), maskReader->GetOutput() );

    StringVectorType filenames;
    getdir(dir, filenames, ".vtk");

    DataManagerType::Pointer dataManager = DataManagerType::New();
	dataManager->SetRepresenter(representer);

    for (StringVectorType::const_iterator it = filenames.begin(); it != filenames.end(); it++) {
        std::string fullpath = (std::string(dir) + "/") + *it;

        dataManager->AddDataset( ReadImageFromFile(fullpath), fullpath.c_str());
    }

	ModelBuilderType::Pointer pcaModelBuilder = ModelBuilderType::New();
    StatisticalModelType::Pointer model = pcaModelBuilder->BuildNewModel(dataManager->GetSampleDataStructure(), 0);

    std::cout<<"dimensionality of the data: "<<model->GetDomain().GetNumberOfPoints()<<", dimension of the images: "<<(*dataManager->GetSampleDataStructure().begin())->GetSample()->GetLargestPossibleRegion().GetNumberOfPixels()<<std::endl;

    std::cout<<"writing the mean sample to a png file..."<<std::endl;
    
	typedef itk::ImageFileWriter< ImageType > ImageWriterType;
	ImageWriterType::Pointer writer = ImageWriterType::New();
	writer->SetFileName( outputImageFilename );
	writer->SetInput(model->DrawSample());
    writer->Update();

}