]> Creatis software - STMS.git/commitdiff
Merge branch 'master' of ssh://git.creatis.insa-lyon.fr/STMS
authorGrenier Thomas <thomas.grenier@creatis.insa-lyon.fr>
Sun, 10 Dec 2017 12:58:00 +0000 (13:58 +0100)
committerGrenier Thomas <thomas.grenier@creatis.insa-lyon.fr>
Sun, 10 Dec 2017 12:58:00 +0000 (13:58 +0100)
# Conflicts:
# Src/CMakeLists.txt

Lib/PrePostProcessing/CMakeLists.txt
Lib/PrePostProcessing/itkSTMS_ImageSequenceToTemporalSet.txx
Lib/PrePostProcessing/itkSTMS_TemporalSetToImageSequence.h
Lib/PrePostProcessing/itkSTMS_TemporalSetToImageSequence.txx
Lib/PrePostProcessing/itkSTMS_XMLFileParser.h
Lib/PrePostProcessing/itkSTMS_XMLFileParser.hxx
Lib/SpatioTemporalMeanShift/CMakeLists.txt
Lib/SpatioTemporalMeanShift/itkSTMS_BlurringSTMS.txx
Src/CMakeLists.txt
Src/STMS_GrayLevelFiltering.cxx

index cc8c3db3939be10e4d8107028e854a84aa3c3198..a41de85a94fd5d0f4737a6bed8b598cc3457e011 100755 (executable)
@@ -80,6 +80,8 @@ IF ( BUILD_${LIBRARY_NAME} )
    TARGET_LINK_LIBRARIES(${LIBRARY_NAME} ${${LIBRARY_NAME}_LINK_LIBRARIES} )
    SET_TARGET_PROPERTIES(${LIBRARY_NAME} PROPERTIES LINKER_LANGUAGE C)
 
+   install(TARGETS ${LIBRARY_NAME} DESTINATION lib)
+   install(FILES  ${LIBRARY_NAME_HEADERS} DESTINATION include)
   #
   #----------------------------------------------------------------------------
 
index ed74c3c32b1b8155ead8ff4b429afc59c5ffb73d..1f55193634d6a06e846263ed9ce405023155fc9a 100755 (executable)
@@ -120,20 +120,18 @@ itkSTMS_ImageSequenceToTemporalSet< ImageType, MaskImageType >
         idx = 0;
 
         char buffer[6];
-        int n = 0;
+        // int n = 0; // used to debug sprintf : n = sprintf( ...
 
-        if( sizeof(STMS_NUMBERING_FORM_ONE) == 6 ) n=sprintf (buffer, "%05d", i + stmsParameters->startTimePoint - 1);
-        if( sizeof(STMS_NUMBERING_FORM_ONE) == 5 ) n=sprintf (buffer, "%04d", i + stmsParameters->startTimePoint - 1);
-        if( sizeof(STMS_NUMBERING_FORM_ONE) == 4 ) n=sprintf (buffer, "%03d", i + stmsParameters->startTimePoint - 1);
-        if( sizeof(STMS_NUMBERING_FORM_ONE) == 3 ) n=sprintf (buffer, "%02d", i + stmsParameters->startTimePoint - 1);
-        if( sizeof(STMS_NUMBERING_FORM_ONE) == 2 ) n=sprintf (buffer, "%01d", i + stmsParameters->startTimePoint - 1);
+        if( sizeof(STMS_NUMBERING_FORM_ONE) == 6 ) sprintf (buffer, "%05d", i + stmsParameters->startTimePoint - 1);
+        if( sizeof(STMS_NUMBERING_FORM_ONE) == 5 ) sprintf (buffer, "%04d", i + stmsParameters->startTimePoint - 1);
+        if( sizeof(STMS_NUMBERING_FORM_ONE) == 4 ) sprintf (buffer, "%03d", i + stmsParameters->startTimePoint - 1);
+        if( sizeof(STMS_NUMBERING_FORM_ONE) == 3 ) sprintf (buffer, "%02d", i + stmsParameters->startTimePoint - 1);
+        if( sizeof(STMS_NUMBERING_FORM_ONE) == 2 ) sprintf (buffer, "%01d", i + stmsParameters->startTimePoint - 1);
 
         std::string imagePath = expDescription->experimentPath+expDescription->inputFolder+expDescription->inputCommonRoot+buffer+expDescription->imageExtension;
 
