]> Creatis software - STMS.git/commitdiff
Adding CSV file generation
authorGrenier Thomas <thomas.grenier@creatis.insa-lyon.fr>
Wed, 19 Jul 2017 17:05:48 +0000 (19:05 +0200)
committerGrenier Thomas <thomas.grenier@creatis.insa-lyon.fr>
Wed, 19 Jul 2017 17:05:48 +0000 (19:05 +0200)
Lib/PrePostProcessing/itkSTMS_TemporalSetToImageSequence.h
Lib/PrePostProcessing/itkSTMS_TemporalSetToImageSequence.txx
Lib/PrePostProcessing/itkSTMS_XMLFileParser.h
Lib/PrePostProcessing/itkSTMS_XMLFileParser.hxx
Src/STMS_GrayLevelFiltering.cxx

index dd93ea4982317da4c3600aa6cda0acd443f4e26a..7c5e5866f736f3329f6fca009090ae5d93b7c90b 100755 (executable)
@@ -62,6 +62,7 @@
 
 #include <string>
 #include <vector>
+#include <algorithm>
 #include <math.h>
 
 #include "itkImage.h"
@@ -120,6 +121,7 @@ namespace itkSTMS
                                             itkSTMS::ParserOutputType*         desc   );
 
         void GenerateImageSequence();
+        void GenerateCSVFile();
 
     private:
         // Attributes
index 698e3ae4ec33359625560ecfcb4f1c8db75aec16..f5a00e9c08706091ca710fac3b5cf62e6a3c8c0d 100755 (executable)
@@ -127,7 +127,7 @@ itkSTMS_TemporalSetToImageSequence< ImageType, ClassImageType >
             "_Class_X-"+std::to_string((unsigned int)stmsParameters->spScales[0])+
             "_Y-"+std::to_string((unsigned int)stmsParameters->spScales[1])+
             "_Z-"+std::to_string((unsigned int)stmsParameters->spScales[2])+
-            "_R-"+std::to_string(stmsParameters->rScale)+"_"+
+            "_R-"+std::to_string(stmsParameters->rScale)+
             expDescription->outputImageExtension;
 
     ClassWriterPointer classWriter
@@ -135,8 +135,8 @@ itkSTMS_TemporalSetToImageSequence< ImageType, ClassImageType >
     classWriter->SetFileName( classPath );
 
     // Filetered image sequence and class image saving
-    for( unsigned int i=1 ; i<=stmsParameters->numTimePoints - stmsParameters->startTimePoint + 1; ++i ){
-
+    for( unsigned int i=1 ; i<=stmsParameters->numTimePoints - stmsParameters->startTimePoint + 1; ++i )
+    {
         char buffer[6];
         int n;
 
@@ -194,6 +194,36 @@ itkSTMS_TemporalSetToImageSequence< ImageType, ClassImageType >
     }
 }
 
+
+template < class ImageType, class ClassImageType>
+void
+itkSTMS_TemporalSetToImageSequence< ImageType, ClassImageType >
+::GenerateCSVFile()
+{
+    std::string CSVFilename = expDescription->experimentPath+expDescription->outputFolder+
+            expDescription->outputCommonRoot+
+            "_X-"+std::to_string((unsigned int)stmsParameters->spScales[0])+
+            "_Y-"+std::to_string((unsigned int)stmsParameters->spScales[1])+
+            "_Z-"+std::to_string((unsigned int)stmsParameters->spScales[2])+
+            "_R-"+std::to_string(stmsParameters->rScale)+".csv";
+
+    std::cout << "Writing CSV File (classID, nb of pixels, values of time serie), : " << CSVFilename << std::endl;
+    std::ofstream ofs;
+    ofs.open (CSVFilename.c_str(), std::ofstream::out | std::ofstream::trunc);
+
+    for(unsigned int j=0 ; j<rangeSet->size() ; ++j)
+    {
+        ofs << j+1 <<", " << std::count (classSet->begin(), classSet->end(), j+1);
+        for( unsigned int i=1 ; i<=stmsParameters->numTimePoints - stmsParameters->startTimePoint + 1; ++i )
+           ofs << ", " << rangeSet->at(j)[i-1]*stmsParameters->rScale ;
+        ofs << std::endl;
+    }
+
+    ofs.close();
+
+}
+
+
 } // end of namespace itkSTMS
 
 #endif
