2 #include <tclap/CmdLine.h> 4 #include <itkTimeProbe.h> 5 #include <itkImageConstIterator.h> 6 #include <itkImageRegionConstIterator.h> 7 #include <itkImageRegionConstIteratorWithIndex.h> 10 int main(
int argc,
char **argv)
12 TCLAP::CmdLine cmd(
"Given a mask creates and a list of volume data, populates a csv file where each colmuns represents one of the volume data and each line a given voxel. The voxel for which the mask is 0 are not set into the csv file. " 13 "\\ Note: the voxel location are lost into the csv file. INRIA / IRISA - VisAGeS/Empenn Team",
' ',ANIMA_VERSION);
14 TCLAP::ValueArg<std::string> dataListArg(
"i",
"database",
"Image List",
true,
"",
"image list",cmd);
15 TCLAP::ValueArg<std::string> maskArg(
"m",
"maskname",
"Mask",
true,
"",
"mask",cmd);
16 TCLAP::ValueArg<std::string> resNameArg(
"o",
"outputname",
"CSV file name",
true,
"",
"file name for the output csv file",cmd);
21 catch (TCLAP::ArgException& e)
23 std::cerr <<
"Error: " << e.error() <<
"for argument " << e.argId() << std::endl;
28 typedef itk::Image <unsigned char, 3> MaskType;
29 MaskType::Pointer maskImage = anima::readImage <MaskType> (maskArg.getValue());
30 typedef itk::ImageRegionConstIteratorWithIndex<MaskType> MaskIterator;
32 MaskIterator iterMaskImage(maskImage,maskImage->GetRequestedRegion());
34 typedef itk::Image <double, 3> ImageType;
35 typedef itk::ImageRegionConstIterator<ImageType> ImageIterator;
38 std::ifstream fileIn(dataListArg.getValue());
40 std::vector< std::vector<double> > allSamples;
44 std::vector<std::string> labels;
45 std::vector<unsigned int> xSample;
46 std::vector<unsigned int> ySample;
47 std::vector<unsigned int> zSample;
49 while (std::getline(fileIn, oneLine))
51 std::size_t pos = oneLine.find(
":");
52 std::string imgeName = oneLine.substr (pos+1);
53 labels.push_back(oneLine.substr(0,pos));
55 itk::SmartPointer<ImageType> ltReader;
58 ltReader=anima::readImage<ImageType>(imgeName);
60 catch(std::exception& e)
62 std::cout<<
"file for field "<<labels.back()<<
" is missing"<<std::endl;
66 ImageIterator iterCurrentImage( ltReader, ltReader->GetRequestedRegion() );
68 iterMaskImage.GoToBegin();
69 iterCurrentImage.GoToBegin();
70 std::vector<double> oneSample;
71 while(!iterCurrentImage.IsAtEnd())
73 if(iterMaskImage.Value()!=0)
74 { oneSample.push_back(iterCurrentImage.Value());
78 const unsigned int x=iterCurrentImage.GetIndex()[0];
79 const unsigned int y=iterCurrentImage.GetIndex()[1];
80 const unsigned int z=iterCurrentImage.GetIndex()[2];
90 allSamples.push_back(oneSample);
94 if (resNameArg.getValue() !=
"")
97 std::ofstream file(resNameArg.getValue());
99 for(
unsigned int indexI=0;indexI<allSamples.size();++indexI)
101 file<<labels[indexI];
102 if(indexI<(allSamples.size()-1))
105 file<<
",indexX,indexY,indexZ";
108 for(
unsigned int indexJ=0;indexJ<allSamples[0].size();++indexJ)
110 for(
unsigned int indexI=0;indexI<allSamples.size();++indexI)
113 file<<allSamples[indexI][indexJ];
114 if(indexI<(allSamples.size()-1))
117 file<<
","<<xSample[indexJ]<<
","<<ySample[indexJ]<<
","<<zSample[indexJ];
int main(int argc, char **argv)