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;
79 struct timespec timestamp;
81 clock_gettime(CLOCK_REALTIME, ×tamp);
82 return timestamp.tv_sec * 1000.0 + timestamp.tv_nsec * 1.0e-6;
85 // Only --expDescription and numTimePoints parameter are compulsory.
87 //--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
89 //--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
90 //--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
91 //--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
93 // --expDescription E:/Documents/Creatis/Projets/15_MUST/Data_Cardiac/Parser_AIF_Cardiac.xml --imageDimension 2 --xScale 10 --yScale 10 --rScale 10 --numTimePoints 80
95 int main(int argc, char **argv){
98 std::cout << "The Numbering form is set to numbers like = " << STMS_NUMBERING_FORM_ONE << std::endl;
99 std::cout << "size : " << sizeof(STMS_NUMBERING_FORM_ONE) << std::endl;
102 itkSTMS::itkSTMS_ArgumentsAnalysis* argsAnalysis
103 = new itkSTMS::itkSTMS_ArgumentsAnalysis(argc, argv);
104 argsAnalysis->Update();
106 itkSTMS::ParamsAnalysisOutputType* params
107 = argsAnalysis->GetSTMSParams();
113 typedef itk::Image< PixelType, 2 > ImageType2D;
114 typedef itk::Image< unsigned char, 2 > MaskImageType2D;
117 typedef itkSTMS::itkSTMS_ImageSequenceToTemporalSet< ImageType2D, MaskImageType2D >::IndexType IndexType;
118 typedef itkSTMS::itkSTMS_ImageSequenceToTemporalSet< ImageType2D, MaskImageType2D >::SpatialType SpatialType;
119 typedef itkSTMS::itkSTMS_ImageSequenceToTemporalSet< ImageType2D, MaskImageType2D >::IndexSampleSetType IndexSampleSetType;
120 typedef itkSTMS::itkSTMS_ImageSequenceToTemporalSet< ImageType2D, MaskImageType2D >::SpatialSampleSetType SpatialSampleSetType;
121 typedef itkSTMS::itkSTMS_ImageSequenceToTemporalSet< ImageType2D, MaskImageType2D >::RangeSampleSetType RangeSampleSetType;
123 typedef itk::Image< IndexType, 2 > ClassImageType2D;
128 itkSTMS::itkSTMS_ImageSequenceToTemporalSet< ImageType2D, MaskImageType2D >* preProcess
129 = new itkSTMS::itkSTMS_ImageSequenceToTemporalSet< ImageType2D, MaskImageType2D > ( params );
130 preProcess->GenerateDataSets();
132 dtime = gettime_hp()-dtime;
133 std::cout<<std::endl<< std::setw(30) << std::left << "Characteristics extraction: " << dtime/1000 << " s" <<std::endl;
135 IndexSampleSetType* indexSet = preProcess->GetIndexSet();
136 IndexSampleSetType* classSet = preProcess->GetClassSet();
137 IndexSampleSetType* weightsSet = preProcess->GetWeightsSet();
138 SpatialSampleSetType* spatialSet = preProcess->GetSpatialSet();
139 RangeSampleSetType* rangeSet = preProcess->GetRangeSet();
144 itkSTMS::itkSTMS_BlurringSTMS< IndexType, SpatialType, PixelType, ImageType2D >* stmsFilter
145 = new itkSTMS::itkSTMS_BlurringSTMS< IndexType, SpatialType, PixelType, ImageType2D >
146 (indexSet, classSet, weightsSet, spatialSet, rangeSet, params, preProcess->GetExperimentDescription());
148 stmsFilter->GenerateData();
150 dtime = gettime_hp()-dtime;
151 std::cout<<std::endl<< std::setw(30) << std::left << "STMS filtering: " << dtime/1000 << " s" <<std::endl;
156 itkSTMS::itkSTMS_TemporalSetToImageSequence< ImageType2D, ClassImageType2D >* postProcess
157 = new itkSTMS::itkSTMS_TemporalSetToImageSequence< ImageType2D, ClassImageType2D >(stmsFilter->GetClassMemory(),
158 stmsFilter->GetSpatialMemory(),
159 stmsFilter->GetRangeSet(),
161 preProcess->GetExperimentDescription());
163 postProcess->GenerateImageSequence();
164 if(preProcess->GetExperimentDescription()->outputCSV == "true" )
165 postProcess->GenerateCSVFile();
167 dtime = gettime_hp()-dtime;
168 std::cout<<std::endl<< std::setw(30) << std::left << "Image sequence saving: " << dtime/1000 << " s" <<std::endl;
179 typedef itk::Image< PixelType, 3 > ImageType3D;
180 typedef itk::Image< unsigned char, 3 > MaskImageType3D;
182 typedef itkSTMS::itkSTMS_ImageSequenceToTemporalSet< ImageType3D, MaskImageType3D >::IndexType IndexType;
183 typedef itkSTMS::itkSTMS_ImageSequenceToTemporalSet< ImageType3D, MaskImageType3D >::SpatialType SpatialType;
184 typedef itkSTMS::itkSTMS_ImageSequenceToTemporalSet< ImageType3D, MaskImageType3D >::IndexSampleSetType IndexSampleSetType;
185 typedef itkSTMS::itkSTMS_ImageSequenceToTemporalSet< ImageType3D, MaskImageType3D >::SpatialSampleSetType SpatialSampleSetType;
186 typedef itkSTMS::itkSTMS_ImageSequenceToTemporalSet< ImageType3D, MaskImageType3D >::RangeSampleSetType RangeSampleSetType;
191 itkSTMS::itkSTMS_ImageSequenceToTemporalSet< ImageType3D, MaskImageType3D >* preProcess
192 = new itkSTMS::itkSTMS_ImageSequenceToTemporalSet< ImageType3D, MaskImageType3D > ( params );
193 preProcess->GenerateDataSets();
195 dtime = gettime_hp()-dtime;
196 std::cout<<std::endl<< std::setw(30) << std::left << "Characteristics extraction: " << dtime/1000 << " s" <<std::endl;
198 IndexSampleSetType* indexSet = preProcess->GetIndexSet();
199 IndexSampleSetType* classSet = preProcess->GetClassSet();
200 IndexSampleSetType* weightsSet = preProcess->GetWeightsSet();
201 SpatialSampleSetType* spatialSet = preProcess->GetSpatialSet();
202 RangeSampleSetType* rangeSet = preProcess->GetRangeSet();
209 itkSTMS::itkSTMS_BlurringSTMS< IndexType, SpatialType, PixelType, ImageType3D >* stmsFilter
210 = new itkSTMS::itkSTMS_BlurringSTMS< IndexType, SpatialType, PixelType, ImageType3D >
211 (indexSet, classSet, weightsSet, spatialSet, rangeSet, params, preProcess->GetExperimentDescription());
213 stmsFilter->GenerateData();
215 dtime = gettime_hp()-dtime;
216 std::cout<<std::endl<< std::setw(30) << std::left << "STMS filtering: " << dtime/1000 << " s" <<std::endl;
221 itkSTMS::itkSTMS_TemporalSetToImageSequence< ImageType3D, MaskImageType3D >* postProcess
222 = new itkSTMS::itkSTMS_TemporalSetToImageSequence< ImageType3D, MaskImageType3D >(stmsFilter->GetClassMemory(),
223 stmsFilter->GetSpatialMemory(),
224 stmsFilter->GetRangeSet(),
226 preProcess->GetExperimentDescription());
228 postProcess->GenerateImageSequence();
229 if(preProcess->GetExperimentDescription()->outputCSV == "true" )
230 postProcess->GenerateCSVFile();
232 dtime = gettime_hp()-dtime;
233 std::cout<<std::endl<< std::setw(30) << std::left << "Image sequence saving: " << dtime/1000 << " s" <<std::endl;
247 std::cout << std::endl << "Image dimensionality should be equal to 2 or 3.";
248 std::exit( EXIT_FAILURE );