3 # File : itkSTMS_ImageSequenceToTemporalSet_Spine.txx
4 # ( C++ header file - STMS )
6 # Description : STMS lib that implements the STMS filter and clustering.
7 # This file is a part of the STMS Library project.
8 # ( https://www.creatis.insa-lyon.fr/site7/fr/realisations )
10 # [1] S. Mure, Grenier, T., Meier, S., Guttmann, R. G., et Benoit-Cattin, H.,
11 # « Unsupervised spatio-temporal filtering of image sequences. A mean-shift specification »,
12 # Pattern Recognition Letters, vol. 68, Part 1, p. 48 - 55, 2015.
14 # Copyright : Thomas GRENIER - Simon MURE
15 # ( https://www.creatis.insa-lyon.fr/~grenier/ )
18 # ( http://www.cecill.info/licences/Licence_CeCILL-C_V1-en.txt )
20 # This software is governed by the CeCILL license under French law and
21 # abiding by the rules of distribution of free software. You can use,
22 # modify and/ or redistribute the software under the terms of the CeCILL
23 # license as circulated by CEA, CNRS and INRIA at the following URL
24 # "http://www.cecill.info".
26 # As a counterpart to the access to the source code and rights to copy,
27 # modify and redistribute granted by the license, users are provided only
28 # with a limited warranty and the software's author, the holder of the
29 # economic rights, and the successive licensors have only limited
32 # In this respect, the user's attention is drawn to the risks associated
33 # with loading, using, modifying and/or developing or reproducing the
34 # software by the user in light of its specific status of free software,
35 # that may mean that it is complicated to manipulate, and that also
36 # therefore means that it is reserved for developers and experienced
37 # professionals having in-depth computer knowledge. Users are therefore
38 # encouraged to load and test the software's suitability as regards their
39 # requirements in conditions enabling the security of their systems and/or
40 # data to be ensured and, more generally, to use and operate it in the
41 # same conditions as regards security.
43 # The fact that you are presently reading this means that you have had
44 # knowledge of the CeCILL license and that you accept its terms.
47 /* Please don't forget to cite our work :
49 title = {Unsupervised spatio-temporal filtering of image sequences. A mean-shift specification},
50 journal = {Pattern Recognition Letters},
51 volume = {68, Part 1},
55 doi = {http://dx.doi.org/10.1016/j.patrec.2015.07.021},
56 url = {http://www.sciencedirect.com/science/article/pii/S0167865515002305},
57 author = {S. Mure and T Grenier and Meier, S. and Guttmann, R.G. and H. Benoit-Cattin}
60 #ifndef itkSTMS_ImageSequenceToTemporalSetSpine_txx
61 #define itkSTMS_ImageSequenceToTemporalSetSpine_txx
64 #include "itkSTMS_ImageSequenceToTemporalSet_Spine.h"
65 #include "itkSTMS_ArgumentsAnalysis_Spine.h"
68 namespace itkSTMS_Spine
71 template < class ImageType, class MaskImageType >
72 itkSTMS_ImageSequenceToTemporalSet < ImageType, MaskImageType >
73 ::itkSTMS_ImageSequenceToTemporalSet( ParamsAnalysisOutputType* stmsParameters )
75 // Get experiments parameters given by the user
76 this->stmsParameters = stmsParameters;
78 // If a mask image is specified ==> instanciation of a mask iterator (region with the highest value in the mask)
79 if( !this->stmsParameters->mask.empty() )
81 mask = MaskImageType::New();
82 mReader = MaskReaderType::New();
83 MinMaxCalculator = MinMaxCalculatorType::New();
85 mReader->SetFileName( this->stmsParameters->mask );
87 mask = mReader->GetOutput();
89 MinMaxCalculator->SetImage( mask );
90 MinMaxCalculator->ComputeMaximum();
91 maskValue = (MaskPixelType)MinMaxCalculator->GetMaximum();
93 mIt = MaskIteratorType( mask, mask->GetLargestPossibleRegion() ); //->GetBufferedRegion() );
98 template < class ImageType, class MaskImageType >
100 itkSTMS_ImageSequenceToTemporalSet< ImageType, MaskImageType >
107 // Preprocessing of the whole image sequence
109 for (std::list<std::string>::iterator it_images = stmsParameters->images.begin(); it_images != stmsParameters->images.end(); ++it_images)
116 = itk::ImageFileReader< ImageType >::New();
118 reader->SetFileName( *it_images );
120 image = reader->GetOutput();
122 IteratorType it( image, image->GetLargestPossibleRegion() );
123 SizeType Size = image->GetLargestPossibleRegion().GetSize();
125 // If there is no mask image specified, all the pixels are extracted
126 if( stmsParameters->mask.empty() )
128 // Only the range values have to be extracted at each time-point. The others need to be extracted just one time.
131 // Containers initialisation
132 unsigned int numSamples = (unsigned int)Size[0];
134 for( unsigned int j=1 ; j<stmsParameters->dim ; ++j )
135 numSamples *= (unsigned int)Size[j];
137 indexSet = IndexSampleSetType( numSamples, 0 );
138 classSet = IndexSampleSetType( numSamples, 0 );
139 mergingSet = IndexSampleSetType( numSamples, 0 );
140 weightsSet = IndexSampleSetType( numSamples, 1 );
141 spatialSet = SpatialSampleSetType( numSamples, SpatialVectorType(stmsParameters->dim, 0));
142 rangeSet = RangeSampleSetType ( numSamples, RangeVectorType(stmsParameters->numTimePoints, 0) );
145 // Samples extraction
147 while( !it.IsAtEnd() ){
150 classSet[idx] = idx+1;
152 for( unsigned int j=0 ; j<stmsParameters->dim ; ++j )
153 spatialSet[idx][j] = (SpatialType)( it.GetIndex()[j]/stmsParameters->spScales[j] );
156 rangeSet[idx++][i-1] = (PixelType)(it.Get()/stmsParameters->rScale);
163 // If a mask is specified, just the characteristics of the pixels equal to maskValue in the mask image are extracted
166 // In this case the number of samples is not known in advance
169 indexSet = IndexSampleSetType();
170 classSet = IndexSampleSetType();
171 mergingSet = IndexSampleSetType();
172 weightsSet = IndexSampleSetType();
173 spatialSet = SpatialSampleSetType();
174 rangeSet = RangeSampleSetType();
176 indexSet.reserve ( Size[0]*Size[1] );
177 classSet.reserve ( Size[0]*Size[1] );
178 mergingSet.reserve( Size[0]*Size[1] );
179 weightsSet.reserve( Size[0]*Size[1] );
180 spatialSet.reserve( Size[0]*Size[1] );
181 rangeSet.reserve ( Size[0]*Size[1] );
184 // Samples extraction
187 while( !mIt.IsAtEnd() )
189 if(mIt.Get() == maskValue)
193 SpatialVectorType spComp = SpatialVectorType(stmsParameters->dim, 0);
194 for( unsigned int j=0 ; j<stmsParameters->dim ; ++j )
195 spComp[j] = (SpatialType)( it.GetIndex()[j]/stmsParameters->spScales[j] );
197 indexSet.push_back ( idx );
198 classSet.push_back ( ++idx );
199 mergingSet.push_back( 0 );
200 weightsSet.push_back( 1 );
201 spatialSet.push_back( spComp );
202 rangeSet.push_back( RangeVectorType(stmsParameters->numTimePoints, (PixelType)(it.Get()/stmsParameters->rScale)) );
205 rangeSet[idx++][i-1] = (PixelType)(it.Get()/stmsParameters->rScale);
220 } // end of namespace itkSTMS