3 # File : STMS_GrayLevelFiltering.cxx
4 # ( C++ example 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/ )
17 # License : CeCILL V2.1
18 # ( http://www.cecill.info/licences/Licence_CeCILL_V2.1-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}
63 #define STMS_NUMBERING_FORM_ONE "01"
66 #include "itkSTMS_ArgumentsAnalysis.h"
67 #include "itkSTMS_ImageSequenceToTemporalSet.h"
68 #include "itkSTMS_TemporalSetToImageSequence.h"
69 #include "itkSTMS_BlurringSTMS.h"
75 typedef float PixelType;
76 typedef unsigned char OutputPixelType2D;
77 typedef float OutputPixelType3D;
82 struct timespec timestamp;
84 clock_gettime(CLOCK_REALTIME, ×tamp);
85 return timestamp.tv_sec * 1000.0 + timestamp.tv_nsec * 1.0e-6;
88 // Only --expDescription and numTimePoints parameter are compulsory.
90 //--expDescription /run/media/mure/HDD/Recherche/These/CVS/Mure/Dev/Cpp/itkSTMS/Data/P43_Parser.xml --imageDimension 2 --xScale 20 --yScale 20 --rScale 1 --epsilon 0.1 --maxIt 20 --numTimePoints 25 --merge
92 //--expDescription /run/media/mure/HDD/Recherche/These/CVS/Mure/Dev/Cpp/itkSTMS/Data/L43_3_Parser.xml --imageDimension 3 --xScale 1000 --yScale 1000 --zScale 1000 --rScale 0.75 --epsilon 0.1 --maxIt 50 --numTimePoints 25 --merge
93 //--expDescription /run/media/mure/HDD/Recherche/These/CVS/Mure/Dev/Cpp/itkSTMS/Data/Simu_Parser.xml --imageDimension 2 --xScale 255 --yScale 255 --rScale 0.4 --epsilon 0.01 --maxIt 50 --numTimePoints 8
94 //--expDescription /run/media/mure/HDD/Recherche/These/CVS/Mure/Dev/Cpp/itkSTMS/Data/G1_Parser.xml --imageDimension 3 --xScale 1000 --yScale 1000 --zScale 1000 --rScale 0.15 --epsilon 0.01 --maxIt 50 --numTimePoints 8
96 // --expDescription E:/Documents/Creatis/Projets/15_MUST/Data_Cardiac/Parser_AIF_Cardiac.xml --imageDimension 2 --xScale 10 --yScale 10 --rScale 10 --numTimePoints 80
98 int main(int argc, char **argv){
101 std::cout << "The Numbering form is set to numbers like = " << STMS_NUMBERING_FORM_ONE << std::endl;
102 std::cout << "size : " << sizeof(STMS_NUMBERING_FORM_ONE) << std::endl;
105 itkSTMS::itkSTMS_ArgumentsAnalysis* argsAnalysis
106 = new itkSTMS::itkSTMS_ArgumentsAnalysis(argc, argv);
107 argsAnalysis->Update();
109 itkSTMS::ParamsAnalysisOutputType* params
110 = argsAnalysis->GetSTMSParams();
116 typedef itk::Image< PixelType, 2 > ImageType2D;
117 typedef itk::Image< OutputPixelType2D, 2 > OutputImageType2D;
118 typedef itk::Image< unsigned char, 2 > MaskImageType2D;
121 typedef itkSTMS::itkSTMS_ImageSequenceToTemporalSet< ImageType2D, MaskImageType2D >::IndexType IndexType;
122 typedef itkSTMS::itkSTMS_ImageSequenceToTemporalSet< ImageType2D, MaskImageType2D >::SpatialType SpatialType;
123 typedef itkSTMS::itkSTMS_ImageSequenceToTemporalSet< ImageType2D, MaskImageType2D >::IndexSampleSetType IndexSampleSetType;
124 typedef itkSTMS::itkSTMS_ImageSequenceToTemporalSet< ImageType2D, MaskImageType2D >::SpatialSampleSetType SpatialSampleSetType;
125 typedef itkSTMS::itkSTMS_ImageSequenceToTemporalSet< ImageType2D, MaskImageType2D >::RangeSampleSetType RangeSampleSetType;
127 typedef itk::Image< IndexType, 2 > ClassImageType2D;
132 itkSTMS::itkSTMS_ImageSequenceToTemporalSet< ImageType2D, MaskImageType2D >* preProcess
133 = new itkSTMS::itkSTMS_ImageSequenceToTemporalSet< ImageType2D, MaskImageType2D > ( params );
134 preProcess->GenerateDataSets();
136 dtime = gettime_hp()-dtime;
137 std::cout<<std::endl<< std::setw(30) << std::left << "Characteristics extraction: " << dtime/1000 << " s" <<std::endl;
139 IndexSampleSetType* indexSet = preProcess->GetIndexSet();
140 IndexSampleSetType* classSet = preProcess->GetClassSet();
141 IndexSampleSetType* weightsSet = preProcess->GetWeightsSet();
142 SpatialSampleSetType* spatialSet = preProcess->GetSpatialSet();
143 RangeSampleSetType* rangeSet = preProcess->GetRangeSet();
148 itkSTMS::itkSTMS_BlurringSTMS< IndexType, SpatialType, PixelType, ImageType2D >* stmsFilter
149 = new itkSTMS::itkSTMS_BlurringSTMS< IndexType, SpatialType, PixelType, ImageType2D >
150 (indexSet, classSet, weightsSet, spatialSet, rangeSet, params, preProcess->GetExperimentDescription());
152 stmsFilter->GenerateData();
154 dtime = gettime_hp()-dtime;
155 std::cout<<std::endl<< std::setw(30) << std::left << "STMS filtering: " << dtime/1000 << " s" <<std::endl;
160 itkSTMS::itkSTMS_TemporalSetToImageSequence< ImageType2D, ClassImageType2D, OutputImageType2D >* postProcess
161 = new itkSTMS::itkSTMS_TemporalSetToImageSequence< ImageType2D, ClassImageType2D, OutputImageType2D>(stmsFilter->GetClassMemory(),
162 stmsFilter->GetSpatialMemory(),
163 stmsFilter->GetRangeSet(),
165 preProcess->GetExperimentDescription());
167 postProcess->GenerateImageSequence();
168 if(preProcess->GetExperimentDescription()->outputCSV == "true" )
169 postProcess->GenerateCSVFile();
171 dtime = gettime_hp()-dtime;
172 std::cout<<std::endl<< std::setw(30) << std::left << "Image sequence saving: " << dtime/1000 << " s" <<std::endl;
183 typedef itk::Image< PixelType, 3 > ImageType3D;
184 typedef itk::Image< OutputPixelType3D, 3 > OutputImageType3D;
185 typedef itk::Image< unsigned char, 3 > MaskImageType3D;
187 typedef itkSTMS::itkSTMS_ImageSequenceToTemporalSet< ImageType3D, MaskImageType3D >::IndexType IndexType;
188 typedef itkSTMS::itkSTMS_ImageSequenceToTemporalSet< ImageType3D, MaskImageType3D >::SpatialType SpatialType;
189 typedef itkSTMS::itkSTMS_ImageSequenceToTemporalSet< ImageType3D, MaskImageType3D >::IndexSampleSetType IndexSampleSetType;
190 typedef itkSTMS::itkSTMS_ImageSequenceToTemporalSet< ImageType3D, MaskImageType3D >::SpatialSampleSetType SpatialSampleSetType;
191 typedef itkSTMS::itkSTMS_ImageSequenceToTemporalSet< ImageType3D, MaskImageType3D >::RangeSampleSetType RangeSampleSetType;
196 itkSTMS::itkSTMS_ImageSequenceToTemporalSet< ImageType3D, MaskImageType3D >* preProcess
197 = new itkSTMS::itkSTMS_ImageSequenceToTemporalSet< ImageType3D, MaskImageType3D > ( params );
198 preProcess->GenerateDataSets();
200 dtime = gettime_hp()-dtime;
201 std::cout<<std::endl<< std::setw(30) << std::left << "Characteristics extraction: " << dtime/1000 << " s" <<std::endl;
203 IndexSampleSetType* indexSet = preProcess->GetIndexSet();
204 IndexSampleSetType* classSet = preProcess->GetClassSet();
205 IndexSampleSetType* weightsSet = preProcess->GetWeightsSet();
206 SpatialSampleSetType* spatialSet = preProcess->GetSpatialSet();
207 RangeSampleSetType* rangeSet = preProcess->GetRangeSet();
214 itkSTMS::itkSTMS_BlurringSTMS< IndexType, SpatialType, PixelType, ImageType3D >* stmsFilter
215 = new itkSTMS::itkSTMS_BlurringSTMS< IndexType, SpatialType, PixelType, ImageType3D >
216 (indexSet, classSet, weightsSet, spatialSet, rangeSet, params, preProcess->GetExperimentDescription());
218 stmsFilter->GenerateData();
220 dtime = gettime_hp()-dtime;
221 std::cout<<std::endl<< std::setw(30) << std::left << "STMS filtering: " << dtime/1000 << " s" <<std::endl;
226 itkSTMS::itkSTMS_TemporalSetToImageSequence< ImageType3D, MaskImageType3D, OutputImageType3D>* postProcess
227 = new itkSTMS::itkSTMS_TemporalSetToImageSequence< ImageType3D, MaskImageType3D, OutputImageType3D >(stmsFilter->GetClassMemory(),
228 stmsFilter->GetSpatialMemory(),
229 stmsFilter->GetRangeSet(),
231 preProcess->GetExperimentDescription());
233 postProcess->GenerateImageSequence();
234 if(preProcess->GetExperimentDescription()->outputCSV == "true" )
235 postProcess->GenerateCSVFile();
237 dtime = gettime_hp()-dtime;
238 std::cout<<std::endl<< std::setw(30) << std::left << "Image sequence saving: " << dtime/1000 << " s" <<std::endl;
252 std::cout << std::endl << "Image dimensionality should be equal to 2 or 3.";
253 std::exit( EXIT_FAILURE );