diff --git a/Modules/PhotoacousticsLib/include/mitkPALinearSpectralUnmixingFilter.h b/Modules/PhotoacousticsLib/include/mitkPALinearSpectralUnmixingFilter.h index ab10dc7779..7e02475cec 100644 --- a/Modules/PhotoacousticsLib/include/mitkPALinearSpectralUnmixingFilter.h +++ b/Modules/PhotoacousticsLib/include/mitkPALinearSpectralUnmixingFilter.h @@ -1,103 +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 }; /** * \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/llt solver which doens't work yet + * @throws if the algorithmName is not a member of the enum VigraAlgortihmType + * @throws if one chooses the ldlt/llt solver which doens't work yet */ virtual Eigen::VectorXf SpectralUnmixingAlgorithm(Eigen::Matrix endmemberMatrix, Eigen::VectorXf inputVector) override; private: mitk::pa::LinearSpectralUnmixingFilter::AlgortihmType algorithmName; }; } } #endif // MITKLINEARPHOTOACOUSTICSPECTRALUNMIXINGFILTER_H diff --git a/Modules/PhotoacousticsLib/include/mitkPASpectralUnmixingFilterBase.h b/Modules/PhotoacousticsLib/include/mitkPASpectralUnmixingFilterBase.h index 8ffde0fbb4..7e012dbaa9 100644 --- a/Modules/PhotoacousticsLib/include/mitkPASpectralUnmixingFilterBase.h +++ b/Modules/PhotoacousticsLib/include/mitkPASpectralUnmixingFilterBase.h @@ -1,176 +1,176 @@ /*=================================================================== 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 MITKPHOTOACOUSTICSPECTRALUNMIXINGFILTERBASE_H #define MITKPHOTOACOUSTICSPECTRALUNMIXINGFILTERBASE_H #include "mitkImageToImageFilter.h" #include //Includes for smart pointer usage #include "mitkCommon.h" #include "itkLightObject.h" // Includes for AddEnmemberMatrix #include "mitkPAPropertyCalculator.h" #include namespace mitk { namespace pa { /** * \brief The spectral unmixing filter base is designed as superclass for several spectral unmixing filter eg. Eigen- or Vigrabased ones. * One can add wavelengths and chromophores and get a unmixed output images out of one MITK input image using algorithms from the subclasses. * * Input: * The unmixing input has to be a 3D MITK image where the XY-plane is a image and the Z-direction represents recordings for different * wavelengths. Herein a XY-plane for a specific Z-direction will be called "image". Every image has to be assigned to a certain wavelength. * The "AddWavelength" uses "push_back" to write float values into a vector. The first wavelength will correspond to the first image!!! * If there a more input images 'I' then added wavelengths 'w' the filter base interprets the next x images as repetition sequence of the same * wavelengths. If I % w !=0 the surplus image(s) will be dropped. * Addtionaly one has to add chromophores from the property calculator class enum "ChromophoreType" with the "AddChromophore" method. * This method as well uses "push_back" but the chosen (arbitary) order will be the order of the outputs. * * Output: * The output will be one MITK image per chosen chromophore. Where the XY-plane is a image and the Z-direction represents recordings for different * sequences. * * Subclasses: * - mitkPASpectralUnmixingFilterVigra * - mitkPALinearSpectralUnmixingFilter (uses Eigen algorithms) * - mitkPASpectralUnmixingFilterSimplex * * Possible exceptions: * - "PIXELTYPE ERROR! FLOAT 32 REQUIRED": The MITK input image has to consist out of floats. * - "ERROR! REMOVE WAVELENGTHS!": One needs at least the same amount of images (z-dimension) then added wavelengths. * - "ADD MORE WAVELENGTHS!": One needs at least the same amount of wavelengths then added chromophores. * - "WAVELENGTH XXX nm NOT SUPPORTED!": The wavelength is not part of the proptery calculater data base. The data base can be found @ * [...]\mitk\Modules\PhotoacousticsLib\Resources\spectralLIB.dat */ class MITKPHOTOACOUSTICSLIB_EXPORT SpectralUnmixingFilterBase : public mitk::ImageToImageFilter { public: mitkClassMacro(SpectralUnmixingFilterBase, mitk::ImageToImageFilter); /** * \brief AddChromophore takes mitk::pa::PropertyCalculator::ChromophoreType and writes them at the end of the m_Chromophore vector. * The call of the method sets the order of the GetOutput method! * * @param chromophore has to be element of porperty calculater enum chromophore type * @return for wavelength smaller then 300nm and larger then 1000nm the return will be 0, because not at the data base (2018/06/19) */ void AddChromophore(mitk::pa::PropertyCalculator::ChromophoreType chromophore); /** * \brief AddWavelength takes integers and writes them at the end of the m_Wavelength vector. The first call of the method then * corresponds to the first input image and so on. * @param wavelength database supports integers between 300 and 1000 nm */ void AddWavelength(int wavelength); /* * \brief Verbose gives more information to the console. Default value is false. * @param verbose is the boolian to activate the MITK_INFO logged to the console */ virtual void Verbose(bool verbose); /** * \brief AddOutputs takes an integer and sets indexed outputs * @param outputs integer correponds to the number of output images */ virtual void AddOutputs(unsigned int outputs); /* * \brief RelativeError returns a image which compare the L2 norm of the input vector with the unmixing result * @param relativeError is the boolian to activate this tool */ virtual void RelativeError(bool relativeError); ofstream myfile; // just for testing purposes; has to be removeed protected: /** * \brief Constructor creats proptery calculater smart pointer new() */ SpectralUnmixingFilterBase(); virtual ~SpectralUnmixingFilterBase(); /** * \brief The subclasses will override the mehtod to calculate the spectral unmixing result vector. * @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. */ virtual Eigen::VectorXf SpectralUnmixingAlgorithm(Eigen::Matrix endmemberMatrix, Eigen::VectorXf inputVector) = 0; bool m_Verbose = false; bool m_RelativeError = false; std::vector m_Chromophore; std::vector m_Wavelength; private: /* * \brief Initialized output images with the same XY-plane size like the input image and total size in z-direction equals number of sequences. * The pixel type is set to float. * @param totalNumberOfSequences = (unsigned int) (numberOfInputImages / numberOfWavelength) >= 1 */ virtual void InitializeOutputs(unsigned int totalNumberOfSequences); /* * \brief Checks if there are a suitable amount of wavelengths and if the input image consists of floats. * @param numberOfInputImages corresponds to the z-dimension of the MITK input image * @param inputDataArray contains every pixel of the MITK input image. Accessable like pseudo multidimensional array, that means * pixel(x,y,z) = (xdim * yDim * z) + x * yDim + y where eg. "xdim" means the total size of the MITK input image in x direction. - * @throw if there are more wavelength then images - * @throw if there are more chromophores then wavelengths - * @throw if the pixel type is not float 32 + * @throws if there are more wavelength then images + * @throws if there are more chromophores then wavelengths + * @throws if the pixel type is not float 32 */ virtual void CheckPreConditions(unsigned int numberOfInputImages, const float* inputDataArray); /* * \brief Inherit from the "ImageToImageFilter" Superclass. Herain it calls InitializeOutputs, CalculateEndmemberMatrix and * CheckPreConditions methods and enables pixelwise access to do spectral unmixing with the "SpectralUnmixingAlgorithm" * method. In the end the method writes the results into the new MITK output images. */ virtual void GenerateData() override; /* * \brief Creats a Matrix with number of chromophores colums and number of wavelengths rows so matrix element (i,j) contains * the absorbtion of chromophore j @ wavelength i. The absorbtion values are taken from the "PropertyElement" method. * @param m_Chromophore is a vector of "PropertyCalculator::ChromophoreType" containing all selected chromophores for the unmixing * @param m_Wavelength is a vector of integers containing all wavelengths of one sequence */ virtual Eigen::Matrix CalculateEndmemberMatrix( std::vector m_Chromophore, std::vector m_Wavelength); /* * \brief "PropertyElement" is the tool to access the absorbtion values out of the database using mitk::pa::PropertyCalculator::GetAbsorptionForWavelengt * and checks if the requested wavelength is part of the database (not zero values). The "ONEENDMEMBER" is a pseudo absorber with static absorbtion 1 * 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. * @param wavelength has to be integer between 300 and 1000 nm * @param chromophore has to be a mitk::pa::PropertyCalculator::ChromophoreType - * @throw if mitk::pa::PropertyCalculator::GetAbsorptionForWavelengt returns 0, because this means that the delivered wavelength is not in the database. + * @throws if mitk::pa::PropertyCalculator::GetAbsorptionForWavelengt returns 0, because this means that the delivered wavelength is not in the database. */ virtual float PropertyElement(mitk::pa::PropertyCalculator::ChromophoreType, int wavelength); PropertyCalculator::Pointer m_PropertyCalculatorEigen; }; } } #endif // MITKPHOTOACOUSTICSPECTRALUNMIXINGFILTERBASE_ diff --git a/Modules/PhotoacousticsLib/include/mitkPASpectralUnmixingFilterVigra.h b/Modules/PhotoacousticsLib/include/mitkPASpectralUnmixingFilterVigra.h index bce89841f1..f29fdea5fc 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 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 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 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 + * @throws 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/include/mitkPASpectralUnmixingSO2.h b/Modules/PhotoacousticsLib/include/mitkPASpectralUnmixingSO2.h index b10e26982b..9180e8968a 100644 --- a/Modules/PhotoacousticsLib/include/mitkPASpectralUnmixingSO2.h +++ b/Modules/PhotoacousticsLib/include/mitkPASpectralUnmixingSO2.h @@ -1,100 +1,100 @@ /*=================================================================== 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 MITKPHOTOACOUSTICSPECTRALUNMIXINGSO2_H #define MITKPHOTOACOUSTICSPECTRALUNMIXINGSO2_H #include "mitkImageToImageFilter.h" #include //Includes for smart pointer usage #include "mitkCommon.h" #include "itkLightObject.h" namespace mitk { namespace pa { /** * \brief derives out of two identical sized MITK images the oxygen saturation and return one MITK image as result. Furthermore * it is possible to set settings that the result shows just SO2 values above a threshold, or above a input value for Hb, HbO2 to * get just a oxygen saturation image of interessting structures. * * Input: * The input has to be two 3D MITK images. The order of the inputs matter! The first input has to be the Hb image the second input * has to be the HbO2 image. The settings are integer values. The SO2 threshold therefore is percentage value. * * Output: * The output will be one MITK image. Where one can see the oxygen saturation of all pixels above the set threholds. If a pixel is * below a threhold or NAN then the value will be set to zero. */ class MITKPHOTOACOUSTICSLIB_EXPORT SpectralUnmixingSO2 : public mitk::ImageToImageFilter { public: mitkClassMacro(SpectralUnmixingSO2, mitk::ImageToImageFilter); itkFactorylessNewMacro(Self); /** * \brief AddSO2Settings takes integers and writes them at the end of the m_SO2Settings vector. * @param value has to be a integer */ virtual void AddSO2Settings(float value); /* * \brief Verbose gives more information to the console. Default value is false. * @param m_Verbose is the boolian to activate the MITK_INFO logged to the console */ virtual void Verbose(bool verbose); protected: /** * \brief Constructor sets number of input images to two and number of output images to one, respectively. */ SpectralUnmixingSO2(); virtual ~SpectralUnmixingSO2(); std::vector m_SO2Settings; bool m_Verbose = false; private: /* * \brief Inherit from the "ImageToImageFilter" Superclass. Herain it calls InitializeOutputs and the CheckPreConditions * methods and enables pixelwise access to the inputs to calculate the oxygen saturation via the "calculate SO2" method. */ virtual void GenerateData() override; /* * \brief Initialized output images with the same size like the input image. The pixel type is set to float. */ virtual void InitializeOutputs(); /* * \brief Checks if the dimensions of the input images are equal. - * @throw if tey are not + * @throws if tey are not */ virtual void CheckPreConditions(mitk::Image::Pointer inputHbO2, mitk::Image::Pointer inputHb); /* * \brief calculates HbO2 / (Hb + HbO2) and afterwards checks if the result and inputs are above threshold values of the * settings. If they are not the method returns zero otherwise it returns the calculated result. * @param pixelHb is the pixel value of the Hb input. * @param pixelHb is the pixel value of the Hb input. * @warn if the HbO2 value is NAN (in patricular if Hb == -HbO2), but result will be set to zero */ float calculateSO2(float pixelHb, float pixelHbO2); }; } } #endif // MITKPHOTOACOUSTICSPECTRALUNMIXINGSO2_ diff --git a/Modules/PhotoacousticsLib/src/SUFilter/mitkPASpectralUnmixingFilterBase.cpp b/Modules/PhotoacousticsLib/src/SUFilter/mitkPASpectralUnmixingFilterBase.cpp index 114610256c..29da1990de 100644 --- a/Modules/PhotoacousticsLib/src/SUFilter/mitkPASpectralUnmixingFilterBase.cpp +++ b/Modules/PhotoacousticsLib/src/SUFilter/mitkPASpectralUnmixingFilterBase.cpp @@ -1,216 +1,215 @@ /*=================================================================== 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 "mitkPASpectralUnmixingFilterBase.h" // Includes for AddEnmemberMatrix #include "mitkPAPropertyCalculator.h" #include // ImageAccessor #include #include #include mitk::pa::SpectralUnmixingFilterBase::SpectralUnmixingFilterBase() { m_PropertyCalculatorEigen = mitk::pa::PropertyCalculator::New(); } mitk::pa::SpectralUnmixingFilterBase::~SpectralUnmixingFilterBase() { } void mitk::pa::SpectralUnmixingFilterBase::AddOutputs(unsigned int outputs) { this->SetNumberOfIndexedOutputs(outputs); for (unsigned int i = 0; iSetNthOutput(i, mitk::Image::New()); } void mitk::pa::SpectralUnmixingFilterBase::AddWavelength(int wavelength) { m_Wavelength.push_back(wavelength); } void mitk::pa::SpectralUnmixingFilterBase::AddChromophore(mitk::pa::PropertyCalculator::ChromophoreType chromophore) { m_Chromophore.push_back(chromophore); } void mitk::pa::SpectralUnmixingFilterBase::Verbose(bool verbose) { m_Verbose = verbose; } void mitk::pa::SpectralUnmixingFilterBase::RelativeError(bool relativeError) { m_RelativeError = relativeError; } void mitk::pa::SpectralUnmixingFilterBase::GenerateData() { MITK_INFO(m_Verbose) << "GENERATING DATA.."; mitk::Image::Pointer input = GetInput(0); unsigned int xDim = input->GetDimensions()[0]; unsigned int yDim = input->GetDimensions()[1]; unsigned int numberOfInputImages = input->GetDimensions()[2]; MITK_INFO(m_Verbose) << "x dimension: " << xDim; MITK_INFO(m_Verbose) << "y dimension: " << yDim; MITK_INFO(m_Verbose) << "z dimension: " << numberOfInputImages; unsigned int sequenceSize = m_Wavelength.size(); unsigned int totalNumberOfSequences = numberOfInputImages / sequenceSize; + if (totalNumberOfSequences == 0) //means that more chromophores then wavelengths + mitkThrow() << "ERROR! REMOVE WAVELENGTHS!"; MITK_INFO(m_Verbose) << "TotalNumberOfSequences: " << totalNumberOfSequences; InitializeOutputs(totalNumberOfSequences); auto endmemberMatrix = CalculateEndmemberMatrix(m_Chromophore, m_Wavelength); // Copy input image into array mitk::ImageReadAccessor readAccess(input); const float* inputDataArray = ((const float*)readAccess.GetData()); CheckPreConditions(numberOfInputImages, inputDataArray); // test to see pixel values @ txt file myfile.open("SimplexNormalisation.txt"); for (unsigned int sequenceCounter = 0; sequenceCounter < totalNumberOfSequences; ++sequenceCounter) { MITK_INFO(m_Verbose) << "SequenceCounter: " << sequenceCounter; //loop over every pixel in XY-plane for (unsigned int x = 0; x < xDim; x++) { for (unsigned int y = 0; y < yDim; y++) { Eigen::VectorXf inputVector(sequenceSize); for (unsigned int z = 0; z < sequenceSize; z++) { /** * 'sequenceCounter*sequenceSize' has to be added to 'z' to ensure that one accesses the * correct pixel, because the inputDataArray contains the information of all sequences and * not just the one of the current sequence. */ unsigned int pixelNumber = (xDim*yDim*(z+sequenceCounter*sequenceSize)) + x * yDim + y; auto pixel = inputDataArray[pixelNumber]; inputVector[z] = pixel; } Eigen::VectorXf resultVector = SpectralUnmixingAlgorithm(endmemberMatrix, inputVector); unsigned int outputCounter = GetNumberOfIndexedOutputs(); if (m_RelativeError == true) { // because rel error is output[IndexedOutputs() - 1] and loop over chromophore outputs has to end at [IndexedOutputs() - 2] outputCounter -= 1; float relativeError = (endmemberMatrix*resultVector - inputVector).norm() / inputVector.norm(); // norm() is L2 norm auto output = GetOutput(outputCounter); mitk::ImageWriteAccessor writeOutput(output); float* writeBuffer = (float *)writeOutput.GetData(); writeBuffer[(xDim*yDim * sequenceCounter) + x * yDim + y] = relativeError; } for (unsigned int outputIdx = 0; outputIdx < outputCounter; ++outputIdx) { auto output = GetOutput(outputIdx); mitk::ImageWriteAccessor writeOutput(output); float* writeBuffer = (float *)writeOutput.GetData(); writeBuffer[(xDim*yDim * sequenceCounter) + x * yDim + y] = resultVector[outputIdx]; } } } } std::chrono::steady_clock::time_point _end(std::chrono::steady_clock::now()); std::chrono::steady_clock::time_point _test(std::chrono::steady_clock::now()); MITK_INFO(m_Verbose) << "GENERATING DATA...[DONE]"; myfile.close(); } void mitk::pa::SpectralUnmixingFilterBase::CheckPreConditions(unsigned int numberOfInputImages, const float* inputDataArray) { MITK_INFO(m_Verbose) << "CHECK PRECONDITIONS ..."; if (m_Wavelength.size() < numberOfInputImages) MITK_WARN << "NUMBER OF WAVELENGTHS < NUMBER OF INPUT IMAGES"; - if (m_Wavelength.size() > numberOfInputImages) - mitkThrow() << "ERROR! REMOVE WAVELENGTHS!"; - if (m_Chromophore.size() > m_Wavelength.size()) - mitkThrow() << "ADD MORE WAVELENGTHS!"; + mitkThrow() << "ADD MORE WAVELENGTHS OR REMOVE ENDMEMBERS!"; if (typeid(inputDataArray[0]).name() != typeid(float).name()) mitkThrow() << "PIXELTYPE ERROR! FLOAT 32 REQUIRED"; MITK_INFO(m_Verbose) << "...[DONE]"; } void mitk::pa::SpectralUnmixingFilterBase::InitializeOutputs(unsigned int totalNumberOfSequences) { MITK_INFO(m_Verbose) << "Initialize Outputs ..."; unsigned int numberOfInputs = GetNumberOfIndexedInputs(); unsigned int numberOfOutputs = GetNumberOfIndexedOutputs(); MITK_INFO(m_Verbose) << "Inputs: " << numberOfInputs << " Outputs: " << numberOfOutputs; mitk::PixelType pixelType = mitk::MakeScalarPixelType(); const int NUMBER_OF_SPATIAL_DIMENSIONS = 3; auto* dimensions = new unsigned int[NUMBER_OF_SPATIAL_DIMENSIONS]; for (unsigned int dimIdx = 0; dimIdx < 2; dimIdx++) dimensions[dimIdx] = GetInput()->GetDimensions()[dimIdx]; dimensions[2] = totalNumberOfSequences; for (unsigned int outputIdx = 0; outputIdx < numberOfOutputs; outputIdx++) GetOutput(outputIdx)->Initialize(pixelType, NUMBER_OF_SPATIAL_DIMENSIONS, dimensions); MITK_INFO(m_Verbose) << "...[DONE]"; } Eigen::Matrix mitk::pa::SpectralUnmixingFilterBase::CalculateEndmemberMatrix( std::vector m_Chromophore, std::vector m_Wavelength) { unsigned int numberOfChromophores = m_Chromophore.size(); //columns unsigned int numberOfWavelengths = m_Wavelength.size(); //rows Eigen::Matrix endmemberMatrixEigen(numberOfWavelengths, numberOfChromophores); for (unsigned int j = 0; j < numberOfChromophores; ++j) { for (unsigned int i = 0; i < numberOfWavelengths; ++i) endmemberMatrixEigen(i, j) = PropertyElement(m_Chromophore[j], m_Wavelength[i]); } MITK_INFO(m_Verbose) << "GENERATING ENMEMBERMATRIX [DONE]"; return endmemberMatrixEigen; } float mitk::pa::SpectralUnmixingFilterBase::PropertyElement(mitk::pa::PropertyCalculator::ChromophoreType chromophore, int wavelength) { if (chromophore == mitk::pa::PropertyCalculator::ChromophoreType::ONEENDMEMBER) return 1; else { float value = m_PropertyCalculatorEigen->GetAbsorptionForWavelength(chromophore, wavelength); if (value == 0) mitkThrow() << "WAVELENGTH " << wavelength << "nm NOT SUPPORTED!"; else return value; } } 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 a4f18b534d..5e8e68d75a 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,409 +1,413 @@ /*=================================================================== 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" #include #include 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); m_Controls.tableWeight->hide(); m_Controls.tableSO2->hide(); connect((QObject*)(m_Controls.QComboBoxAlgorithm), SIGNAL(currentIndexChanged(int)), this, SLOT(ChangeGUIWeight())); connect((QObject*)(m_Controls.checkBoxsO2), SIGNAL(clicked()), this, SLOT(ChangeGUISO2())); } void SpectralUnmixing::SwitchGUIControls(bool change) { MITK_INFO(PluginVerbose) << "ENABLE GUI " << change; m_Controls.inputtable->setEnabled(change); m_Controls.checkBoxOx->setEnabled(change); m_Controls.checkBoxDeOx->setEnabled(change); m_Controls.checkBoxMelanin->setEnabled(change); m_Controls.checkBoxAdd->setEnabled(change); m_Controls.QComboBoxAlgorithm->setEnabled(change); m_Controls.tableWeight->setEnabled(change); m_Controls.checkBoxsO2->setEnabled(change); m_Controls.tableSO2->setEnabled(change); m_Controls.checkBoxVerbose->setEnabled(change); m_Controls.checkBoxChrono->setEnabled(change); m_Controls.buttonPerformImageProcessing->setEnabled(change); } void SpectralUnmixing::ChangeGUIWeight() { auto qs = m_Controls.QComboBoxAlgorithm->currentText(); std::string Algorithm = qs.toUtf8().constData(); if (Algorithm == "weighted") m_Controls.tableWeight->show(); else m_Controls.tableWeight->hide(); } void SpectralUnmixing::ChangeGUISO2() { if (m_Controls.checkBoxsO2->isChecked()) m_Controls.tableSO2->show(); else m_Controls.tableSO2->hide(); } void SpectralUnmixing::SetVerboseMode(mitk::pa::SpectralUnmixingFilterBase::Pointer m_SpectralUnmixingFilter, bool PluginVerbose) { m_SpectralUnmixingFilter->Verbose(PluginVerbose); } void SpectralUnmixing::SetWavlength(mitk::pa::SpectralUnmixingFilterBase::Pointer m_SpectralUnmixingFilter) { 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); MITK_INFO(PluginVerbose) << "Wavelength: " << Wavelength << "nm \n"; } ++col; } } void SpectralUnmixing::SetChromophore(mitk::pa::SpectralUnmixingFilterBase::Pointer m_SpectralUnmixingFilter, std::vector boolVec, std::vector chromophoreNameVec) { unsigned int numberofChromophores = 0; std::vector m_ChromoType = { mitk::pa::PropertyCalculator::ChromophoreType::OXYGENATED, mitk::pa::PropertyCalculator::ChromophoreType::DEOXYGENATED, mitk::pa::PropertyCalculator::ChromophoreType::MELANIN, mitk::pa::PropertyCalculator::ChromophoreType::ONEENDMEMBER}; for (unsigned int chromo = 0; chromo < m_ChromoType.size(); ++chromo) { if (boolVec[chromo] == true) { MITK_INFO(PluginVerbose) << "Chromophore: " << chromophoreNameVec[chromo]; m_SpectralUnmixingFilter->AddChromophore(m_ChromoType[chromo]); numberofChromophores += 1; } } if (numberofChromophores == 0) mitkThrow() << "PRESS 'IGNORE' AND CHOOSE A CHROMOPHORE!"; } 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); } else if (algorithm == "ldlt") { spectralUnmixingFilter = mitk::pa::LinearSpectralUnmixingFilter::New(); dynamic_cast(spectralUnmixingFilter.GetPointer()) ->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); } else if (algorithm == "colPivHouseholderQr") { spectralUnmixingFilter = mitk::pa::LinearSpectralUnmixingFilter::New(); dynamic_cast(spectralUnmixingFilter.GetPointer()) ->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); } else if (algorithm == "fullPivLu") { spectralUnmixingFilter = mitk::pa::LinearSpectralUnmixingFilter::New(); dynamic_cast(spectralUnmixingFilter.GetPointer()) ->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 == "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 unsigned int colunm = 0; int Weight = 1; while (m_Controls.tableWeight->item(0, colunm) && Weight > 0) { QString Text = m_Controls.tableWeight->item(0, colunm)->text(); Weight = Text.toInt(); if (Weight > 0) { dynamic_cast(spectralUnmixingFilter.GetPointer()) ->AddWeight(Weight); MITK_INFO(PluginVerbose) << "Weight: " << 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::SetSO2Settings(mitk::pa::SpectralUnmixingSO2::Pointer m_sO2) { for (unsigned 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(PluginVerbose) << "SO2 setting value: " << value; m_sO2->AddSO2Settings(value); } else m_sO2->AddSO2Settings(0); } } void SpectralUnmixing::CalculateSO2(mitk::pa::SpectralUnmixingFilterBase::Pointer m_SpectralUnmixingFilter, std::vector boolVec) { MITK_INFO(PluginVerbose) << "CALCULATE OXYGEN SATURATION ..."; if (!boolVec[0]) mitkThrow() << "SELECT CHROMOPHORE DEOXYHEMOGLOBIN!"; if (!boolVec[1]) mitkThrow() << "SELECT CHROMOPHORE OXYHEMOGLOBIN!"; auto m_sO2 = mitk::pa::SpectralUnmixingSO2::New(); m_sO2->Verbose(PluginVerbose); SetSO2Settings(m_sO2); // 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(); mitk::Image::Pointer sO2 = m_sO2->GetOutput(0); sO2->SetSpacing(output1->GetGeometry()->GetSpacing()); WriteOutputToDataStorage(sO2, "sO2"); MITK_INFO(PluginVerbose) << "[DONE]"; } void SpectralUnmixing::WriteOutputToDataStorage(mitk::Image::Pointer m_Image, std::string name) { mitk::DataNode::Pointer dataNodeOutput = mitk::DataNode::New(); dataNodeOutput->SetData(m_Image); dataNodeOutput->SetName(name); this->GetDataStorage()->Add(dataNodeOutput); } 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 << "."; SwitchGUIControls(false); std::chrono::steady_clock::time_point _start(std::chrono::steady_clock::now()); PluginVerbose = m_Controls.checkBoxVerbose->isChecked(); MITK_INFO(PluginVerbose) << message.str(); - GenerateOutput(image); + try { GenerateOutput(image); } + catch (const mitk::Exception& e) + { + QMessageBox::information(nullptr, "Template", e.GetDescription()); + } std::chrono::steady_clock::time_point _end(std::chrono::steady_clock::now()); MITK_INFO(m_Controls.checkBoxChrono->isChecked()) << "Time for image Processing: " << std::chrono::duration_cast>(_end - _start).count(); SwitchGUIControls(true); } } } void SpectralUnmixing::GenerateOutput(mitk::Image::Pointer image) { std::vector boolVec = { m_Controls.checkBoxOx->isChecked(), m_Controls.checkBoxDeOx->isChecked(), m_Controls.checkBoxMelanin->isChecked(), m_Controls.checkBoxAdd->isChecked() }; std::vector outputNameVec = { "HbO2", "Hb", "Melanin", "Static Endmember" }; //Read GUI information(algorithm) auto qs = m_Controls.QComboBoxAlgorithm->currentText(); std::string Algorithm = qs.toUtf8().constData(); mitk::pa::SpectralUnmixingFilterBase::Pointer m_SpectralUnmixingFilter = GetFilterInstance(Algorithm); SetVerboseMode(m_SpectralUnmixingFilter, PluginVerbose); m_SpectralUnmixingFilter->RelativeError(m_Controls.checkBoxError->isChecked()); m_SpectralUnmixingFilter->SetInput(image); SetWavlength(m_SpectralUnmixingFilter); SetChromophore(m_SpectralUnmixingFilter, boolVec, outputNameVec); boolVec.push_back(m_Controls.checkBoxError->isChecked()); outputNameVec.push_back("Relative Error"); m_SpectralUnmixingFilter->AddOutputs(std::accumulate(boolVec.begin(), boolVec.end(), 0)); MITK_INFO(PluginVerbose) << "Number of indexed outputs: " << std::accumulate(boolVec.begin(), boolVec.end(), 0); MITK_INFO(PluginVerbose) << "Updating Filter..."; m_SpectralUnmixingFilter->Update(); int outputCounter = 0; mitk::Image::Pointer m_Output; for (unsigned int chromophore = 0; chromophore < outputNameVec.size(); ++chromophore) { if (boolVec[chromophore] != false) { m_Output = m_SpectralUnmixingFilter->GetOutput(outputCounter++); m_Output->SetSpacing(image->GetGeometry()->GetSpacing()); WriteOutputToDataStorage(m_Output, outputNameVec[chromophore] + Algorithm); } } if (m_Controls.checkBoxsO2->isChecked()) CalculateSO2(m_SpectralUnmixingFilter, boolVec); mitk::RenderingManager::GetInstance()->InitializeViewsByBoundingObjects(this->GetDataStorage()); MITK_INFO(PluginVerbose) << "Adding images to DataStorage...[DONE]"; } diff --git a/Plugins/org.mitk.gui.qt.photoacoustics.spectralunmixing/src/internal/SpectralUnmixing.h b/Plugins/org.mitk.gui.qt.photoacoustics.spectralunmixing/src/internal/SpectralUnmixing.h index c5d847c5e0..2aae9c5310 100644 --- a/Plugins/org.mitk.gui.qt.photoacoustics.spectralunmixing/src/internal/SpectralUnmixing.h +++ b/Plugins/org.mitk.gui.qt.photoacoustics.spectralunmixing/src/internal/SpectralUnmixing.h @@ -1,139 +1,142 @@ /*=================================================================== 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 SpectralUnmixing_h #define SpectralUnmixing_h #include #include #include #include #include "ui_SpectralUnmixingControls.h" /** * \brief The spectral unmixing plugin provides a GUI tool to perform spectral unmixing of multispectral MITK images. * It was designed to unmix beamformed photoacoustic imgaes. The outputs are as well MITK images for every chosen absorber * (endmember). Furthermore it is possible to calculate the oxygen saturation of the multispectral input if the endmembers * oxy- and deoxyhemoglobin are selected in the GUI. * * For further information look at the documentation of the mitkPASpectralUnmixingFilterBase.h +* +* @exeption if the GenerateOutput method throws a exception the plugin will show a QMessageBox with the exception +* message at the GUI */ class SpectralUnmixing : public QmitkAbstractView { // this is needed for all Qt objects that should have a Qt meta-object // (everything that derives from QObject and wants to have signal/slots) Q_OBJECT public: static const std::string VIEW_ID; protected: virtual void CreateQtPartControl(QWidget *parent) override; virtual void SetFocus() override; /// \brief called by QmitkFunctionality when DataManager's selection has changed virtual void OnSelectionChanged(berry::IWorkbenchPart::Pointer source, const QList &nodes) override; /** * \brief Called when the user clicks the GUI button. Checks if the selected data is an image. Then performs spectral * unmixing via the GenerateOutput method based on the spectral unmixing filter base and its subclasses. * @exception if nothing is selected. Inform the user and return */ void DoImageProcessing(); /** * \brief slots are there to show/hide input tables for weights- and SO2 settings ig they are not needed */ public slots: void ChangeGUIWeight(); void ChangeGUISO2(); protected: Ui::SpectralUnmixingControls m_Controls; /** * \brief passes the algorithm information from the GUI on to the spectral unmixing filter base subclass method * "SetAlgortihm" and initializes the subclassFilter::Pointer. * @param algorithm has to be a string which can be assigned to the mitk::pa::LinearSpectralUnmixingFilter::AlgortihmType * @thorw if the algorithm string doesn't match to an implemented algorithm */ mitk::pa::SpectralUnmixingFilterBase::Pointer GetFilterInstance(std::string algorithm); /** * \brief passes the algorithm information if verbose mode is requested from the GUI on to the spectral unmixing filter * @param m_SpectralUnmixingFilter is a pointer of the spectral unmixing filter base * @param PluginVerbose is the GUI information bool */ virtual void SetVerboseMode(mitk::pa::SpectralUnmixingFilterBase::Pointer m_SpectralUnmixingFilter, bool PluginVerbose); bool PluginVerbose = true; private: /* * \brief passes the wavelength information from the GUI on to the spectral unmixing filter base method "AddWavelength". * @param m_SpectralUnmixingFilter is a pointer of the spectral unmixing filter base */ virtual void SetWavlength(mitk::pa::SpectralUnmixingFilterBase::Pointer m_SpectralUnmixingFilter); /* * \brief passes the chromophore information from the GUI on to the spectral unmixing filter base method "AddChromophore". * @param m_SpectralUnmixingFilter is a pointer of the spectral unmixing filter base * @param boolVec is a vector which contains the information which chromophore was checked in the GUI * @param chromophoreNameVec contains the names of all chromophores as strings - * @throw "PRESS 'IGNORE' AND CHOOSE A CHROMOPHORE!" if no chromophore was chosen + * @throws "PRESS 'IGNORE' AND CHOOSE A CHROMOPHORE!" if no chromophore was chosen */ virtual void SetChromophore(mitk::pa::SpectralUnmixingFilterBase::Pointer m_SpectralUnmixingFilter, std::vector boolVec, std::vector chromophoreNameVec); /* * \brief The method takes a image pointer and a file name which then will get to the data storage. * @param m_Image is a mitk_::Image::Pointer pointing at the output which one wants to get stored * @param name has to be a string and will be the file name */ virtual void WriteOutputToDataStorage(mitk::Image::Pointer m_Image, std::string name); /** * \brief passes the SetSO2Settings information from the GUI on to the spectral unmixing SO2 filter method "AddSO2Settings". * @param m_sO2 is a pointer of the spectral unmixing SO2 filter */ virtual void SetSO2Settings(mitk::pa::SpectralUnmixingSO2::Pointer m_sO2); /** * \brief calcultes out of two identical sized MITK images the oxygen saturation and stores the result in an image. Herein the two * input images are the output for oxy- and deoxyhemoglobin from the GenerateOutput method (spectral unmixing filter results). * @param m_SpectralUnmixingFilter is a pointer of the spectral unmixing filter base to get the filter output images as sO2 input * @param boolVec is a vector which contains the information which chromophore was checked in the GUI - * @throw if oxy- or deoxyhemoglobin was not selected in the GUI + * @throws if oxy- or deoxyhemoglobin was not selected in the GUI */ virtual void CalculateSO2(mitk::pa::SpectralUnmixingFilterBase::Pointer m_SpectralUnmixingFilter, std::vector boolVec); /** * \brief takes an MITK image as input and performs spectral unmixing based on the spectral unmixing filter base and its subclasses. * @param image has to be an MITK image (pointer). For the request on the image look at the docu of the mitkPASpectralUnmixngFilterBase.h */ virtual void GenerateOutput(mitk::Image::Pointer image); /** * \brief enables/disables GUI * @param change true means GUI buttons enabled, false disabled respectively */ virtual void SwitchGUIControls(bool change); }; #endif // SpectralUnmixing_h