diff --git a/Modules/PhotoacousticsLib/src/SUFilter/mitkPASpectralUnmixingFilterBase.cpp b/Modules/PhotoacousticsLib/src/SUFilter/mitkPASpectralUnmixingFilterBase.cpp index 2e30222e60..ee961260f8 100644 --- a/Modules/PhotoacousticsLib/src/SUFilter/mitkPASpectralUnmixingFilterBase.cpp +++ b/Modules/PhotoacousticsLib/src/SUFilter/mitkPASpectralUnmixingFilterBase.cpp @@ -1,201 +1,201 @@ /*=================================================================== 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() { - this->SetNumberOfIndexedOutputs(3);// find solution --> 4 is max outputs + this->SetNumberOfIndexedOutputs(4);// find solution --> 4 is max outputs for (unsigned int i = 0; iSetNthOutput(i, mitk::Image::New()); } m_PropertyCalculatorEigen = mitk::pa::PropertyCalculator::New(); } mitk::pa::SpectralUnmixingFilterBase::~SpectralUnmixingFilterBase() { } 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::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; 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]; //write all wavelength absorbtion values for one(!) pixel of a sequence to a vector inputVector[z] = pixel; } Eigen::VectorXf resultVector = SpectralUnmixingAlgorithm(endmemberMatrix, inputVector); for (int outputIdx = 0; outputIdx < GetNumberOfIndexedOutputs(); ++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!"; 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 32681ecf1c..f1b813c678 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,397 +1,338 @@ /*=================================================================== 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::SetWavlength(mitk::pa::SpectralUnmixingFilterBase::Pointer m_SpectralUnmixingFilter) { - 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); MITK_INFO(PluignVerbose) << "Wavelength: " << Wavelength << "nm \n"; ++col; } } -void SpectralUnmixing::SetChromophore(mitk::pa::SpectralUnmixingFilterBase::Pointer m_SpectralUnmixingFilter) +void SpectralUnmixing::SetChromophore(mitk::pa::SpectralUnmixingFilterBase::Pointer m_SpectralUnmixingFilter, std::vector boolVec, + std::vector chromophoreNameVec) { unsigned int numberofChromophores = 0; - DeOxbool = m_Controls.checkBoxDeOx->isChecked(); - Oxbool = m_Controls.checkBoxOx->isChecked(); - Melaninbool = m_Controls.checkBoxMelanin->isChecked(); - Onebool = m_Controls.checkBoxAdd->isChecked(); - if (DeOxbool || Oxbool || Melaninbool || Onebool) - { - MITK_INFO(PluignVerbose) << "CHOSEN CHROMOPHORES:"; - } - if (Oxbool) - { - numberofChromophores += 1; - MITK_INFO(PluignVerbose) << "- Oxyhemoglobin"; - m_SpectralUnmixingFilter->AddChromophore( - mitk::pa::PropertyCalculator::ChromophoreType::OXYGENATED); - } - if (DeOxbool) - { - numberofChromophores += 1; - MITK_INFO(PluignVerbose) << "- Deoxygenated hemoglobin"; - m_SpectralUnmixingFilter->AddChromophore( - mitk::pa::PropertyCalculator::ChromophoreType::DEOXYGENATED); - } - if (Melaninbool) - { - numberofChromophores += 1; - MITK_INFO(PluignVerbose) << "- Melanin"; - m_SpectralUnmixingFilter->AddChromophore( - mitk::pa::PropertyCalculator::ChromophoreType::MELANIN); - } - if (Onebool) + + 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) { - numberofChromophores += 1; - MITK_INFO(PluignVerbose) << "- Additional Chromophore"; - m_SpectralUnmixingFilter->AddChromophore( - mitk::pa::PropertyCalculator::ChromophoreType::ONEENDMEMBER); + if (boolVec[chromo] == true) + { + MITK_INFO(PluignVerbose) << "+ " << 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 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::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(PluignVerbose) << "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(PluignVerbose) << "CALCULATE OXYGEN SATURATION ..."; + + if (!boolVec[0]) + mitkThrow() << "SELECT CHROMOPHORE DEOXYHEMOGLOBIN!"; + if (!boolVec[1]) + mitkThrow() << "SELECT CHROMOPHORE OXYHEMOGLOBIN!"; + auto m_sO2 = mitk::pa::SpectralUnmixingSO2::New(); + + 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); + + WriteOutputToDataStorage(sO2, "sO2"); + MITK_INFO(PluignVerbose) << "[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 << "."; MITK_INFO(PluignVerbose) << message.str(); + GenerateOutput(image); + } + } +} - //******************************************************************************************************************* - - //Read GUI information(algorithm) - auto qs = m_Controls.QComboBoxAlgorithm->currentText(); - std::string Algorithm = qs.toUtf8().constData(); - - mitk::pa::SpectralUnmixingFilterBase::Pointer m_SpectralUnmixingFilter = GetFilterInstance(Algorithm); - - m_SpectralUnmixingFilter->SetInput(image); - - SetWavlength(m_SpectralUnmixingFilter); - - SetChromophore(m_SpectralUnmixingFilter); - - MITK_INFO(PluignVerbose) << "Updating Filter..."; - m_SpectralUnmixingFilter->Update(); - - - - // Write Output images to Data Storage - int outputCounter = 0; - std::vector chromophoreVec = { "HbO2", "Hb", "Melanin", "Static Endmember" }; - std::vector boolVec = { Oxbool, DeOxbool, Melaninbool, Onebool}; - mitk::Image::Pointer m_Output; - for (unsigned int chromophore; chromophore < chromophoreVec.size(); ++chromophore) - { - if (boolVec[chromophore] == false) - continue; - else - { - m_Output = m_SpectralUnmixingFilter->GetOutput(outputCounter++); - WriteOutputToDataStorage(m_Output, chromophoreVec[chromophore] + Algorithm); - } - } - - 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); - } +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 chromophoreNameVec = { "HbO2", "Hb", "Melanin", "Static Endmember" }; - 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); - } + //Read GUI information(algorithm) + auto qs = m_Controls.QComboBoxAlgorithm->currentText(); + std::string Algorithm = qs.toUtf8().constData(); - 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); - } + mitk::pa::SpectralUnmixingFilterBase::Pointer m_SpectralUnmixingFilter = GetFilterInstance(Algorithm); + m_SpectralUnmixingFilter->SetInput(image); + SetWavlength(m_SpectralUnmixingFilter); + SetChromophore(m_SpectralUnmixingFilter, boolVec, chromophoreNameVec); - //Calculate oxygen saturation - bool sO2bool = m_Controls.checkBoxsO2->isChecked(); + MITK_INFO(PluignVerbose) << "Updating Filter..."; + m_SpectralUnmixingFilter->Update(); - if (sO2bool) - { - if (!DeOxbool) - mitkThrow() << "SELECT CHROMOPHORE DEOXYHEMOGLOBIN!"; - if (!Oxbool) - mitkThrow() << "SELECT CHROMOPHORE OXYHEMOGLOBIN!"; - - MITK_INFO(PluignVerbose) << "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(PluignVerbose) << "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(PluignVerbose) << "[DONE]"; - } - mitk::RenderingManager::GetInstance()->InitializeViewsByBoundingObjects(this->GetDataStorage()); - MITK_INFO << "Adding images to DataStorage...[DONE]"; + int outputCounter = 0; + mitk::Image::Pointer m_Output; + for (unsigned int chromophore = 0; chromophore < chromophoreNameVec.size(); ++chromophore) + { + if (boolVec[chromophore] != false) + { + m_Output = m_SpectralUnmixingFilter->GetOutput(outputCounter++); + WriteOutputToDataStorage(m_Output, chromophoreNameVec[chromophore] + Algorithm); } } + + if (m_Controls.checkBoxsO2->isChecked()) + CalculateSO2(m_SpectralUnmixingFilter, boolVec); + + mitk::RenderingManager::GetInstance()->InitializeViewsByBoundingObjects(this->GetDataStorage()); + MITK_INFO(PluignVerbose) << "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 e907531dd6..90b89a6606 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,82 +1,118 @@ /*=================================================================== 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 +*/ 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 + /** + * \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(); - - virtual void ClearWavelength(); - - Ui::SpectralUnmixingControls m_Controls; - - std::vector m_Wavelengths; - mitk::pa::SpectralUnmixingFilterBase::Pointer GetFilterInstance(std::string algorithm); - - // Selection of Chromophores - bool DeOxbool; - bool Oxbool; - bool Melaninbool; - bool Onebool; - bool PluignVerbose = false; + 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); + + bool PluignVerbose = true; + private: /* - * \brief passes the wavelength information from the GUI on to the spectral unmixing filter base method - * "AddWavelength". + * \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". + * \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 */ - virtual void SetChromophore(mitk::pa::SpectralUnmixingFilterBase::Pointer m_SpectralUnmixingFilter); + 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 + */ + 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); }; #endif // SpectralUnmixing_h