diff --git a/Modules/PhotoacousticsLib/include/mitkPALinearSpectralUnmixingFilter.h b/Modules/PhotoacousticsLib/include/mitkPALinearSpectralUnmixingFilter.h index d4b9c6d2a0..a2c3c9cb81 100644 --- a/Modules/PhotoacousticsLib/include/mitkPALinearSpectralUnmixingFilter.h +++ b/Modules/PhotoacousticsLib/include/mitkPALinearSpectralUnmixingFilter.h @@ -1,58 +1,103 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #ifndef MITKLINEARPHOTOACOUSTICSPECTRALUNMIXINGFILTER_H #define MITKLINEARPHOTOACOUSTICSPECTRALUNMIXINGFILTER_H #include #include namespace mitk { namespace pa { + /** + * \brief This filter is subclass of the spectral unmixing filter base. All algorithms in this class are + * based on the Eigen open source c++ library. It takes a multispectral pixel as input and returns a vector + * with the unmixing result. + * + * Input: + * - endmemberMatrix Eigen Matrix with number of chromophores colums and number of wavelengths rows so matrix element (i,j) contains + * the absorbtion of chromophore j @ wavelength i taken from the database by PropertyElement method. + * - inputVector Eigen Vector containing values of one pixel of XY-plane image with number of wavelength rows (z-dimension of a sequenece) + * so the pixelvalue of the first wavelength is stored in inputVector[0] and so on. + * + * Output: + * - Eigen vector with unmixing result of one multispectral pixel. The ith element of the vector corresponds to the ith entry of the + * m_Chromophore vector. + * + * Algorithms (see AlgortihmType enum): + * - HOUSEHOLDERQR computes the solution by QR decomposition + * - COLPIVHOUSEHOLDERQR computes the solution by QR decomposition + * - FULLPIVHOUSEHOLDERQR computes the solution by QR decomposition + * - LDLT computes the solution by Cholesky decomposition + * - LLT computes the solution by Cholesky decomposition + * - JACOBISVD computes the solution by singular value decomposition uses least square solver + * + * Possible exceptions: + * - "algorithm not working": doesn't work now (2018/06/19) + * - "404 VIGRA ALGORITHM NOT FOUND": Algorithm not implemented + */ + class MITKPHOTOACOUSTICSLIB_EXPORT LinearSpectralUnmixingFilter : public SpectralUnmixingFilterBase { public: mitkClassMacro(LinearSpectralUnmixingFilter, SpectralUnmixingFilterBase) itkFactorylessNewMacro(Self) + /** + * \brief Contains all implemented Eigen algorithms for spectral unmixing. For detailed information of the algorithms look at the + * mitkPALinearSpectralUnmixingFilter.h documentation (section Algorithms). + */ enum AlgortihmType { - householderQr, - ldlt, - llt, - colPivHouseholderQr, - jacobiSvd, - fullPivLu, - fullPivHouseholderQr, - test + HOUSEHOLDERQR, + LDLT, + LLT, + COLPIVHOUSEHOLDERQR, + JACOBISVD, + FULLPIVLU, + FULLPIVHOUSEHOLDERQR }; - void mitk::pa::LinearSpectralUnmixingFilter::SetAlgorithm(AlgortihmType SetAlgorithmIndex); + /** + * \brief Takes a mitk::pa::LinearSpectralUnmixingFilter::AlgortihmType and fix it for usage at the "SpectralUnmixingAlgorithm" method. + * @param algorithmName has to be a mitk::pa::LinearSpectralUnmixingFilter::AlgortihmType + */ + void mitk::pa::LinearSpectralUnmixingFilter::SetAlgorithm(AlgortihmType inputAlgorithmName); protected: LinearSpectralUnmixingFilter(); virtual ~LinearSpectralUnmixingFilter(); + /** + * \brief overrides the baseclass method with a mehtod to calculate the spectral unmixing result vector. Herain the class performs the + * algorithm set by the "SetAlgorithm" method and writes the result into a Eigen vector which is the return value. + * @param endmemberMatrix Matrix with number of chromophores colums and number of wavelengths rows so matrix element (i,j) contains + * the absorbtion of chromophore j @ wavelength i taken from the database by PropertyElement method. + * @param inputVector Vector containing values of one pixel of XY-plane image with number of wavelength rows (z-dimension of a sequenece) + * so the pixelvalue of the first wavelength is stored in inputVector[0] and so on. + * @throw if the algorithmName is not a member of the enum VigraAlgortihmType + * @throw if one chooses the ldlt solver which doens't work yet + */ virtual Eigen::VectorXf SpectralUnmixingAlgorithm(Eigen::Matrix EndmemberMatrix, Eigen::VectorXf inputVector) override; private: - mitk::pa::LinearSpectralUnmixingFilter::AlgortihmType algorithmIndex; + mitk::pa::LinearSpectralUnmixingFilter::AlgortihmType algorithmName; }; } } #endif // MITKLINEARPHOTOACOUSTICSPECTRALUNMIXINGFILTER_H diff --git a/Modules/PhotoacousticsLib/include/mitkPASpectralUnmixingFilterVigra.h b/Modules/PhotoacousticsLib/include/mitkPASpectralUnmixingFilterVigra.h index 6e10593542..bce89841f1 100644 --- a/Modules/PhotoacousticsLib/include/mitkPASpectralUnmixingFilterVigra.h +++ b/Modules/PhotoacousticsLib/include/mitkPASpectralUnmixingFilterVigra.h @@ -1,108 +1,108 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #ifndef MITKPHOTOACOUSTICSPECTRALUNMIXINGFILTERVIGRA_H #define MITKPHOTOACOUSTICSPECTRALUNMIXINGFILTERVIGRA_H #include #include #include namespace mitk { namespace pa { /** * \brief This filter is subclass of the spectral unmixing filter base. All algorithms in this class are * based on the vigra open source c++ library. It takes a multispectral pixel as input and returns a vector * with the unmixing result. * * Input: - * - endmemberMatrix Matrix with number of chromophores colums and number of wavelengths rows so matrix element (i,j) contains + * - endmemberMatrix Eigen Matrix with number of chromophores colums and number of wavelengths rows so matrix element (i,j) contains * the absorbtion of chromophore j @ wavelength i taken from the database by PropertyElement method. - * - inputVector Vector containing values of one pixel of XY-plane image with number of wavelength rows (z-dimension of a sequenece) + * - inputVector Eigen Vector containing values of one pixel of XY-plane image with number of wavelength rows (z-dimension of a sequenece) * so the pixelvalue of the first wavelength is stored in inputVector[0] and so on. * * Output: * - Eigen vector with unmixing result of one multispectral pixel. The ith element of the vector corresponds to the ith entry of the * m_Chromophore vector. * * Algorithms (see VigraAlgortihmType enum): * - LARS algorithm minimizes (A*x-b)^2 s.t. x>=0 using least angle regression * - GOLDFARB minimizes (A*x-b)^2 s.t. x>=0 using the Goldfarb-Idnani algorithm * - WEIGHTED minimizes transpose(A*x-b)*diag(weights)*(A*x-b) using QR decomposition * - LS minimizes (A*x-b)^2 using QR decomposition * * Possible exceptions: * - "404 VIGRA ALGORITHM NOT FOUND": Algorithm not implemented */ class MITKPHOTOACOUSTICSLIB_EXPORT SpectralUnmixingFilterVigra : public SpectralUnmixingFilterBase { public: mitkClassMacro(SpectralUnmixingFilterVigra, SpectralUnmixingFilterBase) itkFactorylessNewMacro(Self) /** * \brief Contains all implemented Vigra algorithms for spectral unmixing. For detailed information of the algorithms look at the * mitkPASpectralUnmixingFilterVigra.h documentation (section Algorithms). */ enum VigraAlgortihmType { LARS, GOLDFARB, WEIGHTED, LS }; /** * \brief AddWeight takes integers and writes them at the end of the weightsvec vector. The first call of the method then * corresponds to the first input image/wavelength and so on. * @param weight is a percentage (integer) between 1 and 100 */ void AddWeight(unsigned int weight); /** * \brief Takes a mitk::pa::SpectralUnmixingFilterVigra::VigraAlgortihmType and fix it for usage at the "SpectralUnmixingAlgorithm" * method. * @param algorithmName has to be a mitk::pa::SpectralUnmixingFilterVigra::VigraAlgortihmType */ - void mitk::pa::SpectralUnmixingFilterVigra::SetAlgorithm(VigraAlgortihmType algorithmName); + void mitk::pa::SpectralUnmixingFilterVigra::SetAlgorithm(VigraAlgortihmType inputAlgorithmName); protected: SpectralUnmixingFilterVigra(); virtual ~SpectralUnmixingFilterVigra(); /** * \brief overrides the baseclass method with a mehtod to calculate the spectral unmixing result vector. Herain it first converts the * Eigen inputs to the Vigra class. Afterwards the class performs the algorithm set by the "SetAlgorithm" method and writes the result * into a Eigen vector which is the return value. * @param endmemberMatrix Matrix with number of chromophores colums and number of wavelengths rows so matrix element (i,j) contains * the absorbtion of chromophore j @ wavelength i taken from the database by PropertyElement method. * @param inputVector Vector containing values of one pixel of XY-plane image with number of wavelength rows (z-dimension of a sequenece) * so the pixelvalue of the first wavelength is stored in inputVector[0] and so on. * @throw if the algorithmName is not a member of the enum VigraAlgortihmType */ virtual Eigen::VectorXf SpectralUnmixingAlgorithm(Eigen::Matrix EndmemberMatrix, Eigen::VectorXf inputVector) override; private: std::vector weightsvec; mitk::pa::SpectralUnmixingFilterVigra::VigraAlgortihmType algorithmName; }; } } #endif // MITKPHOTOACOUSTICSPECTRALUNMIXINGFILTERVIGRA_H diff --git a/Modules/PhotoacousticsLib/src/SUFilter/mitkPALinearSpectralUnmixingFilter.cpp b/Modules/PhotoacousticsLib/src/SUFilter/mitkPALinearSpectralUnmixingFilter.cpp index 4b892e7a7e..e99bffa27a 100644 --- a/Modules/PhotoacousticsLib/src/SUFilter/mitkPALinearSpectralUnmixingFilter.cpp +++ b/Modules/PhotoacousticsLib/src/SUFilter/mitkPALinearSpectralUnmixingFilter.cpp @@ -1,84 +1,78 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #include "mitkPALinearSpectralUnmixingFilter.h" // Testing algorithms #include // ImageAccessor #include #include mitk::pa::LinearSpectralUnmixingFilter::LinearSpectralUnmixingFilter() { } mitk::pa::LinearSpectralUnmixingFilter::~LinearSpectralUnmixingFilter() { } -void mitk::pa::LinearSpectralUnmixingFilter::SetAlgorithm(mitk::pa::LinearSpectralUnmixingFilter::AlgortihmType SetAlgorithmIndex) +void mitk::pa::LinearSpectralUnmixingFilter::SetAlgorithm(mitk::pa::LinearSpectralUnmixingFilter::AlgortihmType inputAlgorithmName) { - algorithmIndex = SetAlgorithmIndex; + algorithmName = inputAlgorithmName; } Eigen::VectorXf mitk::pa::LinearSpectralUnmixingFilter::SpectralUnmixingAlgorithm( Eigen::Matrix EndmemberMatrix, Eigen::VectorXf inputVector) { Eigen::VectorXf resultVector; - if (mitk::pa::LinearSpectralUnmixingFilter::AlgortihmType::colPivHouseholderQr == algorithmIndex) - resultVector = EndmemberMatrix.colPivHouseholderQr().solve(inputVector); - - if (mitk::pa::LinearSpectralUnmixingFilter::AlgortihmType::llt == algorithmIndex) - resultVector = EndmemberMatrix.llt().solve(inputVector); - - if (mitk::pa::LinearSpectralUnmixingFilter::AlgortihmType::householderQr == algorithmIndex) + if (mitk::pa::LinearSpectralUnmixingFilter::AlgortihmType::HOUSEHOLDERQR == algorithmName) resultVector = EndmemberMatrix.householderQr().solve(inputVector); - if (mitk::pa::LinearSpectralUnmixingFilter::AlgortihmType::ldlt == algorithmIndex) + else if (mitk::pa::LinearSpectralUnmixingFilter::AlgortihmType::LDLT == algorithmName) { mitkThrow() << "algorithm not working"; resultVector = EndmemberMatrix.ldlt().solve(inputVector); } - if (mitk::pa::LinearSpectralUnmixingFilter::AlgortihmType::jacobiSvd == algorithmIndex) + else if (mitk::pa::LinearSpectralUnmixingFilter::AlgortihmType::LLT == algorithmName) + resultVector = EndmemberMatrix.llt().solve(inputVector); + + else if (mitk::pa::LinearSpectralUnmixingFilter::AlgortihmType::COLPIVHOUSEHOLDERQR == algorithmName) + resultVector = EndmemberMatrix.colPivHouseholderQr().solve(inputVector); + + else if (mitk::pa::LinearSpectralUnmixingFilter::AlgortihmType::JACOBISVD == algorithmName) resultVector = EndmemberMatrix.jacobiSvd(Eigen::ComputeFullU | Eigen::ComputeFullV).solve(inputVector); - if (mitk::pa::LinearSpectralUnmixingFilter::AlgortihmType::fullPivLu == algorithmIndex) + else if (mitk::pa::LinearSpectralUnmixingFilter::AlgortihmType::FULLPIVLU == algorithmName) resultVector = EndmemberMatrix.fullPivLu().solve(inputVector); - if (mitk::pa::LinearSpectralUnmixingFilter::AlgortihmType::householderQr == algorithmIndex) - resultVector = EndmemberMatrix.householderQr().solve(inputVector); - - if (mitk::pa::LinearSpectralUnmixingFilter::AlgortihmType::fullPivHouseholderQr == algorithmIndex) + else if (mitk::pa::LinearSpectralUnmixingFilter::AlgortihmType::FULLPIVHOUSEHOLDERQR == algorithmName) resultVector = EndmemberMatrix.fullPivHouseholderQr().solve(inputVector); - - if (mitk::pa::LinearSpectralUnmixingFilter::AlgortihmType::test == algorithmIndex) - { - mitkThrow() << "404 NO ALGORITHM IMPLEMENTED"; - } + else + mitkThrow() << "404 VIGRA ALGORITHM NOT FOUND"; /*double relativeError = (EndmemberMatrix*resultVector - inputVector).norm() / inputVector.norm(); // norm() is L2 norm MITK_INFO << "relativ error: " << relativeError; float accuracyLevel = .1; bool resultIsApprox = inputVector.isApprox(EndmemberMatrix*resultVector, accuracyLevel); MITK_INFO << "IS APPROX RESULT: " << resultIsApprox;*/ //MITK_INFO << "Result vector: " << resultVector; //++++++++++++++++++Maybe add this as additional ouptu image++++++++++++++++++++++ return resultVector; } diff --git a/Modules/PhotoacousticsLib/src/SUFilter/mitkPASpectralUnmixingFilterVigra.cpp b/Modules/PhotoacousticsLib/src/SUFilter/mitkPASpectralUnmixingFilterVigra.cpp index 547200f65d..1add393c1a 100644 --- a/Modules/PhotoacousticsLib/src/SUFilter/mitkPASpectralUnmixingFilterVigra.cpp +++ b/Modules/PhotoacousticsLib/src/SUFilter/mitkPASpectralUnmixingFilterVigra.cpp @@ -1,102 +1,102 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #include "mitkPASpectralUnmixingFilterVigra.h" // ImageAccessor #include #include //vigra #include #include #include mitk::pa::SpectralUnmixingFilterVigra::SpectralUnmixingFilterVigra() { } mitk::pa::SpectralUnmixingFilterVigra::~SpectralUnmixingFilterVigra() { } -void mitk::pa::SpectralUnmixingFilterVigra::SetAlgorithm(mitk::pa::SpectralUnmixingFilterVigra::VigraAlgortihmType algorithmName) +void mitk::pa::SpectralUnmixingFilterVigra::SetAlgorithm(mitk::pa::SpectralUnmixingFilterVigra::VigraAlgortihmType inputAlgorithmName) { - algorithmName = algorithmName; + algorithmName = inputAlgorithmName; } void mitk::pa::SpectralUnmixingFilterVigra::AddWeight(unsigned int weight) { double value = double(weight) / 100.0; weightsvec.push_back(value); } Eigen::VectorXf mitk::pa::SpectralUnmixingFilterVigra::SpectralUnmixingAlgorithm( Eigen::Matrix endmemberMatrix, Eigen::VectorXf inputVector) { unsigned int numberOfWavelengths = endmemberMatrix.rows(); unsigned int numberOfChromophores = endmemberMatrix.cols(); // writes endmemberMatrix and inputVector into vigra::Matrix std::vector aData; std::vector bData; for (unsigned int i = 0; i < numberOfWavelengths; ++i) { bData.push_back((double)inputVector(i)); for (unsigned int j = 0; j < numberOfChromophores; ++j) aData.push_back((double)endmemberMatrix(i, j)); } const double* aDat = aData.data(); const double* bDat = bData.data(); vigra::Matrix A(vigra::Shape2(numberOfWavelengths, numberOfChromophores), aDat); vigra::Matrix b(vigra::Shape2(numberOfWavelengths, 1), bDat); vigra::Matrix x(vigra::Shape2(numberOfChromophores, 1)); if (mitk::pa::SpectralUnmixingFilterVigra::VigraAlgortihmType::LARS == algorithmName) nonnegativeLeastSquares(A, b, x); else if (mitk::pa::SpectralUnmixingFilterVigra::VigraAlgortihmType::GOLDFARB == algorithmName) { vigra::linalg::Matrix eye(vigra::linalg::identityMatrix(numberOfChromophores)), zeros(vigra::Shape2(numberOfChromophores, 1)), empty, U = vigra::linalg::transpose(A)*A, // v= -transpose(A)*b replaced by -v used in "quadraticProgramming" v = vigra::linalg::transpose(A)*b; x = 0; quadraticProgramming(U, -v, empty, empty, eye, zeros, x); } else if (mitk::pa::SpectralUnmixingFilterVigra::VigraAlgortihmType::WEIGHTED == algorithmName) { const double* weightsdat = weightsvec.data(); vigra::Matrix weigths(vigra::Shape2(numberOfWavelengths, 1), weightsdat); vigra::linalg::weightedLeastSquares(A, b, weigths, x); } else if (mitk::pa::SpectralUnmixingFilterVigra::VigraAlgortihmType::LS == algorithmName) linearSolve(A, b, x); else mitkThrow() << "404 VIGRA ALGORITHM NOT FOUND"; Eigen::VectorXf resultVector(numberOfChromophores); for (unsigned int k = 0; k < numberOfChromophores; ++k) resultVector[k] = (float)x(k, 0); return resultVector; } diff --git a/Plugins/org.mitk.gui.qt.photoacoustics.spectralunmixing/src/internal/SpectralUnmixing.cpp b/Plugins/org.mitk.gui.qt.photoacoustics.spectralunmixing/src/internal/SpectralUnmixing.cpp index 66a1f2d2eb..5068da74af 100644 --- a/Plugins/org.mitk.gui.qt.photoacoustics.spectralunmixing/src/internal/SpectralUnmixing.cpp +++ b/Plugins/org.mitk.gui.qt.photoacoustics.spectralunmixing/src/internal/SpectralUnmixing.cpp @@ -1,378 +1,370 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ // Blueberry #include #include // Qmitk #include "SpectralUnmixing.h" // Qt #include // mitk image #include // Include to perform Spectral Unmixing #include "mitkPASpectralUnmixingFilterBase.h" #include "mitkPALinearSpectralUnmixingFilter.h" #include "mitkPASpectralUnmixingSO2.h" #include "mitkPASpectralUnmixingFilterVigra.h" #include "mitkPASpectralUnmixingFilterLagrange.h" #include "mitkPASpectralUnmixingFilterSimplex.h" const std::string SpectralUnmixing::VIEW_ID = "org.mitk.views.spectralunmixing"; void SpectralUnmixing::SetFocus() { m_Controls.buttonPerformImageProcessing->setFocus(); } void SpectralUnmixing::CreateQtPartControl(QWidget *parent) { // create GUI widgets from the Qt Designer's .ui file m_Controls.setupUi(parent); connect(m_Controls.buttonPerformImageProcessing, &QPushButton::clicked, this, &SpectralUnmixing::DoImageProcessing); } void SpectralUnmixing::ClearWavelength() { m_Wavelengths.clear(); } void SpectralUnmixing::OnSelectionChanged(berry::IWorkbenchPart::Pointer /*source*/, const QList &nodes) { // iterate all selected objects, adjust warning visibility foreach (mitk::DataNode::Pointer node, nodes) { if (node.IsNotNull() && dynamic_cast(node->GetData())) { m_Controls.labelWarning->setVisible(false); m_Controls.buttonPerformImageProcessing->setEnabled(true); return; } } m_Controls.labelWarning->setVisible(true); m_Controls.buttonPerformImageProcessing->setEnabled(false); } mitk::pa::SpectralUnmixingFilterBase::Pointer SpectralUnmixing::GetFilterInstance(std::string algorithm) { - mitk::pa::SpectralUnmixingFilterBase::Pointer spectralUnmixingFilter; if (algorithm == "householderQr") { spectralUnmixingFilter = mitk::pa::LinearSpectralUnmixingFilter::New(); dynamic_cast(spectralUnmixingFilter.GetPointer()) - ->SetAlgorithm(mitk::pa::LinearSpectralUnmixingFilter::AlgortihmType::householderQr); + ->SetAlgorithm(mitk::pa::LinearSpectralUnmixingFilter::AlgortihmType::HOUSEHOLDERQR); } else if (algorithm == "ldlt") { spectralUnmixingFilter = mitk::pa::LinearSpectralUnmixingFilter::New(); dynamic_cast(spectralUnmixingFilter.GetPointer()) - ->SetAlgorithm(mitk::pa::LinearSpectralUnmixingFilter::AlgortihmType::ldlt); + ->SetAlgorithm(mitk::pa::LinearSpectralUnmixingFilter::AlgortihmType::LDLT); } else if (algorithm == "llt") { spectralUnmixingFilter = mitk::pa::LinearSpectralUnmixingFilter::New(); dynamic_cast(spectralUnmixingFilter.GetPointer()) - ->SetAlgorithm(mitk::pa::LinearSpectralUnmixingFilter::AlgortihmType::llt); + ->SetAlgorithm(mitk::pa::LinearSpectralUnmixingFilter::AlgortihmType::LLT); } else if (algorithm == "colPivHouseholderQr") { spectralUnmixingFilter = mitk::pa::LinearSpectralUnmixingFilter::New(); dynamic_cast(spectralUnmixingFilter.GetPointer()) - ->SetAlgorithm(mitk::pa::LinearSpectralUnmixingFilter::AlgortihmType::colPivHouseholderQr); + ->SetAlgorithm(mitk::pa::LinearSpectralUnmixingFilter::AlgortihmType::COLPIVHOUSEHOLDERQR); } else if (algorithm == "jacobiSvd") { spectralUnmixingFilter = mitk::pa::LinearSpectralUnmixingFilter::New(); dynamic_cast(spectralUnmixingFilter.GetPointer()) - ->SetAlgorithm(mitk::pa::LinearSpectralUnmixingFilter::AlgortihmType::jacobiSvd); + ->SetAlgorithm(mitk::pa::LinearSpectralUnmixingFilter::AlgortihmType::JACOBISVD); } else if (algorithm == "fullPivLu") { spectralUnmixingFilter = mitk::pa::LinearSpectralUnmixingFilter::New(); dynamic_cast(spectralUnmixingFilter.GetPointer()) - ->SetAlgorithm(mitk::pa::LinearSpectralUnmixingFilter::AlgortihmType::fullPivLu); + ->SetAlgorithm(mitk::pa::LinearSpectralUnmixingFilter::AlgortihmType::FULLPIVLU); } else if (algorithm == "fullPivHouseholderQr") { spectralUnmixingFilter = mitk::pa::LinearSpectralUnmixingFilter::New(); dynamic_cast(spectralUnmixingFilter.GetPointer()) - ->SetAlgorithm(mitk::pa::LinearSpectralUnmixingFilter::AlgortihmType::fullPivHouseholderQr); - } - - else if (algorithm == "test") - { - spectralUnmixingFilter = mitk::pa::LinearSpectralUnmixingFilter::New(); - dynamic_cast(spectralUnmixingFilter.GetPointer()) - ->SetAlgorithm(mitk::pa::LinearSpectralUnmixingFilter::AlgortihmType::test); + ->SetAlgorithm(mitk::pa::LinearSpectralUnmixingFilter::AlgortihmType::FULLPIVHOUSEHOLDERQR); } else if (algorithm == "NNLARS") { spectralUnmixingFilter = mitk::pa::SpectralUnmixingFilterVigra::New(); dynamic_cast(spectralUnmixingFilter.GetPointer()) ->SetAlgorithm(mitk::pa::SpectralUnmixingFilterVigra::VigraAlgortihmType::LARS); } else if (algorithm == "NNGoldfarb") { spectralUnmixingFilter = mitk::pa::SpectralUnmixingFilterVigra::New(); dynamic_cast(spectralUnmixingFilter.GetPointer()) ->SetAlgorithm(mitk::pa::SpectralUnmixingFilterVigra::VigraAlgortihmType::GOLDFARB); } else if (algorithm == "weighted") { spectralUnmixingFilter = mitk::pa::SpectralUnmixingFilterVigra::New(); dynamic_cast(spectralUnmixingFilter.GetPointer()) ->SetAlgorithm(mitk::pa::SpectralUnmixingFilterVigra::VigraAlgortihmType::WEIGHTED); //Tranfer GUI information(Weights) to filter int colunm = 0; int Weight = 1; while (m_Controls.inputtable->item(1, colunm) && Weight > 0) { QString Text = m_Controls.inputtable->item(1, colunm)->text(); Weight = Text.toInt(); if (Weight > 0) dynamic_cast(spectralUnmixingFilter.GetPointer()) ->AddWeight(Weight); ++colunm; } } else if (algorithm == "LS") { spectralUnmixingFilter = mitk::pa::SpectralUnmixingFilterVigra::New(); dynamic_cast(spectralUnmixingFilter.GetPointer()) ->SetAlgorithm(mitk::pa::SpectralUnmixingFilterVigra::VigraAlgortihmType::LS); } else if (algorithm == "SimplexMax") { spectralUnmixingFilter = mitk::pa::SpectralUnmixingFilterSimplex::New(); } else mitkThrow() << "404 ALGORITHM NOT FOUND!"; return spectralUnmixingFilter; } void SpectralUnmixing::DoImageProcessing() { QList nodes = this->GetDataManagerSelection(); if (nodes.empty()) return; mitk::DataNode *node = nodes.front(); if (!node) { // Nothing selected. Inform the user and return QMessageBox::information(nullptr, "Template", "Please load and select an image before starting image processing."); return; } // here we have a valid mitk::DataNode // a node itself is not very useful, we need its data item (the image) mitk::BaseData *data = node->GetData(); if (data) { // test if this data item is an image or not (could also be a surface or something totally different) mitk::Image *image = dynamic_cast(data); if (image) { std::stringstream message; std::string name; message << "PERFORMING SPECTRAL UNMIXING "; if (node->GetName(name)) { // a property called "name" was found for this DataNode message << "'" << name << "'"; } message << "."; MITK_INFO << message.str(); //Tranfer GUI information(Algortihm) to filter auto qs = m_Controls.QComboBoxAlgorithm->currentText(); std::string Algorithm = qs.toUtf8().constData(); mitk::pa::SpectralUnmixingFilterBase::Pointer m_SpectralUnmixingFilter = GetFilterInstance(Algorithm); m_SpectralUnmixingFilter->SetInput(image); //Tranfer GUI information(Wavelength) to filter ClearWavelength(); int col = 0; int Wavelength = 1; while (m_Controls.inputtable->item(0, col) && Wavelength > 0) { QString Text = m_Controls.inputtable->item(0, col)->text(); Wavelength = Text.toInt(); if (Wavelength > 0) m_SpectralUnmixingFilter->AddWavelength(Wavelength); ++col; } //Tranfer GUI information(Chromophores) to filter unsigned int numberofChromophores = 0; DeOxbool = m_Controls.checkBoxDeOx->isChecked(); Oxbool = m_Controls.checkBoxOx->isChecked(); bool Melaninbool = m_Controls.checkBoxMelanin->isChecked(); bool Onebool = m_Controls.checkBoxAdd->isChecked(); if (DeOxbool || Oxbool) { MITK_INFO << "CHOSEN CHROMOPHORES:"; } if (Oxbool) { numberofChromophores += 1; MITK_INFO << "- Oxyhemoglobin"; m_SpectralUnmixingFilter->AddChromophore( mitk::pa::PropertyCalculator::ChromophoreType::OXYGENATED); } if (DeOxbool) { numberofChromophores += 1; MITK_INFO << "- Deoxygenated hemoglobin"; m_SpectralUnmixingFilter->AddChromophore( mitk::pa::PropertyCalculator::ChromophoreType::DEOXYGENATED); } if (Melaninbool) { numberofChromophores += 1; MITK_INFO << "- Melanin"; m_SpectralUnmixingFilter->AddChromophore( mitk::pa::PropertyCalculator::ChromophoreType::MELANIN); } if (Onebool) { numberofChromophores += 1; MITK_INFO << "- Additional Chromophore"; m_SpectralUnmixingFilter->AddChromophore( mitk::pa::PropertyCalculator::ChromophoreType::ONEENDMEMBER); } if (numberofChromophores == 0) { mitkThrow() << "PRESS 'IGNORE' AND CHOOSE A CHROMOPHORE!"; } MITK_INFO << "Updating Filter..."; m_SpectralUnmixingFilter->Update(); int outputCounter = 0; // Write Output images to Data Storage if (Oxbool) { mitk::Image::Pointer HbO2 = m_SpectralUnmixingFilter->GetOutput(outputCounter++); mitk::DataNode::Pointer dataNodeHbO2 = mitk::DataNode::New(); dataNodeHbO2->SetData(HbO2); dataNodeHbO2->SetName("HbO2 " + Algorithm); this->GetDataStorage()->Add(dataNodeHbO2); } if (DeOxbool) { mitk::Image::Pointer Hb = m_SpectralUnmixingFilter->GetOutput(outputCounter++); mitk::DataNode::Pointer dataNodeHb = mitk::DataNode::New(); dataNodeHb->SetData(Hb); dataNodeHb->SetName("Hb " + Algorithm); this->GetDataStorage()->Add(dataNodeHb); } if (Melaninbool) { mitk::Image::Pointer Melanin = m_SpectralUnmixingFilter->GetOutput(outputCounter++); mitk::DataNode::Pointer dataNodeMelanin = mitk::DataNode::New(); dataNodeMelanin->SetData(Melanin); dataNodeMelanin->SetName("Melanin " + Algorithm); this->GetDataStorage()->Add(dataNodeMelanin); } if (Onebool) { mitk::Image::Pointer One = m_SpectralUnmixingFilter->GetOutput(outputCounter++); mitk::DataNode::Pointer dataNodeOne = mitk::DataNode::New(); dataNodeOne->SetData(One); dataNodeOne->SetName("One " + Algorithm); this->GetDataStorage()->Add(dataNodeOne); } //Calculate oxygen saturation bool sO2bool = m_Controls.checkBoxsO2->isChecked(); if (sO2bool) { if (!DeOxbool) mitkThrow() << "SELECT CHROMOPHORE DEOXYHEMOGLOBIN!"; if (!Oxbool) mitkThrow() << "SELECT CHROMOPHORE OXYHEMOGLOBIN!"; MITK_INFO << "CALCULATE OXYGEN SATURATION ..."; auto m_sO2 = mitk::pa::SpectralUnmixingSO2::New(); // Oxygen Saturation Setting for (int i = 0; i < 4; ++i) { if (m_Controls.inputtable->item(0, i)) { QString Text = m_Controls.tableSO2->item(0, i)->text(); float value = Text.toFloat(); MITK_INFO << "value: " << value; m_sO2->AddSO2Settings(value); } else m_sO2->AddSO2Settings(0); } // Initialize pipeline from SU filter class to SO2 class auto output1 = m_SpectralUnmixingFilter->GetOutput(0); auto output2 = m_SpectralUnmixingFilter->GetOutput(1); m_sO2->SetInput(0, output1); m_sO2->SetInput(1, output2); m_sO2->Update(); // Write Output images to Data Storage mitk::Image::Pointer sO2 = m_sO2->GetOutput(0); mitk::DataNode::Pointer dataNodesO2 = mitk::DataNode::New(); dataNodesO2->SetData(sO2); dataNodesO2->SetName("sO2" + Algorithm); this->GetDataStorage()->Add(dataNodesO2); MITK_INFO << "[DONE]"; } mitk::RenderingManager::GetInstance()->InitializeViewsByBoundingObjects(this->GetDataStorage()); MITK_INFO << "Adding images to DataStorage...[DONE]"; } } }