Medical Imaging Interaction Toolkit  2026.06.00
Medical Imaging Interaction Toolkit
mitkAbstractClassifier.h
Go to the documentation of this file.
1 /*============================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center (DKFZ)
6 All rights reserved.
7 
8 Use of this source code is governed by a 3-clause BSD license that can be
9 found in the LICENSE file.
10 
11 ============================================================================*/
12 
13 
14 #ifndef mitkAbstractClassifier_h
15 #define mitkAbstractClassifier_h
16 
17 #include <MitkCLCoreExports.h>
18 
19 
20 #include <mitkBaseData.h>
21 
22 // Eigen
23 #include <itkeigen/Eigen/Dense>
24 
25 // STD Includes
26 
27 // MITK includes
29 
30 namespace mitk
31 {
50 {
51 public:
52 
54 
61  virtual void Train(const Eigen::MatrixXd &X, const Eigen::MatrixXi &Y) = 0;
62 
69  virtual Eigen::MatrixXi Predict(const Eigen::MatrixXd &X) = 0;
70 
76  Eigen::MatrixXi & GetLabels()
77  {
78  return m_OutLabel;
79  }
80 
81 protected:
82  Eigen::MatrixXi m_OutLabel;
83 
84 
85 public:
86  // * --------------- *
87  // PointWiseWeight
88  // * --------------- *
89 
95  virtual bool SupportsPointWiseWeight() = 0;
96 
102  virtual Eigen::MatrixXd & GetPointWiseWeight()
103  {
104  return m_PointWiseWeight;
105  }
106 
112  virtual void SetPointWiseWeight(const Eigen::MatrixXd& W)
113  {
114  this->m_PointWiseWeight = W;
115  }
116 
122  virtual void UsePointWiseWeight(bool value)
123  {
124  this->m_IsUsingPointWiseWeight = value;
125  }
126 
132  virtual bool IsUsingPointWiseWeight()
133  {
134  return this->m_IsUsingPointWiseWeight;
135  }
136 
137 protected:
138  Eigen::MatrixXd m_PointWiseWeight;
140 
141  // * --------------- *
142  // PointWiseProbabilities
143  // * --------------- *
144 
145 public:
151  virtual bool SupportsPointWiseProbability() = 0;
152 
158  virtual Eigen::MatrixXd & GetPointWiseProbabilities()
159  {
160  return m_OutProbability;
161  }
162 
168  virtual void UsePointWiseProbability(bool value)
169  {
170  m_IsUsingPointWiseProbability = value;
171  }
172 
179  {
180  return m_IsUsingPointWiseProbability;
181  }
182 
183 protected:
184  Eigen::MatrixXd m_OutProbability;
186 
187 private:
188  void MethodForBuild();
189 
190 public:
191 
200  void SetNthItems(const char *val, unsigned int idx);
201 
208  std::string GetNthItems(unsigned int idx) const;
209 
215  void SetItemList(std::vector<std::string> list);
216 
222  std::vector<std::string> GetItemList() const;
223 
224 #ifndef DOXYGEN_SKIP
225 
227  bool RequestedRegionIsOutsideOfTheBufferedRegion() override{return true;}
228  bool VerifyRequestedRegion() override{return false;}
229 
230  void SetRequestedRegion(const itk::DataObject* /*data*/) override{}
231 
232 
233  // Override
234  bool IsEmpty() const override
235  {
236  if(IsInitialized() == false)
237  return true;
238  const TimeGeometry* timeGeometry = const_cast<AbstractClassifier*>(this)->GetUpdatedTimeGeometry();
239  if(timeGeometry == nullptr)
240  return true;
241  return false;
242  }
243 
244 #endif // Skip Doxygen
245 
246 };
247 }
248 
249 #endif
#define MITKCLCORE_EXPORT
Abstract base class for machine learning classifiers.
virtual void Train(const Eigen::MatrixXd &X, const Eigen::MatrixXi &Y)=0
Train the classifier on a labeled dataset.
Eigen::MatrixXi & GetLabels()
Get the predicted label matrix from the last prediction.
void SetItemList(std::vector< std::string > list)
Replace the entire item list with the given vector of strings.
std::string GetNthItems(unsigned int idx) const
Get the item string at the given index from the property-based item list.
bool VerifyRequestedRegion() override
Verify that the RequestedRegion is within the LargestPossibleRegion.
virtual bool IsUsingPointWiseWeight()
Query whether per-sample weighting is currently enabled.
virtual Eigen::MatrixXd & GetPointWiseWeight()
Get the per-sample weight matrix.
bool RequestedRegionIsOutsideOfTheBufferedRegion() override
Determine whether the RequestedRegion is outside of the BufferedRegion.
virtual bool SupportsPointWiseProbability()=0
Query whether this classifier supports per-sample class probability output.
virtual bool IsUsingPointWiseProbability()
Query whether per-sample class probability output is currently enabled.
virtual Eigen::MatrixXd & GetPointWiseProbabilities()
Get the per-sample class probability matrix from the last prediction.
mitkClassMacro(AbstractClassifier, BaseData)
virtual bool SupportsPointWiseWeight()=0
Query whether this classifier supports per-sample weighting.
void SetRequestedRegionToLargestPossibleRegion() override
Set the RequestedRegion to the LargestPossibleRegion.
bool IsEmpty() const override
Check whether the object contains data at any time step.
virtual void UsePointWiseWeight(bool value)
Enable or disable per-sample weighting during training.
void SetNthItems(const char *val, unsigned int idx)
Set an item in the property-based item list at the given index.
virtual Eigen::MatrixXi Predict(const Eigen::MatrixXd &X)=0
Predict class labels for the given input samples.
virtual void SetPointWiseWeight(const Eigen::MatrixXd &W)
Set the per-sample weight matrix.
std::vector< std::string > GetItemList() const
Retrieve all items from the property-based item list.
virtual void UsePointWiseProbability(bool value)
Enable or disable per-sample class probability computation.
void SetRequestedRegion(const itk::DataObject *) override
Set the requested region from this data object to match the requested region of the data object passe...
Base class of all data objects.
Definition: mitkBaseData.h:60
Find image slices visible on a given plane.