-        ImagePointer image
-                = ImageType::New();
-        ReaderPointer reader
-                = itk::ImageFileReader< ImageType >::New();
+        ImagePointer image       = ImageType::New();
+        ReaderPointer reader     = itk::ImageFileReader< ImageType >::New();
 
         reader->SetFileName( imagePath );
         reader->Update();
index 996d65b8ce5e1e2546f573ac6d00c563fc5cd73d..1b53b3e57910ff07c5dfac7db346483cb867142b 100755 (executable)
 
 namespace itkSTMS
 {
-    template < class ImageType, class ClassImageType >
+    template < class ImageType, class ClassImageType, class OutputImageType=ImageType>
     class itkSTMS_TemporalSetToImageSequence
     {
     public:
         // Reader and writer typedefs
         typedef itk::ImageFileReader< ImageType >       ReaderType;
         typedef typename ReaderType::Pointer            ReaderPointer;
-        typedef itk::ImageFileWriter< ImageType >       WriterType;
+        typedef itk::ImageFileWriter< OutputImageType > WriterType;
         typedef typename WriterType::Pointer            WriterPointer;
         typedef itk::ImageFileWriter< ClassImageType >  ClassWriterType;
         typedef typename ClassWriterType::Pointer       ClassWriterPointer;
index 2d5131821dafa43f4ff2b394f9b137b0ed8f0e49..115918763c8368d28107ba013fb5d0bac3d73e15 100755 (executable)
@@ -67,8 +67,8 @@
 namespace itkSTMS
 {
 
-template < class ImageType, class ClassImageType >
-itkSTMS_TemporalSetToImageSequence < ImageType, ClassImageType >
+template < class ImageType, class ClassImageType, class OutputImageType>
+itkSTMS_TemporalSetToImageSequence < ImageType, ClassImageType, OutputImageType >
 ::itkSTMS_TemporalSetToImageSequence( IndexSampleSetType* cl, SpatialSampleSetType* sp, RangeSampleSetType* ra,
                                       itkSTMS::ParamsAnalysisOutputType* params, itkSTMS::ParserOutputType* desc )
 {
@@ -81,9 +81,9 @@ itkSTMS_TemporalSetToImageSequence < ImageType, ClassImageType >
 }
 
 
-template < class ImageType, class ClassImageType >
+template < class ImageType, class ClassImageType, class OutputImageType >
 void
-itkSTMS_TemporalSetToImageSequence< ImageType, ClassImageType >
+itkSTMS_TemporalSetToImageSequence< ImageType, ClassImageType, OutputImageType >
 ::GenerateImageSequence()
 {
     bool first = true;
@@ -114,9 +114,7 @@ itkSTMS_TemporalSetToImageSequence< ImageType, ClassImageType >
 
     std::string outputPath, classPath;
 
-    ClassImagePointer classImage
-            = ClassImageType::New();
-
+    ClassImagePointer classImage          = ClassImageType::New();
     classImage->SetRegions( classRegion );
     classImage->Allocate();
     classImage->FillBuffer( 15.0 );
@@ -128,23 +126,22 @@ itkSTMS_TemporalSetToImageSequence< ImageType, ClassImageType >
             "_Y-"+std::to_string((unsigned int)stmsParameters->spScales[1])+
             "_Z-"+std::to_string((unsigned int)stmsParameters->spScales[2])+
             "_R-"+std::to_string(stmsParameters->rScale)+
-            expDescription->outputImageExtension;
+            expDescription->outputClassExtension;
 
-    ClassWriterPointer classWriter
-            = ClassWriterType::New();
+    ClassWriterPointer classWriter         = ClassWriterType::New();
     classWriter->SetFileName( classPath );
 
     // Filetered image sequence and class image saving
     for( unsigned int i=1 ; i<=stmsParameters->numTimePoints - stmsParameters->startTimePoint + 1; ++i )
     {
         char buffer[6];
-        int n;
+         // int n;
 
-        if( sizeof(STMS_NUMBERING_FORM_ONE) == 6 ) n=sprintf (buffer, "%05d", i + stmsParameters->startTimePoint - 1);
-        if( sizeof(STMS_NUMBERING_FORM_ONE) == 5 ) n=sprintf (buffer, "%04d", i + stmsParameters->startTimePoint - 1);
-        if( sizeof(STMS_NUMBERING_FORM_ONE) == 4 ) n=sprintf (buffer, "%03d", i + stmsParameters->startTimePoint - 1);
-        if( sizeof(STMS_NUMBERING_FORM_ONE) == 3 ) n=sprintf (buffer, "%02d", i + stmsParameters->startTimePoint - 1);
-        if( sizeof(STMS_NUMBERING_FORM_ONE) == 2 ) n=sprintf (buffer, "%01d", i + stmsParameters->startTimePoint - 1);
+        if( sizeof(STMS_NUMBERING_FORM_ONE) == 6 ) sprintf( buffer, "%05d", i + stmsParameters->startTimePoint - 1);
+        if( sizeof(STMS_NUMBERING_FORM_ONE) == 5 ) sprintf( buffer, "%04d", i + stmsParameters->startTimePoint - 1);
+        if( sizeof(STMS_NUMBERING_FORM_ONE) == 4 ) sprintf( buffer, "%03d", i + stmsParameters->startTimePoint - 1);
+        if( sizeof(STMS_NUMBERING_FORM_ONE) == 3 ) sprintf( buffer, "%02d", i + stmsParameters->startTimePoint - 1);
+        if( sizeof(STMS_NUMBERING_FORM_ONE) == 2 ) sprintf( buffer, "%01d", i + stmsParameters->startTimePoint - 1);
 
         outputPath = expDescription->experimentPath+expDescription->outputFolder+
                 expDescription->outputCommonRoot+
@@ -154,15 +151,14 @@ itkSTMS_TemporalSetToImageSequence< ImageType, ClassImageType >
                 "_R-"+std::to_string(stmsParameters->rScale)+"_"+
                 buffer+expDescription->outputImageExtension;
 
-        ImagePointer outImage
-                = ImageType::New();
 
+
+        typename OutputImageType::Pointer outImage           = OutputImageType::New();
         outImage->SetRegions( region );
         outImage->Allocate();
-        outImage->FillBuffer( 15.0 );
+        outImage->FillBuffer( 0 );
 
-        WriterPointer writer
-                = WriterType::New();
+        WriterPointer writer            = WriterType::New();
         writer->SetFileName( outputPath );
 
         //#pragma omp parrallel for ...
@@ -176,7 +172,7 @@ itkSTMS_TemporalSetToImageSequence< ImageType, ClassImageType >
                     classIndex[k] = outIndex[k];
             }
 
-            outImage->SetPixel( outIndex, rangeSet->at( classSet->at(j)-1 )[i-1]*stmsParameters->rScale );
+            outImage->SetPixel( outIndex, static_cast<typename OutputImageType::PixelType>(rangeSet->at( classSet->at(j)-1 )[i-1]*stmsParameters->rScale) );
 
             if( first )
                 classImage->SetPixel(classIndex, classSet->at(j));
@@ -195,9 +191,9 @@ itkSTMS_TemporalSetToImageSequence< ImageType, ClassImageType >
 }
 
 
-template < class ImageType, class ClassImageType>
+template < class ImageType, class ClassImageType, class OutputImageType>
 void
-itkSTMS_TemporalSetToImageSequence< ImageType, ClassImageType >
+itkSTMS_TemporalSetToImageSequence< ImageType, ClassImageType, OutputImageType>
 ::GenerateCSVFile(const std::string &delimiter)
 {
     std::string CSVFilename = expDescription->experimentPath+expDescription->outputFolder+
@@ -207,13 +203,14 @@ itkSTMS_TemporalSetToImageSequence< ImageType, ClassImageType >
             "_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::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 << delimiter << std::count (classSet->begin(), classSet->end(), j+1);
+        ofs << delimiter << stmsParameters->startTimePoint << delimiter << stmsParameters->numTimePoints;
         for( unsigned int i=1 ; i<=stmsParameters->numTimePoints - stmsParameters->startTimePoint + 1; ++i )
            ofs << delimiter << rangeSet->at(j)[i-1]*stmsParameters->rScale ;
         ofs << std::endl;
index 7bc7b185dabc81e99a69f279b164a0873d80d473..b27cd9f5898dc1ba89563bad65f2e7a19f8388cf 100755 (executable)
@@ -70,6 +70,7 @@ namespace itkSTMS
         std::string  experimentPath;
         std::string  imageExtension;
         std::string  outputImageExtension;
+        std::string  outputClassExtension;
         std::string  inputCommonRoot;
         std::string  inputFolder;
         std::string  maskImage;
index 191adb356b4928ad9cb49c53e77319e99227c513..130e518bfc5a2c342ab12cd69959bd6de81753b8 100755 (executable)
@@ -69,6 +69,7 @@ itkSTMS_XMLFileParser::itkSTMS_XMLFileParser()
     xmlParams.experimentPath     = "";
     xmlParams.imageExtension     = "";
     xmlParams.outputImageExtension = "";
+    xmlParams.outputClassExtension = "";
     xmlParams.inputCommonRoot    = "";
     xmlParams.inputFolder        = "";
     xmlParams.maskImage          = "";
@@ -109,10 +110,18 @@ void itkSTMS_XMLFileParser::Update()
     xmlParams.outputImageExtension = DomObject->GetAttribute( "outputImageExtension" );
     if ( xmlParams.outputImageExtension == "" )
     {
-        std::cout << std::endl << std::endl <<  "outputImageExtension not set" << std::endl << std::endl;
-        std::exit( EXIT_FAILURE );
+        std::cout << std::endl << std::endl <<  "outputImageExtension not set, using same as input (imageExtension) : "<< xmlParams.imageExtension << std::endl << std::endl;
+        xmlParams.outputImageExtension = xmlParams.imageExtension;
     }
 
+    xmlParams.outputClassExtension = DomObject->GetAttribute( "outputClassExtension" );
+    if ( xmlParams.outputClassExtension == "" )
+    {
+        std::cout << std::endl << std::endl <<  "outputClassExtension not set, .nii (nifti) used by default" << std::endl << std::endl;
+        xmlParams.outputClassExtension = ".nii";
+    }
+
+
     // Read input parameters
     listInput = DomObject->GetChild( "listInput" );
     xmlParams.inputFolder = listInput->GetAttribute( "inputFolder" );
index c5ed43e21b3c55ed3e7d0a88def903d343ba191e..2fce5933eb3479030a9ef204f4d635f9645e9d1f 100755 (executable)
@@ -80,6 +80,8 @@ IF ( BUILD_${LIBRARY_NAME} )
    TARGET_LINK_LIBRARIES(${LIBRARY_NAME} ${${LIBRARY_NAME}_LINK_LIBRARIES} )
    SET_TARGET_PROPERTIES(${LIBRARY_NAME} PROPERTIES LINKER_LANGUAGE C)
 
+   install(TARGETS ${LIBRARY_NAME} DESTINATION lib)
+   install(FILES  ${LIBRARY_NAME_HEADERS} DESTINATION include)
   #
   #----------------------------------------------------------------------------
 
index 8dda23294f68d22d78f162114c33d79b41374739..1e37fbdb3581916f6fbad649bc4d79187477345c 100755 (executable)
@@ -60,6 +60,7 @@
 #ifndef itkSTMS_BlurringSTMS_TXX
 #define itkSTMS_BlurringSTMS_TXX
 
+#include <limits>
 #include <random>
 #include <algorithm>
 #include <iterator>
@@ -524,7 +525,7 @@ void
 itkSTMS_BlurringSTMS< IndexType, SpatialType, PixelType, ImageType >
 ::FinalMerging()
 {
-    unsigned int size = INFINITY;
+    unsigned int size = std::numeric_limits<unsigned int>::max() - 1; // INFINITY;
     std::string imagePath = expDescription->experimentPath+expDescription->inputFolder+expDescription->inputCommonRoot+STMS_NUMBERING_FORM_ONE+expDescription->imageExtension;
 
     while(size > classSet->size()){
@@ -628,7 +629,8 @@ itkSTMS_BlurringSTMS< IndexType, SpatialType, PixelType, ImageType >
                                         idx[0] = refClass->at(m)[0]+x;
                                         idx[1] = refClass->at(m)[1]+y;
 
-                                        if(idx[0]<image->GetBufferedRegion().GetSize()[0] && idx[0]>0 && idx[1]<image->GetBufferedRegion().GetSize()[1] && idx[1]>0)
+                                        if(   ( idx[0] < static_cast<long>(image->GetBufferedRegion().GetSize()[0]) )  && (idx[0]>0)
+                                            && (idx[1] < static_cast<long>(image->GetBufferedRegion().GetSize()[1]) )  && (idx[1]>0) )
                                         {
                                             if(image->GetPixel(idx) == 2)
                                             {
@@ -656,7 +658,8 @@ itkSTMS_BlurringSTMS< IndexType, SpatialType, PixelType, ImageType >
                                         idx[0] = candClass->at(m)[0]+x;
                                         idx[1] = candClass->at(m)[1]+y;
 
-                                        if(idx[0]<image->GetBufferedRegion().GetSize()[0] && idx[0]>0 && idx[1]<image->GetBufferedRegion().GetSize()[1] && idx[1]>0)
+                                        if(   ( idx[0] < static_cast<long>(image->GetBufferedRegion().GetSize()[0]) ) && ( idx[0] > 0 )
+                                           && ( idx[1] < static_cast<long>(image->GetBufferedRegion().GetSize()[1]) ) && ( idx[1] > 0 ) )
                                         {
                                             if(image->GetPixel(idx) == 1)
                                             {
@@ -691,7 +694,9 @@ itkSTMS_BlurringSTMS< IndexType, SpatialType, PixelType, ImageType >
                                             idx[1] = refClass->at(m)[1]+y;
                                             idx[2] = refClass->at(m)[2]+z;
 
-                                            if(idx[0]<image->GetBufferedRegion().GetSize()[0] && idx[0]>0 && idx[1]<image->GetBufferedRegion().GetSize()[1] && idx[1]>0 && idx[2]<image->GetBufferedRegion().GetSize()[2] && idx[2]>0)
+                                            if(  ( idx[0] < static_cast<long>(image->GetBufferedRegion().GetSize()[0]) ) && (idx[0] > 0) &&
+                                                 ( idx[1] < static_cast<long>(image->GetBufferedRegion().GetSize()[1]) ) && (idx[1] > 0) &&
+                                                 ( idx[2] < static_cast<long>(image->GetBufferedRegion().GetSize()[2]) ) && (idx[2] > 0)  )
                                             {
                                                 if(image->GetPixel(idx) == 2)
                                                 {
@@ -724,7 +729,9 @@ itkSTMS_BlurringSTMS< IndexType, SpatialType, PixelType, ImageType >
                                             idx[1] = candClass->at(m)[1]+y;
                                             idx[2] = candClass->at(m)[2]+z;
 
-                                            if(idx[0]<image->GetBufferedRegion().GetSize()[0] && idx[0]>0 && idx[1]<image->GetBufferedRegion().GetSize()[1] && idx[1]>0 && idx[2]<image->GetBufferedRegion().GetSize()[2] && idx[2]>0)
+                                            if(   ( idx[0] < static_cast<long>(image->GetBufferedRegion().GetSize()[0]) ) && ( idx[0] > 0 ) &&
+                                                  ( idx[1] < static_cast<long>(image->GetBufferedRegion().GetSize()[1]) ) && ( idx[1] > 0 ) &&
+                                                  ( idx[2] < static_cast<long>(image->GetBufferedRegion().GetSize()[2]) ) && ( idx[2] > 0 ) )
                                             {
                                                 if(image->GetPixel(idx) == 1)
                                                 {
index d0ddbc4f6ad60ead10859b4f81e9f16f8b4fb5b5..b5c695a005d221b440afd97a633e36552d0b33ef 100755 (executable)
@@ -27,5 +27,8 @@ target_link_libraries(STMS_GrayLevelFiltering ${ITK_LIBRARIES})
 #add_executable(STMS_GrayLevelFiltering_Spine STMS_GrayLevelFiltering_Spine.cxx )
 #target_link_libraries(STMS_GrayLevelFiltering_Spine ${ITK_LIBRARIES})
 
+install(TARGETS STMS_GrayLevelFiltering DESTINATION bin)
+
 add_executable(STMS_generateClosestMap STMS_generateClosestMap.cxx)
 target_link_libraries(STMS_generateClosestMap ${ITK_LIBRARIES})
+install(TARGETS STMS_generateClosestMap DESTINATION bin)
index 6de788375fa7c36391b51c0a6653590728bb11eb..d0c17d2f312b142f1d59153a3f8686ef577afe5c 100755 (executable)
@@ -60,7 +60,7 @@
 #include <iomanip>
 #include <ctime>
 
-#define STMS_NUMBERING_FORM_ONE "001"
+#define STMS_NUMBERING_FORM_ONE "0001"
 
 #include "itkImage.h"
 #include "itkSTMS_ArgumentsAnalysis.h"
@@ -73,6 +73,9 @@
 
 
 typedef float PixelType;
+typedef unsigned char OutputPixelType2D;
+typedef float OutputPixelType3D;
+
 
 double gettime_hp()
 {
@@ -110,8 +113,9 @@ int main(int argc, char **argv){
     switch(params->dim){
         case 2:
         {
-            typedef itk::Image< PixelType, 2 >     ImageType2D;
-            typedef itk::Image< unsigned char, 2 > MaskImageType2D;
+            typedef itk::Image< PixelType, 2 >          ImageType2D;
+            typedef itk::Image< OutputPixelType2D, 2 >  OutputImageType2D;
+            typedef itk::Image< unsigned char, 2 >      MaskImageType2D;
 
 
             typedef itkSTMS::itkSTMS_ImageSequenceToTemporalSet< ImageType2D, MaskImageType2D >::IndexType            IndexType;
@@ -153,8 +157,8 @@ int main(int argc, char **argv){
 
             dtime=gettime_hp();
 
-            itkSTMS::itkSTMS_TemporalSetToImageSequence< ImageType2D, ClassImageType2D >* postProcess
-                    = new itkSTMS::itkSTMS_TemporalSetToImageSequence< ImageType2D, ClassImageType2D >(stmsFilter->GetClassMemory(),
+            itkSTMS::itkSTMS_TemporalSetToImageSequence< ImageType2D, ClassImageType2D, OutputImageType2D >* postProcess
+                    = new itkSTMS::itkSTMS_TemporalSetToImageSequence< ImageType2D, ClassImageType2D, OutputImageType2D>(stmsFilter->GetClassMemory(),
                                                                                                        stmsFilter->GetSpatialMemory(),
                                                                                                        stmsFilter->GetRangeSet(),
                                                                                                        params,
@@ -177,6 +181,7 @@ int main(int argc, char **argv){
         case 3:
         {
             typedef itk::Image< PixelType, 3 >     ImageType3D;
+            typedef itk::Image< OutputPixelType3D, 3 >     OutputImageType3D;
             typedef itk::Image< unsigned char, 3 > MaskImageType3D;
 
             typedef itkSTMS::itkSTMS_ImageSequenceToTemporalSet< ImageType3D, MaskImageType3D >::IndexType            IndexType;
@@ -218,8 +223,8 @@ int main(int argc, char **argv){
 
             dtime=gettime_hp();
 
-            itkSTMS::itkSTMS_TemporalSetToImageSequence< ImageType3D, MaskImageType3D >* postProcess
-                    = new itkSTMS::itkSTMS_TemporalSetToImageSequence< ImageType3D, MaskImageType3D >(stmsFilter->GetClassMemory(),
+            itkSTMS::itkSTMS_TemporalSetToImageSequence< ImageType3D, MaskImageType3D, OutputImageType3D>* postProcess
+                    = new itkSTMS::itkSTMS_TemporalSetToImageSequence< ImageType3D, MaskImageType3D, OutputImageType3D >(stmsFilter->GetClassMemory(),
                                                                                                       stmsFilter->GetSpatialMemory(),
                                                                                                       stmsFilter->GetRangeSet(),
                                                                                                       params,