/* # # File : itkSTMS_TemporalSetToImageSequence_Spine.txx # ( C++ header file - STMS ) # # Description : STMS lib that implements the STMS filter and clustering. # This file is a part of the STMS Library project. # ( https://www.creatis.insa-lyon.fr/site7/fr/realisations ) # # [1] S. Mure, Grenier, T., Meier, S., Guttmann, R. G., et Benoit-Cattin, H., # « Unsupervised spatio-temporal filtering of image sequences. A mean-shift specification », # Pattern Recognition Letters, vol. 68, Part 1, p. 48 - 55, 2015. # # Copyright : Thomas GRENIER - Simon MURE # ( https://www.creatis.insa-lyon.fr/~grenier/ ) # # License : CeCILL C # ( http://www.cecill.info/licences/Licence_CeCILL-C_V1-en.txt ) # # This software is governed by the CeCILL license under French law and # abiding by the rules of distribution of free software. You can use, # modify and/ or redistribute the software under the terms of the CeCILL # license as circulated by CEA, CNRS and INRIA at the following URL # "http://www.cecill.info". # # As a counterpart to the access to the source code and rights to copy, # modify and redistribute granted by the license, users are provided only # with a limited warranty and the software's author, the holder of the # economic rights, and the successive licensors have only limited # liability. # # In this respect, the user's attention is drawn to the risks associated # with loading, using, modifying and/or developing or reproducing the # software by the user in light of its specific status of free software, # that may mean that it is complicated to manipulate, and that also # therefore means that it is reserved for developers and experienced # professionals having in-depth computer knowledge. Users are therefore # encouraged to load and test the software's suitability as regards their # requirements in conditions enabling the security of their systems and/or # data to be ensured and, more generally, to use and operate it in the # same conditions as regards security. # # The fact that you are presently reading this means that you have had # knowledge of the CeCILL license and that you accept its terms. # */ /* Please don't forget to cite our work : @article {MURE-15a, title = {Unsupervised spatio-temporal filtering of image sequences. A mean-shift specification}, journal = {Pattern Recognition Letters}, volume = {68, Part 1}, year = {2015}, pages = {48 - 55}, issn = {0167-8655}, doi = {http://dx.doi.org/10.1016/j.patrec.2015.07.021}, url = {http://www.sciencedirect.com/science/article/pii/S0167865515002305}, author = {S. Mure and T Grenier and Meier, S. and Guttmann, R.G. and H. Benoit-Cattin} } */ #ifndef itkSTMS_TemporalSetToImageSequenceSpine_txx #define itkSTMS_TemporalSetToImageSequenceSpine_txx #include "itkSTMS_TemporalSetToImageSequence_Spine.h" #include "itkSTMS_ArgumentsAnalysis_Spine.h" namespace itkSTMS_Spine { template < class ImageType, class ClassImageType > itkSTMS_TemporalSetToImageSequence < ImageType, ClassImageType > ::itkSTMS_TemporalSetToImageSequence( IndexSampleSetType* cl, SpatialSampleSetType* sp, RangeSampleSetType* ra, itkSTMS_Spine::ParamsAnalysisOutputType* params) { this->stmsParameters = params; this->classSet = cl; this->spatialSet = sp; this->rangeSet = ra; } template < class ImageType, class ClassImageType > void itkSTMS_TemporalSetToImageSequence< ImageType, ClassImageType > ::GenerateImageSequence() { bool first = true; // Output images allocation ImagePointer image = ImageType::New(); ReaderPointer reader = ReaderType::New(); reader->SetFileName( *stmsParameters->images.begin() ); reader->Update(); image = reader->GetOutput(); SpatialIndexType start, outIndex, classIndex; start.Fill(0); RegionType region; region.SetSize( image->GetBufferedRegion().GetSize()); region.SetIndex(start); ClassRegionType classRegion; classRegion.SetSize( image->GetBufferedRegion().GetSize()); classRegion.SetIndex( start ); std::string outputPath, classPath; ClassImagePointer classImage = ClassImageType::New(); classImage->SetRegions( classRegion ); classImage->Allocate(); classImage->FillBuffer( 15.0 ); // Filetered image sequence and class image saving // for( unsigned int i=1 ; i<=stmsParameters->numTimePoints ; ++i ) // { unsigned int i=1; for (std::list::iterator it_images = stmsParameters->images.begin(); it_images != stmsParameters->images.end(); ++it_images) { outputPath = stmsParameters->outFolder+ it_images->substr( it_images->find_last_of("/"), it_images->length()-stmsParameters->imageExtension.length()-it_images->find_last_of("/") ) + "_X-"+std::to_string((unsigned int)stmsParameters->spScales[0])+ "_Y-"+std::to_string((unsigned int)stmsParameters->spScales[1])+ "_Z-"+std::to_string(stmsParameters->spScales[2])+ "_R-"+std::to_string(stmsParameters->rScale)+"_"+ std::to_string(i)+stmsParameters->imageExtension; ImagePointer outImage = ImageType::New(); outImage->SetRegions( region ); outImage->Allocate(); outImage->FillBuffer( 15.0 ); WriterPointer writer = WriterType::New(); writer->SetFileName( outputPath ); //#pragma omp parrallel for ... for(unsigned int j=0 ; jsize() ; ++j) { for( unsigned int k=0 ; kdim ; ++k) { outIndex[k] = (IndexType)( round(spatialSet->at(j)[k]*stmsParameters->spScales[k]) ); if( first ) classIndex[k] = outIndex[k]; } outImage->SetPixel( outIndex, rangeSet->at( classSet->at(j)-1 )[i-1]*stmsParameters->rScale ); if( first ) classImage->SetPixel(classIndex, classSet->at(j)); } writer->SetInput( outImage ); writer->Update(); if( first ) { classPath = stmsParameters->outFolder + it_images->substr( it_images->find_last_of("/"), it_images->length()-stmsParameters->imageExtension.length()-it_images->find_last_of("/") ) + "_Class_X-"+std::to_string((unsigned int)stmsParameters->spScales[0])+ "_Y-"+std::to_string((unsigned int)stmsParameters->spScales[1])+ "_Z-"+std::to_string(stmsParameters->spScales[2])+ "_R-"+std::to_string(stmsParameters->rScale)+"_"+ stmsParameters->imageExtension; ClassWriterPointer classWriter = ClassWriterType::New(); classWriter->SetFileName( classPath ); classWriter->SetInput( classImage ); classWriter->Update(); first = false; } ++i; } } } // end of namespace itkSTMS #endif