Medical Imaging Interaction Toolkit  2018.4.99-65942676
Medical Imaging Interaction Toolkit
mitkPASpectralUnmixingFilterBase.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 #ifndef MITKPHOTOACOUSTICSPECTRALUNMIXINGFILTERBASE_H
14 #define MITKPHOTOACOUSTICSPECTRALUNMIXINGFILTERBASE_H
15 
16 #include "mitkImageToImageFilter.h"
18 
19 //Includes for smart pointer usage
20 #include "mitkCommon.h"
21 #include "itkLightObject.h"
22 
23 // Includes for AddEnmemberMatrix
25 #include <eigen3/Eigen/Dense>
26 
27 namespace mitk {
28  namespace pa {
64  {
65  public:
67 
75  void AddChromophore(mitk::pa::PropertyCalculator::ChromophoreType chromophore);
76 
82  void AddWavelength(int wavelength);
83 
84  /*
85  * \brief Verbose gives more information to the console. Default value is false.
86  * @param verbose is the boolian to activate the MITK_INFO logged to the console
87  */
88  virtual void Verbose(bool verbose);
89 
95  virtual void AddOutputs(unsigned int outputs);
96 
97  /*
98  * \brief RelativeError returns a image which compare the L2 norm of the input vector with the unmixing result
99  * @param relativeError is the boolian to activate this tool
100  */
101  virtual void RelativeError(bool relativeError);
102 
107  virtual void AddRelativeErrorSettings(int value);
108 
109  ofstream myfile; // just for testing purposes; has to be removeed
110 
111  protected:
116  ~SpectralUnmixingFilterBase() override;
117 
126  virtual Eigen::VectorXf SpectralUnmixingAlgorithm(Eigen::Matrix<float, Eigen::Dynamic, Eigen::Dynamic> endmemberMatrix,
127  Eigen::VectorXf inputVector) = 0;
128 
129  bool m_Verbose = false;
130  bool m_RelativeError = false;
131 
132  std::vector<mitk::pa::PropertyCalculator::ChromophoreType> m_Chromophore;
133  std::vector<int> m_Wavelength;
134  std::vector<int> m_RelativeErrorSettings;
135 
136  private:
137  /*
138  * \brief Initialized output images with the same XY-plane size like the input image and total size in z-direction equals number of sequences.
139  * The pixel type is set to float.
140  * @param totalNumberOfSequences = (unsigned int) (numberOfInputImages / numberOfWavelength) >= 1
141  */
142  virtual void InitializeOutputs(unsigned int totalNumberOfSequences);
143 
144  /*
145  * \brief Checks if there are a suitable amount of wavelengths and if the input image consists of floats.
146  * @param input pointer on the MITK input image
147  * @throws if there are more wavelength then images
148  * @throws if there are more chromophores then wavelengths
149  * @throws if the pixel type is not float 32
150  * @throws if no chromophores or wavelengths selected as input
151  * @throws if the number of indexed outputs does'nt fit to the expected number
152  */
153  virtual void CheckPreConditions(mitk::Image::Pointer input);
154 
155  /*
156  * \brief Inherit from the "ImageToImageFilter" Superclass. Herain it calls InitializeOutputs, CalculateEndmemberMatrix and
157  * CheckPreConditions methods and enables pixelwise access to do spectral unmixing with the "SpectralUnmixingAlgorithm"
158  * method. In the end the method writes the results into the new MITK output images.
159  */
160  void GenerateData() override;
161 
162  /*
163  * \brief Creats a Matrix with number of chromophores colums and number of wavelengths rows so matrix element (i,j) contains
164  * the absorbtion of chromophore j @ wavelength i. The absorbtion values are taken from the "PropertyElement" method.
165  * @param m_Chromophore is a vector of "PropertyCalculator::ChromophoreType" containing all selected chromophores for the unmixing
166  * @param m_Wavelength is a vector of integers containing all wavelengths of one sequence
167  */
168  virtual Eigen::Matrix<float, Eigen::Dynamic, Eigen::Dynamic> CalculateEndmemberMatrix(
169  std::vector<mitk::pa::PropertyCalculator::ChromophoreType> m_Chromophore, std::vector<int> m_Wavelength);
170 
171  /*
172  * \brief "PropertyElement" is the tool to access the absorbtion values out of the database using mitk::pa::PropertyCalculator::GetAbsorptionForWavelengt
173  * and checks if the requested wavelength is part of the database (not zero values). The "ONEENDMEMBER" is a pseudo absorber with static absorbtion 1
174  * at every wavelength and is therefor not part of the database. If this one is the selected chromophore the return value is 1 for every wavelength.
175  * @param wavelength has to be integer between 300 and 1000 nm
176  * @param chromophore has to be a mitk::pa::PropertyCalculator::ChromophoreType
177  * @throws if mitk::pa::PropertyCalculator::GetAbsorptionForWavelengt returns 0, because this means that the delivered wavelength is not in the database.
178  */
179  virtual float PropertyElement(mitk::pa::PropertyCalculator::ChromophoreType, int wavelength);
180 
181  /*
182  * \brief calculates the relative error between the input image and the unmixing result in the L2 norm
183  * @param endmemberMatrix is a Eigen matrix containing the endmember information
184  * @param inputVector is a Eigen vector containing the multispectral information of one pixel
185  * @param resultVector is a Eigen vector containing the spectral unmmixing result
186  */
187  float CalculateRelativeError(Eigen::Matrix<float, Eigen::Dynamic, Eigen::Dynamic> endmemberMatrix,
188  Eigen::VectorXf inputVector, Eigen::VectorXf resultVector);
189 
190  PropertyCalculator::Pointer m_PropertyCalculatorEigen;
191  };
192  }
193 }
194 #endif // MITKPHOTOACOUSTICSPECTRALUNMIXINGFILTERBASE_
The spectral unmixing filter base is designed as superclass for several spectral unmixing filter eg...
DataCollection - Class to facilitate loading/accessing structured data.
std::vector< mitk::pa::PropertyCalculator::ChromophoreType > m_Chromophore
#define mitkClassMacro(className, SuperClassName)
Definition: mitkCommon.h:40
Superclass of all classes having one or more Images as input and generating Images as output...
#define MITKPHOTOACOUSTICSLIB_EXPORT