From 24c64f13145b43b638d11d938dcc24a9dc89cb74 Mon Sep 17 00:00:00 2001 From: Thomas Greneir Date: Wed, 20 Sep 2017 18:34:34 +0200 Subject: [PATCH] output 2D as png file new options in .xml file about image file extension --- CMakeLists.txt.user | 232 ++++++++++++++++++ .../itkSTMS_TemporalSetToImageSequence.h | 4 +- .../itkSTMS_TemporalSetToImageSequence.txx | 29 ++- Lib/PrePostProcessing/itkSTMS_XMLFileParser.h | 1 + .../itkSTMS_XMLFileParser.hxx | 13 +- Src/STMS_GrayLevelFiltering.cxx | 17 +- 6 files changed, 271 insertions(+), 25 deletions(-) create mode 100644 CMakeLists.txt.user diff --git a/CMakeLists.txt.user b/CMakeLists.txt.user new file mode 100644 index 0000000..e49be18 --- /dev/null +++ b/CMakeLists.txt.user @@ -0,0 +1,232 @@ + + + + + + EnvironmentId + {0d0dac41-b5d4-48ba-8b55-2eef6c8f9c37} + + + ProjectExplorer.Project.ActiveTarget + 0 + + + ProjectExplorer.Project.EditorSettings + + true + false + true + + Cpp + + CppGlobal + + + 1 + UTF-8 + false + 4 + false + 80 + true + true + 1 + true + false + 0 + true + true + 0 + 8 + true + 1 + true + true + true + false + + + + ProjectExplorer.Project.PluginSettings + + + + ProjectExplorer.Project.Target.0 + + Desktop + Desktop + {02771194-e57d-45d0-a1ce-cf0336f8bb4f} + 1 + 0 + 0 + + + CMAKE_BUILD_TYPE:STRING=Debug + + /opt/MasterGrenier/bin/Creatis_GIT/STMS/STMS-Debug + + + + + all + + true + Make + + CMakeProjectManager.MakeStep + + 1 + Build + + ProjectExplorer.BuildSteps.Build + + + + + + clean + + true + Make + + CMakeProjectManager.MakeStep + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Debug + Debug + CMakeProjectManager.CMakeBuildConfiguration + + + + CMAKE_BUILD_TYPE:STRING=Release + CMAKE_CXX_COMPILER:FILEPATH=/usr/bin/c++ + + /opt/MasterGrenier/bin/Creatis_GIT/STMS/STMS-Release + + + + + all + + true + Make + + CMakeProjectManager.MakeStep + + 1 + Build + + ProjectExplorer.BuildSteps.Build + + + + + + clean + + true + Make + + CMakeProjectManager.MakeStep + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Release + Release + CMakeProjectManager.CMakeBuildConfiguration + + 2 + + + 0 + Deploy + + ProjectExplorer.BuildSteps.Deploy + + 1 + Deploy locally + + ProjectExplorer.DefaultDeployConfiguration + + 1 + + + + false + false + false + false + true + 0.01 + 10 + true + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + STMS_GrayLevelFiltering + + + /opt/MasterGrenier/bin/Creatis_GIT/STMS/STMS-Release/Src + 2 + + STMS_GrayLevelFiltering + + CMakeProjectManager.CMakeRunConfiguration.STMS_GrayLevelFiltering + 3768 + false + true + false + false + true + + 1 + + + + ProjectExplorer.Project.TargetCount + 1 + + + ProjectExplorer.Project.Updater.FileVersion + 18 + + + Version + 18 + + diff --git a/Lib/PrePostProcessing/itkSTMS_TemporalSetToImageSequence.h b/Lib/PrePostProcessing/itkSTMS_TemporalSetToImageSequence.h index 996d65b..1b53b3e 100755 --- a/Lib/PrePostProcessing/itkSTMS_TemporalSetToImageSequence.h +++ b/Lib/PrePostProcessing/itkSTMS_TemporalSetToImageSequence.h @@ -77,14 +77,14 @@ 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; diff --git a/Lib/PrePostProcessing/itkSTMS_TemporalSetToImageSequence.txx b/Lib/PrePostProcessing/itkSTMS_TemporalSetToImageSequence.txx index c988bb7..1159187 100755 --- a/Lib/PrePostProcessing/itkSTMS_TemporalSetToImageSequence.txx +++ b/Lib/PrePostProcessing/itkSTMS_TemporalSetToImageSequence.txx @@ -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,10 +126,9 @@ 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 @@ -154,10 +151,12 @@ 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(); writer->SetFileName( outputPath ); @@ -173,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(rangeSet->at( classSet->at(j)-1 )[i-1]*stmsParameters->rScale) ); if( first ) classImage->SetPixel(classIndex, classSet->at(j)); @@ -192,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+ diff --git a/Lib/PrePostProcessing/itkSTMS_XMLFileParser.h b/Lib/PrePostProcessing/itkSTMS_XMLFileParser.h index 7bc7b18..b27cd9f 100755 --- a/Lib/PrePostProcessing/itkSTMS_XMLFileParser.h +++ b/Lib/PrePostProcessing/itkSTMS_XMLFileParser.h @@ -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; diff --git a/Lib/PrePostProcessing/itkSTMS_XMLFileParser.hxx b/Lib/PrePostProcessing/itkSTMS_XMLFileParser.hxx index 191adb3..130e518 100755 --- a/Lib/PrePostProcessing/itkSTMS_XMLFileParser.hxx +++ b/Lib/PrePostProcessing/itkSTMS_XMLFileParser.hxx @@ -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" ); diff --git a/Src/STMS_GrayLevelFiltering.cxx b/Src/STMS_GrayLevelFiltering.cxx index f999b5f..c7cfffd 100755 --- a/Src/STMS_GrayLevelFiltering.cxx +++ b/Src/STMS_GrayLevelFiltering.cxx @@ -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, -- 2.47.1