21 #ifndef _MIRTKEMCLASSIFICATIONNEO_H 22 #define _MIRTKEMCLASSIFICATIONNEO_H 24 #include "mirtk/Image.h" 25 #include "mirtk/Object.h" 26 #include "mirtk/HashProbabilisticAtlas.h" 27 #include "mirtk/Gaussian.h" 28 #include "mirtk/Histogram1D.h" 29 #include "mirtk/MeanShift.h" 38 class EMBase :
public Object
42 typedef GenericImage<int> IntegerImage;
57 HashProbabilisticAtlas _output;
60 HashProbabilisticAtlas _pv_output;
63 HashProbabilisticAtlas _atlas;
66 IntegerImage _segmentation;
69 RealImage _postpenalty;
73 int _number_of_tissues;
76 int _number_of_voxels;
102 bool _posteriors_set;
112 template <
class ImageType>
113 EMBase(
int noTissues, ImageType **atlas, ImageType *background);
116 template <
class ImageType>
117 EMBase(
int noTissues, ImageType **atlas);
120 template <
class ImageType>
121 EMBase(
int noTissues, ImageType **atlas, ImageType **initposteriors ) ;
127 template <
class ImageType>
128 void addProbabilityMap(ImageType image);
131 void addBackground();
132 template <
class ImageType>
133 void addBackground(ImageType image);
136 void NormalizeAtlas();
139 virtual void Initialise();
142 void InitialiseParameters();
145 virtual void InitialiseGMM();
148 void InitialiseGMMParameters(
int n,
double *m,
double *s,
double *c);
151 virtual const char* NameOfClass()
const;
154 virtual void EStep();
157 virtual void MStep();
160 virtual void EStepGMM(
bool uniform_prior =
false);
163 virtual void MStepGMM(
bool uniform_prior =
false);
166 virtual void MStepVarGMM(
bool uniform_prior =
false);
169 virtual double LogLikelihood();
172 virtual double LogLikelihoodGMM();
175 virtual void GetProbMap(
int i,RealImage& image);
178 virtual void Print();
181 virtual void PrintGMM();
184 virtual void WStep();
187 virtual void SetInput(
const RealImage &);
190 void SetMask(ByteImage &mask);
193 virtual void SetPadding(RealPixel);
196 void setPostPenalty(RealImage &postpenalty);
198 void setSuperlabels(
int *superlabels);
201 virtual double Iterate(
int iteration);
204 virtual double IterateGMM(
int iteration,
bool equal_var =
false,
bool uniform_prior =
false);
207 virtual void GetProportions(
double *);
210 virtual void ConstructSegmentation(IntegerImage &);
212 virtual void ConstructSegmentation();
215 void WriteProbMap(
int i,
const char *filename);
217 void WriteGaussianParameters(
const char *file_name,
int flag = 0);
219 void WriteEstimate(
const char *filename);
221 void WriteWeights(
const char *filename);
223 void WriteInput(
const char *filename);
225 void WriteSegmentation(
const char *filename);
229 double PointLogLikelihoodGMM(
double x);
235 virtual void GetMean(
double *);
237 virtual void GetVariance(
double *);
240 void InitialiseGMMParameters(
int n);
246 inline void EMBase::addBackground(){
247 _atlas.AddBackground();
248 _has_background =
true;
249 _number_of_tissues = _atlas.GetNumberOfMaps();
252 template <
class ImageType>
253 inline void EMBase::addBackground(ImageType background){
254 _atlas.AddBackground(background);
255 _has_background =
true;
256 _number_of_tissues = _atlas.GetNumberOfMaps();
260 template <
class ImageType>
261 inline void EMBase::addProbabilityMap(ImageType image){
262 _atlas.AddImage(image);
263 _number_of_tissues = _atlas.GetNumberOfMaps();
266 inline void EMBase::NormalizeAtlas(){
267 _atlas.NormalizeAtlas();
270 inline void EMBase::SetPadding(RealPixel padding)
275 inline void EMBase::WriteEstimate(
const char *filename)
277 _estimate.Write(filename);
280 inline void EMBase::WriteInput(
const char *filename)
282 _input.Write(filename);
285 inline void EMBase::WriteSegmentation(
const char *filename)
287 _segmentation.Write(filename);
290 inline const char* EMBase::NameOfClass()
const {
return "EMBase"; }
std::ostream & Print(std::ostream &os, T value)
Print single argument to output stream.