20 #include <vigra/matrix.hxx> 21 #include <vigra/regression.hxx> 22 #include <vigra/quadprog.hxx> 34 algorithmName = inputAlgorithmName;
39 double value = double(weight) / 100.0;
40 weightsvec.push_back(value);
44 Eigen::Matrix<float, Eigen::Dynamic, Eigen::Dynamic> endmemberMatrix, Eigen::VectorXf inputVector)
46 unsigned int numberOfWavelengths = endmemberMatrix.rows();
47 unsigned int numberOfChromophores = endmemberMatrix.cols();
50 std::vector<double> aData;
51 std::vector<double> bData;
52 for (
unsigned int i = 0; i < numberOfWavelengths; ++i)
54 bData.push_back((
double)inputVector(i));
55 for (
unsigned int j = 0; j < numberOfChromophores; ++j)
56 aData.push_back((
double)endmemberMatrix(i, j));
58 const double* aDat = aData.data();
59 const double* bDat = bData.data();
61 vigra::Matrix<double> A(vigra::Shape2(numberOfWavelengths, numberOfChromophores), aDat);
62 vigra::Matrix<double> b(vigra::Shape2(numberOfWavelengths, 1), bDat);
63 vigra::Matrix<double> x(vigra::Shape2(numberOfChromophores, 1));
65 if (mitk::pa::SpectralUnmixingFilterVigra::VigraAlgortihmType::LARS == algorithmName)
66 nonnegativeLeastSquares(A, b, x);
68 else if (mitk::pa::SpectralUnmixingFilterVigra::VigraAlgortihmType::GOLDFARB == algorithmName)
70 vigra::linalg::Matrix<double> eye(vigra::linalg::identityMatrix<double>(numberOfChromophores)),
71 zeros(vigra::Shape2(numberOfChromophores, 1)),
73 U = vigra::linalg::transpose(A)*A,
75 v = vigra::linalg::transpose(A)*b;
77 quadraticProgramming(U, -v, empty, empty, eye, zeros, x);
80 else if (mitk::pa::SpectralUnmixingFilterVigra::VigraAlgortihmType::WEIGHTED == algorithmName)
82 if (weightsvec.size() != numberOfWavelengths)
83 mitkThrow() <<
"Number of weights and wavelengths doesn't match! OR Invalid weight!";
84 const double* weightsdat = weightsvec.data();
85 vigra::Matrix<double> weigths(vigra::Shape2(numberOfWavelengths, 1), weightsdat);
86 vigra::linalg::weightedLeastSquares(A, b, weigths, x);
89 else if (mitk::pa::SpectralUnmixingFilterVigra::VigraAlgortihmType::LS == algorithmName)
93 mitkThrow() <<
"404 VIGRA ALGORITHM NOT FOUND";
95 Eigen::VectorXf resultVector(numberOfChromophores);
96 for (
unsigned int k = 0;
k < numberOfChromophores; ++
k)
97 resultVector[
k] = (
float)x(
k, 0);
SpectralUnmixingFilterVigra()
Eigen::VectorXf SpectralUnmixingAlgorithm(Eigen::Matrix< float, Eigen::Dynamic, Eigen::Dynamic > EndmemberMatrix, Eigen::VectorXf inputVector) override
overrides the baseclass method with a mehtod to calculate the spectral unmixing result vector...
VigraAlgortihmType
Contains all implemented Vigra algorithms for spectral unmixing. For detailed information of the algo...
~SpectralUnmixingFilterVigra() override
void SetAlgorithm(VigraAlgortihmType inputAlgorithmName)
Takes a mitk::pa::SpectralUnmixingFilterVigra::VigraAlgortihmType and fix it for usage at the "Spectr...
void AddWeight(unsigned int weight)
AddWeight takes integers and writes them at the end of the weightsvec vector. The first call of the m...