diff --git a/Modules/PhotoacousticsLib/include/mitkPASpectralUnmixingFilterBase.h b/Modules/PhotoacousticsLib/include/mitkPASpectralUnmixingFilterBase.h index ed8b8b64bf..e9be406c52 100644 --- a/Modules/PhotoacousticsLib/include/mitkPASpectralUnmixingFilterBase.h +++ b/Modules/PhotoacousticsLib/include/mitkPASpectralUnmixingFilterBase.h @@ -1,71 +1,75 @@ /*=================================================================== 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 { + /** + * documentation + *\brief ,,,, + */ class MITKPHOTOACOUSTICSLIB_EXPORT SpectralUnmixingFilterBase : public mitk::ImageToImageFilter { public: mitkClassMacro(SpectralUnmixingFilterBase, mitk::ImageToImageFilter); void AddChromophore(mitk::pa::PropertyCalculator::ChromophoreType); void AddWavelength(int wavelength); void AddWeight(int Weight); ofstream myfile; protected: SpectralUnmixingFilterBase(); virtual ~SpectralUnmixingFilterBase(); std::vector m_Chromophore; std::vector m_Wavelength; virtual Eigen::VectorXf SpectralUnmixingAlgorithm(Eigen::Matrix EndmemberMatrix, Eigen::VectorXf inputVector) = 0; std::vector m_Weight; private: virtual void CheckPreConditions(unsigned int size, unsigned int NumberOfInputImages, const float* inputDataArray); virtual void GenerateData() override; virtual void InitializeOutputs(unsigned int TotalNumberOfSequences); virtual Eigen::Matrix CalculateEndmemberMatrix( std::vector m_Chromophore, std::vector m_Wavelength); PropertyCalculator::Pointer m_PropertyCalculatorEigen; - virtual float propertyElement(mitk::pa::PropertyCalculator::ChromophoreType, int wavelength); + virtual float PropertyElement(mitk::pa::PropertyCalculator::ChromophoreType, int wavelength); }; } } #endif // MITKPHOTOACOUSTICSPECTRALUNMIXINGFILTERBASE_ diff --git a/Modules/PhotoacousticsLib/src/SUFilter/mitkPASpectralUnmixingFilterBase.cpp b/Modules/PhotoacousticsLib/src/SUFilter/mitkPASpectralUnmixingFilterBase.cpp index 127186fba1..d70b156fe9 100644 --- a/Modules/PhotoacousticsLib/src/SUFilter/mitkPASpectralUnmixingFilterBase.cpp +++ b/Modules/PhotoacousticsLib/src/SUFilter/mitkPASpectralUnmixingFilterBase.cpp @@ -1,239 +1,232 @@ /*=================================================================== 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 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::AddWeight(int Weight) { m_Weight.push_back(Weight); - MITK_INFO << "Weight: " << m_Weight[m_Weight.size()-1]; } void mitk::pa::SpectralUnmixingFilterBase::GenerateData() { MITK_INFO << "GENERATING DATA.."; // Get input image mitk::Image::Pointer input = GetInput(0); unsigned int xDim = input->GetDimensions()[0]; unsigned int yDim = input->GetDimensions()[1]; unsigned int NumberOfInputImages = input->GetDimensions()[2]; unsigned int size = xDim * yDim * NumberOfInputImages; MITK_INFO << "x dimension: " << xDim; MITK_INFO << "y dimension: " << yDim; MITK_INFO << "z dimension: " << NumberOfInputImages; unsigned int sequenceSize = m_Wavelength.size(); unsigned int TotalNumberOfSequences = NumberOfInputImages / sequenceSize; MITK_INFO << "TotalNumberOfSequences: " << TotalNumberOfSequences; InitializeOutputs(TotalNumberOfSequences); auto EndmemberMatrix = CalculateEndmemberMatrix(m_Chromophore, m_Wavelength); //Eigen Endmember Matrix // Copy input image into array mitk::ImageReadAccessor readAccess(input); const float* inputDataArray = ((const float*)readAccess.GetData()); CheckPreConditions(size, NumberOfInputImages, inputDataArray); // test to see pixel values @ txt file //ofstream myfile; //myfile.open("PASpectralUnmixingPixelValues.txt"); std::chrono::steady_clock::time_point _start(std::chrono::steady_clock::now()); myfile.open("SimplexNormalisation.txt"); for (unsigned int SequenceCounter = 0; SequenceCounter < TotalNumberOfSequences;++SequenceCounter) { MITK_INFO << "SequenceCounter: " << SequenceCounter; //loop over every pixel @ x,y 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++) { // Get pixel value of pixel x,y @ wavelength z unsigned int pixelNumber = (xDim*yDim*(z+SequenceCounter*sequenceSize)) + x * yDim + y; auto pixel = inputDataArray[pixelNumber]; //write all wavelength absorbtion values for one(!) pixel to a vector inputVector[z] = pixel; } Eigen::VectorXf resultVector = SpectralUnmixingAlgorithm(EndmemberMatrix, inputVector); // write output 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]; } //myfile << "Input Pixel(x,y): " << x << "," << y << "\n" << inputVector << "\n"; //myfile << "Result: " << "\n HbO2: " << resultVector[0] << "\n Hb: " << resultVector[1] << "\n Mel: " // << resultVector[2] << "Result vector size" << resultVector.size() << "\n"; } } } 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 << "Chronotets: " << std::chrono::duration_cast>(_test - _start).count() << "s"; MITK_INFO << "Chrono: " << std::chrono::duration_cast>(_end - _start).count() << "s"; MITK_INFO << "GENERATING DATA...[DONE]"; myfile.close(); } void mitk::pa::SpectralUnmixingFilterBase::CheckPreConditions(unsigned int size, unsigned int NumberOfInputImages, const float* inputDataArray) { - // Checking if number of Inputs == added wavelengths if (m_Wavelength.size() < NumberOfInputImages) MITK_WARN << "NUMBER OF WAVELENGTHS < NUMBER OF INPUT IMAGES"; if (m_Wavelength.size() > NumberOfInputImages) mitkThrow() << "ERROR! REMOVE WAVELENGTHS!"; // Checking if number of wavelengths >= number of chromophores if (m_Chromophore.size() > m_Wavelength.size()) - mitkThrow() << "PRESS 'IGNORE' AND ADD MORE WAVELENGTHS!"; + mitkThrow() << "ADD MORE WAVELENGTHS!"; // Checking if pixel type is float - int maxPixel = size; - for (int i = 0; i < maxPixel; ++i) - { - if (typeid(inputDataArray[i]).name() != typeid(float).name()) - mitkThrow() << "PIXELTYPE ERROR! FLOAT 32 REQUIRED"; + if (typeid(inputDataArray[0]).name() != typeid(float).name()) + mitkThrow() << "PIXELTYPE ERROR! FLOAT 32 REQUIRED"; - else continue; - } MITK_INFO << "CHECK PRECONDITIONS ...[DONE]"; } void mitk::pa::SpectralUnmixingFilterBase::InitializeOutputs(unsigned int TotalNumberOfSequences) { unsigned int numberOfInputs = GetNumberOfIndexedInputs(); unsigned int numberOfOutputs = GetNumberOfIndexedOutputs(); MITK_INFO << "Inputs: " << numberOfInputs << " Outputs: " << numberOfOutputs; // Set dimensions (3) and pixel type (float) for output 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; // Initialize numberOfOutput pictures with pixel type and dimensions for (unsigned int outputIdx = 0; outputIdx < numberOfOutputs; outputIdx++) { GetOutput(outputIdx)->Initialize(pixelType, NUMBER_OF_SPATIAL_DIMENSIONS, dimensions); } } //Matrix with #chromophores colums and #wavelengths rows //so Matrix Element (i,j) contains the Absorbtion of chromophore j @ wavelength i 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) { if (m_Chromophore[j] == mitk::pa::PropertyCalculator::ChromophoreType::OXYGENATED) { for (unsigned int i = 0; i < numberOfWavelengths; ++i) - EndmemberMatrixEigen(i, j) = propertyElement(m_Chromophore[j], m_Wavelength[i]); + EndmemberMatrixEigen(i, j) = PropertyElement(m_Chromophore[j], m_Wavelength[i]); } else if (m_Chromophore[j] == mitk::pa::PropertyCalculator::ChromophoreType::DEOXYGENATED) { for (unsigned int i = 0; i < numberOfWavelengths; ++i) - EndmemberMatrixEigen(i, j) = propertyElement(m_Chromophore[j], m_Wavelength[i]); + EndmemberMatrixEigen(i, j) = PropertyElement(m_Chromophore[j], m_Wavelength[i]); } else if (m_Chromophore[j] == mitk::pa::PropertyCalculator::ChromophoreType::MELANIN) { for (unsigned int i = 0; i < numberOfWavelengths; ++i) { - EndmemberMatrixEigen(i, j) = propertyElement(m_Chromophore[j], m_Wavelength[i]); + EndmemberMatrixEigen(i, j) = PropertyElement(m_Chromophore[j], m_Wavelength[i]); MITK_INFO << "MELANIN " << EndmemberMatrixEigen(i, j); } } else if (m_Chromophore[j] == mitk::pa::PropertyCalculator::ChromophoreType::ONEENDMEMBER) { for (unsigned int i = 0; i < numberOfWavelengths; ++i) EndmemberMatrixEigen(i, j) = 1; } else mitkThrow() << "404 CHROMOPHORE NOT FOUND!"; } MITK_INFO << "GENERATING ENMEMBERMATRIX [DONE]!"; return EndmemberMatrixEigen; } -float mitk::pa::SpectralUnmixingFilterBase::propertyElement(mitk::pa::PropertyCalculator::ChromophoreType Chromophore, int Wavelength) +float mitk::pa::SpectralUnmixingFilterBase::PropertyElement(mitk::pa::PropertyCalculator::ChromophoreType Chromophore, int Wavelength) { float value = m_PropertyCalculatorEigen->GetAbsorptionForWavelength(Chromophore, Wavelength); if (value == 0) mitkThrow() << "WAVELENGTH " << Wavelength << "nm NOT SUPPORTED!"; return value; } diff --git a/Modules/PhotoacousticsLib/test/mitkSpectralUnmixingTest.cpp b/Modules/PhotoacousticsLib/test/mitkSpectralUnmixingTest.cpp index e9ef3fd988..aa84f76d4c 100644 --- a/Modules/PhotoacousticsLib/test/mitkSpectralUnmixingTest.cpp +++ b/Modules/PhotoacousticsLib/test/mitkSpectralUnmixingTest.cpp @@ -1,328 +1,328 @@ //*=================================================================== //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 #include #include #include #include #include #include #include class mitkSpectralUnmixingTestSuite : public mitk::TestFixture { CPPUNIT_TEST_SUITE(mitkSpectralUnmixingTestSuite); MITK_TEST(testEigenSUAlgorithm); MITK_TEST(testVigraSUAlgorithm); //MITK_TEST(testSimplexSUAlgorithm);// --> RESULT FAILS - MITK_TEST(testSO2); //--> SO2 Settings FAILS + MITK_TEST(testSO2); CPPUNIT_TEST_SUITE_END(); private: mitk::pa::SpectralUnmixingFilterBase::Pointer m_SpectralUnmixingFilter; mitk::Image::Pointer inputImage; std::vector m_inputWavelengths; std::vector m_inputWeights; std::vector m_CorrectResult; float threshold; public: void setUp() override { MITK_INFO << "setUp ... "; //Set empty input image: inputImage = mitk::Image::New(); mitk::PixelType pixelType = mitk::MakeScalarPixelType(); const int NUMBER_OF_SPATIAL_DIMENSIONS = 3; auto* dimensions = new unsigned int[NUMBER_OF_SPATIAL_DIMENSIONS]; dimensions[0] = 1; dimensions[1] = 1; dimensions[2] = 5; inputImage->Initialize(pixelType, NUMBER_OF_SPATIAL_DIMENSIONS, dimensions); //Set wavelengths for unmixing: m_inputWavelengths.push_back(750); m_inputWavelengths.push_back(800); m_inputWeights.push_back(50); m_inputWeights.push_back(100); //Set fraction of Hb and HbO2 to unmix: float fracHb = 100; float fracHbO2 = 300; m_CorrectResult.push_back(fracHbO2); m_CorrectResult.push_back(fracHb); m_CorrectResult.push_back(fracHbO2 + 10); m_CorrectResult.push_back(fracHb - 10); threshold = 0.01; //Multiply values of wavelengths (750,800,850 nm) with fractions to get pixel values: float px1 = fracHb * 7.52 + fracHbO2 * 2.77; float px2 = fracHb * 4.08 + fracHbO2 * 4.37; float px3 = (fracHb - 10) * 7.52 + (fracHbO2 + 10) * 2.77; float px4 = (fracHb - 10) * 4.08 + (fracHbO2 + 10) * 4.37; float* data = new float[3]; data[0] = px1; data[1] = px2; data[2] = px3; data[3] = px4; data[5] = 0; inputImage->SetImportVolume(data, mitk::Image::ImportMemoryManagementType::CopyMemory); delete[] data; MITK_INFO << "[DONE]"; } void testEigenSUAlgorithm() { MITK_INFO << "START FILTER TEST ... "; // Set input image auto m_SpectralUnmixingFilter = mitk::pa::LinearSpectralUnmixingFilter::New(); m_SpectralUnmixingFilter->SetInput(inputImage); //Set wavelengths to filter for (unsigned int imageIndex = 0; imageIndex < m_inputWavelengths.size(); imageIndex++) { unsigned int wavelength = m_inputWavelengths[imageIndex]; m_SpectralUnmixingFilter->AddWavelength(wavelength); } //Set Chromophores to filter m_SpectralUnmixingFilter->AddChromophore( mitk::pa::PropertyCalculator::ChromophoreType::OXYGENATED); m_SpectralUnmixingFilter->AddChromophore( mitk::pa::PropertyCalculator::ChromophoreType::DEOXYGENATED); ofstream myfile; myfile.open("EigenTestResult.txt"); std::vector m_Eigen = { mitk::pa::LinearSpectralUnmixingFilter::AlgortihmType::householderQr, /* mitk::pa::LinearSpectralUnmixingFilter::AlgortihmType::ldlt, mitk::pa::LinearSpectralUnmixingFilter::AlgortihmType::llt,*/ mitk::pa::LinearSpectralUnmixingFilter::AlgortihmType::colPivHouseholderQr, mitk::pa::LinearSpectralUnmixingFilter::AlgortihmType::jacobiSvd, mitk::pa::LinearSpectralUnmixingFilter::AlgortihmType::fullPivLu, mitk::pa::LinearSpectralUnmixingFilter::AlgortihmType::fullPivHouseholderQr/*mitk::pa::LinearSpectralUnmixingFilter::AlgortihmType::test*/}; for (int Algorithmidx = 0; Algorithmidx < m_Eigen.size();++Algorithmidx) { m_SpectralUnmixingFilter->SetAlgorithm(m_Eigen[Algorithmidx]); m_SpectralUnmixingFilter->Update(); /*For printed pixel values and results look at: [...]\mitk-superbuild\MITK-build\Modules\PhotoacousticsLib\test\*/ for (int i = 0; i < 2; ++i) { mitk::Image::Pointer output = m_SpectralUnmixingFilter->GetOutput(i); mitk::ImageReadAccessor readAccess(output); const float* inputDataArray = ((const float*)readAccess.GetData()); auto pixel = inputDataArray[0]; auto pixel2 = inputDataArray[1]; myfile << "Algorithmidx: " << Algorithmidx << "\n Output " << i << ": " << "\n" << inputDataArray[0] << "\n" << inputDataArray[1] << "\n"; myfile << "Correct Result: " << "\n" << m_CorrectResult[i] << "\n" << m_CorrectResult[i + 2] << "\n"; CPPUNIT_ASSERT(std::abs(pixel - m_CorrectResult[i]) < threshold); CPPUNIT_ASSERT(std::abs(pixel2 - m_CorrectResult[i + 2]) < threshold); } } myfile.close(); MITK_INFO << "EIGEN FILTER TEST SUCCESFULL :)"; } void testVigraSUAlgorithm() { MITK_INFO << "START FILTER TEST ... "; // Set input image auto m_SpectralUnmixingFilter = mitk::pa::SpectralUnmixingFilterVigra::New(); m_SpectralUnmixingFilter->SetInput(inputImage); //Set wavelengths to filter for (unsigned int imageIndex = 0; imageIndex < m_inputWavelengths.size(); imageIndex++) { unsigned int wavelength = m_inputWavelengths[imageIndex]; double Weight = m_inputWeights[imageIndex]; m_SpectralUnmixingFilter->AddWavelength(wavelength); m_SpectralUnmixingFilter->AddWeight(Weight); } //Set Chromophores to filter m_SpectralUnmixingFilter->AddChromophore( mitk::pa::PropertyCalculator::ChromophoreType::OXYGENATED); m_SpectralUnmixingFilter->AddChromophore( mitk::pa::PropertyCalculator::ChromophoreType::DEOXYGENATED); std::vector Vigra = { mitk::pa::SpectralUnmixingFilterVigra::VigraAlgortihmType::LARS, mitk::pa::SpectralUnmixingFilterVigra::VigraAlgortihmType::GOLDFARB, mitk::pa::SpectralUnmixingFilterVigra::VigraAlgortihmType::WEIGHTED, mitk::pa::SpectralUnmixingFilterVigra::VigraAlgortihmType::LS/*, mitk::pa::SpectralUnmixingFilterVigra::VigraAlgortihmType::vigratest*/}; ofstream myfile; myfile.open("VigraTestResult.txt"); for (int Algorithmidx = 0; Algorithmidx < Vigra.size();++Algorithmidx) { m_SpectralUnmixingFilter->SetAlgorithm(Vigra[0]); m_SpectralUnmixingFilter->Update(); /*For printed pixel values and results look at: [...]\mitk-superbuild\MITK-build\Modules\PhotoacousticsLib\test\*/ for (int i = 0; i < 2; ++i) { mitk::Image::Pointer output = m_SpectralUnmixingFilter->GetOutput(i); mitk::ImageReadAccessor readAccess(output); const float* inputDataArray = ((const float*)readAccess.GetData()); auto pixel = inputDataArray[0]; auto pixel2 = inputDataArray[1]; myfile << "Algorithmidx: " << Algorithmidx << "\n Output " << i << ": " << "\n" << inputDataArray[0] << "\n" << inputDataArray[1] << "\n"; myfile << "Correct Result: " << "\n" << m_CorrectResult[i] << "\n" << m_CorrectResult[i + 2] << "\n"; CPPUNIT_ASSERT(std::abs(pixel - m_CorrectResult[i]) < threshold); CPPUNIT_ASSERT(std::abs(pixel2 - m_CorrectResult[i + 2]) < threshold); } } myfile.close(); MITK_INFO << "VIGRA FILTER TEST SUCCESFULL :)"; } void testSimplexSUAlgorithm() { MITK_INFO << "START FILTER TEST ... "; // Set input image auto m_SpectralUnmixingFilter = mitk::pa::SpectralUnmixingFilterSimplex::New(); m_SpectralUnmixingFilter->SetInput(inputImage); //Set wavelengths to filter for (unsigned int imageIndex = 0; imageIndex < m_inputWavelengths.size(); imageIndex++) { unsigned int wavelength = m_inputWavelengths[imageIndex]; m_SpectralUnmixingFilter->AddWavelength(wavelength); } //Set Chromophores to filter m_SpectralUnmixingFilter->AddChromophore( mitk::pa::PropertyCalculator::ChromophoreType::OXYGENATED); m_SpectralUnmixingFilter->AddChromophore( mitk::pa::PropertyCalculator::ChromophoreType::DEOXYGENATED); m_SpectralUnmixingFilter->Update(); /*For printed pixel values and results look at: [...]\mitk-superbuild\MITK-build\Modules\PhotoacousticsLib\test\*/ ofstream myfile; myfile.open("SimplexTestResult.txt"); for (int i = 0; i < 2; ++i) { mitk::Image::Pointer output = m_SpectralUnmixingFilter->GetOutput(i); mitk::ImageReadAccessor readAccess(output); const float* inputDataArray = ((const float*)readAccess.GetData()); auto pixel = inputDataArray[0]; auto pixel2 = inputDataArray[1]; myfile << "Output " << i << ": " << "\n" << inputDataArray[0] << "\n" << inputDataArray[1] << "\n"; myfile << "Correct Result: " << "\n" << m_CorrectResult[i] << "\n" << m_CorrectResult[i + 2] << "\n"; CPPUNIT_ASSERT(std::abs(pixel - m_CorrectResult[i]) CorrectSO2Result1 = { 0, 0, 0, 0, 0 }; std::vector Test1 = { 0,0,0,51 }; std::vector CorrectSO2Result2 = { 0, 0.5, 0, 0.5, 0 }; std::vector Test2 = { 1584, 0, 0, 0 }; std::vector CorrectSO2Result3 = { 0.5, 0.5, 0, 0.5, 0 }; std::vector Test3 = { 0, 1536, 0, 0 }; std::vector CorrectSO2Result4 = { 0.5, 0.5, 0, 0.5, 0 }; std::vector Test4 = { 0, 0, 3072, 49 }; std::vector CorrectSO2Result5 = { 0.5, 0.5, 0.5, 0.5, 0 }; std::vector Test5 = { 1, 1, 1, 49 }; std::vector> TestList; std::vector> ResultList; TestList.push_back(Test1); TestList.push_back(Test2); TestList.push_back(Test3); TestList.push_back(Test4); TestList.push_back(Test5); ResultList.push_back(CorrectSO2Result1); ResultList.push_back(CorrectSO2Result2); ResultList.push_back(CorrectSO2Result3); ResultList.push_back(CorrectSO2Result4); ResultList.push_back(CorrectSO2Result5); /*For printed pixel values and results look at: [...]\mitk-superbuild\MITK-build\Modules\PhotoacousticsLib\test\*/ ofstream myfile; myfile.open("SO2TestResult.txt"); for (int k = 0; k < 5; ++k) { std::vector SO2Settings = TestList[k]; std::vector m_CorrectSO2Result = ResultList[k]; auto m_sO2 = mitk::pa::SpectralUnmixingSO2::New(); m_sO2->SetInput(0, inputImage); m_sO2->SetInput(1, inputImage); for (int i = 0; i < SO2Settings.size(); ++i) m_sO2->AddSO2Settings(SO2Settings[i]); m_sO2->Update(); mitk::Image::Pointer output = m_sO2->GetOutput(0); mitk::ImageReadAccessor readAccess(output); const float* inputDataArray = ((const float*)readAccess.GetData()); for (unsigned int Pixel = 0; Pixel < inputImage->GetDimensions()[2]; ++Pixel) { auto Value = inputDataArray[Pixel]; myfile << "Output(Test "<< k <<") "<< Pixel << ": " << "\n" << Value << "\n"; myfile << "Correct Result: " << "\n" << m_CorrectSO2Result[Pixel] << "\n"; CPPUNIT_ASSERT(std::abs(Value - m_CorrectSO2Result[Pixel]) < threshold); } } myfile.close(); MITK_INFO << "SO2 TEST SUCCESFULL :)"; } void tearDown() override { m_SpectralUnmixingFilter = nullptr; inputImage = nullptr; m_inputWavelengths.clear(); m_CorrectResult.clear(); MITK_INFO << "tearDown ... [DONE]"; } }; MITK_TEST_SUITE_REGISTRATION(mitkSpectralUnmixing)