1 /*=========================================================================
2 Program: vv http://www.creatis.insa-lyon.fr/rio/vv
5 - University of LYON http://www.universite-lyon.fr/
6 - Léon Bérard cancer center http://www.centreleonberard.fr
7 - CREATIS CNRS laboratory http://www.creatis.insa-lyon.fr
9 This software is distributed WITHOUT ANY WARRANTY; without even
10 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
11 PURPOSE. See the copyright notices for more information.
13 It is distributed under dual licence
15 - BSD See included LICENSE.txt file
16 - CeCILL-B http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
17 ===========================================================================**/
18 #ifndef __clitkDeformationFieldStatisticsFilter_txx
19 #define __clitkDeformationFieldStatisticsFilter_txx
20 #include "clitkDeformationListStatisticsFilter.h"
26 //------------------------------------------------------
28 //------------------------------------------------------
29 template <class ListItemType>
31 DeformationListStatisticsFilter<ListItemType>::GetStatistics(const ListType& list, ValueType & mean, ValueType & sd, ValueType & max)
39 // loop over the list of displacements
40 for (unsigned int i=0;i<list.size();i++)
42 norm=list[i].GetNorm();
45 if (max<norm)max=norm;
58 //------------------------------------------------------
60 //------------------------------------------------------
61 template <class ListItemType>
63 DeformationListStatisticsFilter<ListItemType>::GetStatistics(const ListsType& list, ValueListType & mean, ValueListType & sd, ValueListType & max)
66 mean.resize(list.size());
67 sd.resize(list.size());
68 max.resize(list.size());
70 for (unsigned int i=0;i<list.size();i++)
72 // call function per list
73 GetStatistics(list[i], mean[i], sd[i], max[i]);
78 //------------------------------------------------------
79 // Magnitude AND General statistics for magnitude
80 //------------------------------------------------------
81 template <class ListItemType>
83 DeformationListStatisticsFilter<ListItemType>::GetStatistics(const ListsType& list, ValueType& mean, ValueType &sd, ValueType & max, ValueListType & meanList, ValueListType & sdList, ValueListType & maxList)
85 // Calculate statistics per list
86 GetStatistics(list, meanList, sdList, maxList);
94 for (unsigned int i=0;i<list.size();i++)
97 sd+=sdList[i]*sdList[i];
98 if(max<maxList[i])max=maxList[i];
108 //------------------------------------------------------
110 //------------------------------------------------------
111 template <class ListItemType>
113 DeformationListStatisticsFilter<ListItemType>::GetStatistics(const ListType& list, ListItemType & mean, ListItemType & sd, ListItemType & max)
116 ListItemType displacement;
117 mean.Fill(itk::NumericTraits<ValueType>::Zero);
118 sd.Fill(itk::NumericTraits<ValueType>::Zero);
119 max.Fill(itk::NumericTraits<ValueType>::Zero);
121 // Loop over the list of displacements
122 for (unsigned int i=0;i<list.size();i++)
124 displacement=list[i];
126 for (unsigned int dim=0; dim<list[0].Size(); dim++)
128 sd[dim]+=displacement[dim]*displacement[dim];
129 if (fabs(max[dim])<fabs(displacement[dim])) max[dim]=displacement[dim];
134 for (unsigned int dim=0; dim<list[0].Size(); dim++)
136 mean[dim]/=list.size();
137 sd[dim]/=list.size();
138 sd[dim]-=mean[dim]*mean[dim];
139 sd[dim]=sqrt(sd[dim]);
143 //------------------------------------------------------
144 // For multiple lists
145 //------------------------------------------------------
146 template <class ListItemType>
148 DeformationListStatisticsFilter<ListItemType>::GetStatistics(const ListsType& list, ListType & mean, ListType & sd, ListType & max)
150 mean.resize(list.size());
151 sd.resize(list.size());
152 max.resize(list.size());
154 for (unsigned int i=0;i<list.size();i++)
156 // call function per list
157 GetStatistics(list[i], mean[i], sd[i], max[i]);
163 //------------------------------------------------------
164 // Magnitude AND General statistics per component
165 //------------------------------------------------------
166 template <class ListItemType>
168 DeformationListStatisticsFilter<ListItemType>::GetStatistics(const ListsType& list, ListItemType& mean, ListItemType &sd, ListItemType & max, ListType & meanList, ListType & sdList, ListType & maxList)
170 // Calculate statistics par list
171 GetStatistics(list, meanList, sdList, maxList);
174 mean.Fill(itk::NumericTraits<ValueType>::Zero);
175 sd.Fill(itk::NumericTraits<ValueType>::Zero);
176 max.Fill(itk::NumericTraits<ValueType>::Zero);
177 ListItemType displacement;
180 for (unsigned int i=0;i<list.size();i++)
185 for (unsigned int dim=0; dim<mean.Size(); dim++)
187 sd[dim]+=sdList[i][dim]*sdList[i][dim];
188 if (fabs(max[dim])<fabs(maxList[i][dim])) max[dim]=maxList[i][dim];
193 for (unsigned int dim=0; dim<mean.Size(); dim++)
195 mean[dim]/=list.size();
196 sd[dim]/=list.size();
197 //sd[dim]-=mean[dim]*mean[dim];
198 sd[dim]=sqrt(sd[dim]);