index 0c3589ef4f5519d870f1cc116d900b667e5fbde3..7bc7b185dabc81e99a69f279b164a0873d80d473 100755 (executable)
@@ -75,6 +75,7 @@ namespace itkSTMS
         std::string  maskImage;
         std::string  outputFolder;
         std::string  outputCommonRoot;
+        std::string  outputCSV;
     };
 
 
index 1bb4c27c17ac901e3b246986ac63715da12168f9..191adb356b4928ad9cb49c53e77319e99227c513 100755 (executable)
@@ -74,6 +74,7 @@ itkSTMS_XMLFileParser::itkSTMS_XMLFileParser()
     xmlParams.maskImage          = "";
     xmlParams.outputFolder       = "";
     xmlParams.outputCommonRoot   = "";
+    xmlParams.outputCSV          = "";
 }
 
 
@@ -108,7 +109,7 @@ void itkSTMS_XMLFileParser::Update()
     xmlParams.outputImageExtension = DomObject->GetAttribute( "outputImageExtension" );
     if ( xmlParams.outputImageExtension == "" )
     {
-        std::cout << std::endl << std::endl <<  "outputImageExtension not found" << std::endl << std::endl;
+        std::cout << std::endl << std::endl <<  "outputImageExtension not set" << std::endl << std::endl;
         std::exit( EXIT_FAILURE );
     }
 
@@ -150,6 +151,13 @@ void itkSTMS_XMLFileParser::Update()
         std::cout << std::endl << std::endl <<  "outputCommonRoot not found" << std::endl << std::endl;
         std::exit( EXIT_FAILURE );
     }
+
+    xmlParams.outputCSV = listOutput->GetAttribute( "outputCSV" );
+    if ( xmlParams.outputCSV == "" )
+    {
+        std::cout << std::endl << std::endl <<  "outputCSV not set: no CSV file will be created" << std::endl << std::endl;
+    }
+
 }
 } // end of namespace itkSTMS
 #endif // itkSTMS_XMLFileParser_HXX
index d2bcb3d4addd6ba2814d0576eddb54425b61aa6e..7f2cd022ba348c9af564772e8d7cd15ca82303da 100755 (executable)
@@ -60,7 +60,7 @@
 #include <iomanip>
 #include <ctime>
 
-#define STMS_NUMBERING_FORM_ONE "01"
+#define STMS_NUMBERING_FORM_ONE "001"
 
 #include "itkImage.h"
 #include "itkSTMS_ArgumentsAnalysis.h"
@@ -161,6 +161,8 @@ int main(int argc, char **argv){
                                                                                                        preProcess->GetExperimentDescription());
 
             postProcess->GenerateImageSequence();
+            if(preProcess->GetExperimentDescription()->outputCSV == "true"  )
+                postProcess->GenerateCSVFile(  );
 
             dtime = gettime_hp()-dtime;
             std::cout<<std::endl<< std::setw(30) << std::left << "Image sequence saving: " << dtime/1000 << " s" <<std::endl;
@@ -224,6 +226,8 @@ int main(int argc, char **argv){
                                                                                                       preProcess->GetExperimentDescription());
 
             postProcess->GenerateImageSequence();
+            if(preProcess->GetExperimentDescription()->outputCSV == "true"  )
+                postProcess->GenerateCSVFile();
 
             dtime = gettime_hp()-dtime;
             std::cout<<std::endl<< std::setw(30) << std::left << "Image sequence saving: " << dtime/1000 << " s" <<std::endl;