diff --git a/Modules/PhotoacousticsLib/test/mitkSpectralUnmixingTest.cpp b/Modules/PhotoacousticsLib/test/mitkSpectralUnmixingTest.cpp index 8d6e9516b8..d5db505a12 100644 --- a/Modules/PhotoacousticsLib/test/mitkSpectralUnmixingTest.cpp +++ b/Modules/PhotoacousticsLib/test/mitkSpectralUnmixingTest.cpp @@ -1,141 +1,139 @@ ///*=================================================================== //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 class mitkSpectralUnmixingTestSuite : public mitk::TestFixture { CPPUNIT_TEST_SUITE(mitkSpectralUnmixingTestSuite); MITK_TEST(testSUAlgorithm); CPPUNIT_TEST_SUITE_END(); private: mitk::pa::SpectralUnmixingFilterBase::Pointer m_SpectralUnmixingFilter; mitk::Image::Pointer inputImage; std::vector m_inputWavelengths; std::vector m_CorrectResult; 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] = 3; //Initialie empty input image: inputImage->Initialize(pixelType, NUMBER_OF_SPATIAL_DIMENSIONS, dimensions); //Set wavelengths for unmixing: m_inputWavelengths.push_back(750); m_inputWavelengths.push_back(800); m_inputWavelengths.push_back(850); //Set fraction of Hb and HbO2 to unmix: float fracHb = 0.3; float fracHbO2 = 0.67; //Fractions are also correct unmixing result: - m_CorrectResult.push_back(fracHb); m_CorrectResult.push_back(fracHbO2); + m_CorrectResult.push_back(fracHb); //Calculate values of wavelengths (750,800,850 nm) and multiply 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 * 3.7 + fracHbO2 * 5.67; std::vector m_Value{px1,px2,px3}; float* data = new float[3]; data[0] = m_Value[0]; data[1] = m_Value[1]; data[2] = m_Value[2]; MITK_INFO << "data0 " << data[0]; MITK_INFO << "data1 " << data[1]; MITK_INFO << "data2 " << data[2]; inputImage->SetImportVolume(data, mitk::Image::ImportMemoryManagementType::CopyMemory); delete[] data; - //Set input into filter + MITK_INFO << "[DONE]"; + } + + void testSUAlgorithm() + { + MITK_INFO << "START FILTER TEST ... "; + // Set input image auto m_SpectralUnmixingFilter = mitk::pa::LinearSpectralUnmixingFilter::New(); m_SpectralUnmixingFilter->SetInput(inputImage); // Set Algortihm to filter m_SpectralUnmixingFilter->SetAlgorithm(mitk::pa::LinearSpectralUnmixingFilter::AlgortihmType::householderQr); //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::SpectralUnmixingFilterBase::ChromophoreType::OXYGENATED_HEMOGLOBIN); m_SpectralUnmixingFilter->AddChromophore( mitk::pa::SpectralUnmixingFilterBase::ChromophoreType::DEOXYGENATED_HEMOGLOBIN); - MITK_INFO << "[DONE]"; - } - - void testSUAlgorithm() - { - MITK_INFO << "START FILTER TEST ... "; - auto m_LinearSpectralUnmixing = mitk::pa::LinearSpectralUnmixingFilter::New(); - auto m_SpectralUnmixingFilter = mitk::pa::LinearSpectralUnmixingFilter::New(); - m_LinearSpectralUnmixing->SetInput(inputImage); - - //compare filter result (output) with theoretical result + m_SpectralUnmixingFilter->Update(); float threshold = 1e-5; + 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]; - CPPUNIT_ASSERT((pixel - m_CorrectResult[i])