24 CPPUNIT_TEST_SUITE(mitkSpectralUnmixingTestSuite);
36 CPPUNIT_TEST_SUITE_END();
41 std::vector<int> m_inputWavelengths;
42 std::vector<double> m_inputWeights;
43 std::vector<float> m_CorrectResult;
53 const int NUMBER_OF_SPATIAL_DIMENSIONS = 3;
54 auto* dimensions =
new unsigned int[NUMBER_OF_SPATIAL_DIMENSIONS];
60 inputImage->Initialize(pixelType, NUMBER_OF_SPATIAL_DIMENSIONS, dimensions);
63 m_inputWavelengths.push_back(750);
64 m_inputWavelengths.push_back(800);
66 m_inputWeights.push_back(50);
67 m_inputWeights.push_back(100);
72 m_CorrectResult.push_back(fracHbO2);
73 m_CorrectResult.push_back(fracHb);
74 m_CorrectResult.push_back(fracHbO2 + 10);
75 m_CorrectResult.push_back(fracHb - 10);
79 float px1 = fracHb * 7.52 + fracHbO2 * 2.77;
80 float px2 = fracHb * 4.08 + fracHbO2 * 4.37;
81 float px3 = (fracHb - 10) * 7.52 + (fracHbO2 + 10) * 2.77;
82 float px4 = (fracHb - 10) * 4.08 + (fracHbO2 + 10) * 4.37;
84 float* data =
new float[6];
91 inputImage->SetImportVolume(data, mitk::Image::ImportMemoryManagementType::CopyMemory);
96 void testEigenSUAlgorithm()
101 m_SpectralUnmixingFilter->Verbose(
false);
102 m_SpectralUnmixingFilter->RelativeError(
false);
103 m_SpectralUnmixingFilter->SetInput(inputImage);
104 m_SpectralUnmixingFilter->AddOutputs(2);
107 for (
unsigned int imageIndex = 0; imageIndex < m_inputWavelengths.size(); imageIndex++)
109 unsigned int wavelength = m_inputWavelengths[imageIndex];
110 m_SpectralUnmixingFilter->AddWavelength(wavelength);
114 m_SpectralUnmixingFilter->AddChromophore(
115 mitk::pa::PropertyCalculator::ChromophoreType::OXYGENATED);
116 m_SpectralUnmixingFilter->AddChromophore(
117 mitk::pa::PropertyCalculator::ChromophoreType::DEOXYGENATED);
120 myfile.open(
"EigenTestResult.txt");
122 std::vector<mitk::pa::LinearSpectralUnmixingFilter::AlgortihmType> m_Eigen = {
123 mitk::pa::LinearSpectralUnmixingFilter::AlgortihmType::HOUSEHOLDERQR,
124 mitk::pa::LinearSpectralUnmixingFilter::AlgortihmType::COLPIVHOUSEHOLDERQR,
125 mitk::pa::LinearSpectralUnmixingFilter::AlgortihmType::JACOBISVD, mitk::pa::LinearSpectralUnmixingFilter::AlgortihmType::FULLPIVLU,
126 mitk::pa::LinearSpectralUnmixingFilter::AlgortihmType::FULLPIVHOUSEHOLDERQR};
128 for (
unsigned int Algorithmidx = 0; Algorithmidx < m_Eigen.size();++Algorithmidx)
130 m_SpectralUnmixingFilter->SetAlgorithm(m_Eigen[Algorithmidx]);
132 m_SpectralUnmixingFilter->Update();
137 for (
int i = 0; i < 2; ++i)
141 const float* inputDataArray = ((
const float*)readAccess.GetData());
142 auto pixel = inputDataArray[0];
143 auto pixel2 = inputDataArray[1];
145 myfile <<
"Algorithmidx: " << Algorithmidx <<
"\n Output " << i <<
": " <<
"\n" << inputDataArray[0] <<
"\n" << inputDataArray[1] <<
"\n";
146 myfile <<
"Correct Result: " <<
"\n" << m_CorrectResult[i] <<
"\n" << m_CorrectResult[i + 2] <<
"\n";
148 CPPUNIT_ASSERT(std::abs(pixel - m_CorrectResult[i]) < threshold);
149 CPPUNIT_ASSERT(std::abs(pixel2 - m_CorrectResult[i + 2]) < threshold);
153 MITK_INFO <<
"EIGEN FILTER TEST SUCCESFULL :)";
157 void testVigraSUAlgorithm()
162 m_SpectralUnmixingFilter->SetInput(inputImage);
163 m_SpectralUnmixingFilter->AddOutputs(2);
164 m_SpectralUnmixingFilter->Verbose(
false);
165 m_SpectralUnmixingFilter->RelativeError(
false);
169 for (
unsigned int imageIndex = 0; imageIndex < m_inputWavelengths.size(); imageIndex++)
171 unsigned int wavelength = m_inputWavelengths[imageIndex];
172 double Weight = m_inputWeights[imageIndex];
173 m_SpectralUnmixingFilter->AddWavelength(wavelength);
174 m_SpectralUnmixingFilter->AddWeight(Weight);
178 m_SpectralUnmixingFilter->AddChromophore(
179 mitk::pa::PropertyCalculator::ChromophoreType::OXYGENATED);
180 m_SpectralUnmixingFilter->AddChromophore(
181 mitk::pa::PropertyCalculator::ChromophoreType::DEOXYGENATED);
184 std::vector<mitk::pa::SpectralUnmixingFilterVigra::VigraAlgortihmType> Vigra = {
185 mitk::pa::SpectralUnmixingFilterVigra::VigraAlgortihmType::LARS, mitk::pa::SpectralUnmixingFilterVigra::VigraAlgortihmType::GOLDFARB,
186 mitk::pa::SpectralUnmixingFilterVigra::VigraAlgortihmType::WEIGHTED, mitk::pa::SpectralUnmixingFilterVigra::VigraAlgortihmType::LS
190 myfile.open(
"VigraTestResult.txt");
192 for (
unsigned int Algorithmidx = 0; Algorithmidx < Vigra.size();++Algorithmidx)
194 m_SpectralUnmixingFilter->SetAlgorithm(Vigra[0]);
196 m_SpectralUnmixingFilter->Update();
201 for (
int i = 0; i < 2; ++i)
205 const float* inputDataArray = ((
const float*)readAccess.GetData());
206 auto pixel = inputDataArray[0];
207 auto pixel2 = inputDataArray[1];
209 myfile <<
"Algorithmidx: " << Algorithmidx <<
"\n Output " << i <<
": " <<
"\n" << inputDataArray[0] <<
"\n" << inputDataArray[1] <<
"\n";
210 myfile <<
"Correct Result: " <<
"\n" << m_CorrectResult[i] <<
"\n" << m_CorrectResult[i + 2] <<
"\n";
212 CPPUNIT_ASSERT(std::abs(pixel - m_CorrectResult[i]) < threshold);
213 CPPUNIT_ASSERT(std::abs(pixel2 - m_CorrectResult[i + 2]) < threshold);
217 MITK_INFO <<
"VIGRA FILTER TEST SUCCESFULL :)";
220 void testSimplexSUAlgorithm()
225 m_SpectralUnmixingFilter->SetInput(inputImage);
226 m_SpectralUnmixingFilter->AddOutputs(2);
227 m_SpectralUnmixingFilter->Verbose(
true);
228 m_SpectralUnmixingFilter->RelativeError(
false);
231 for (
unsigned int imageIndex = 0; imageIndex < m_inputWavelengths.size(); imageIndex++)
233 unsigned int wavelength = m_inputWavelengths[imageIndex];
234 m_SpectralUnmixingFilter->AddWavelength(wavelength);
238 m_SpectralUnmixingFilter->AddChromophore(
239 mitk::pa::PropertyCalculator::ChromophoreType::OXYGENATED);
240 m_SpectralUnmixingFilter->AddChromophore(
241 mitk::pa::PropertyCalculator::ChromophoreType::DEOXYGENATED);
243 m_SpectralUnmixingFilter->Update();
248 myfile.open(
"SimplexTestResult.txt");
249 for (
int i = 0; i < 2; ++i)
253 const float* inputDataArray = ((
const float*)readAccess.GetData());
254 auto pixel = inputDataArray[0];
255 auto pixel2 = inputDataArray[1];
257 myfile <<
"Output " << i <<
": " <<
"\n" << inputDataArray[0] <<
"\n" << inputDataArray[1] <<
"\n";
258 myfile <<
"Correct Result: " <<
"\n" << m_CorrectResult[i] <<
"\n" << m_CorrectResult[i + 2] <<
"\n";
260 CPPUNIT_ASSERT(std::abs(pixel - m_CorrectResult[i])<threshold);
261 CPPUNIT_ASSERT(std::abs(pixel2 - m_CorrectResult[i + 2])<threshold);
264 MITK_INFO <<
"SIMPLEX FILTER TEST SUCCESFULL :)";
268 void testExceptionSO2()
270 MITK_INFO <<
"START EXCEPTION SO2 TEST ... ";
273 m_sO2->SetInput(0, inputImage);
275 inputImage =
nullptr;
278 const int NUMBER_OF_SPATIAL_DIMENSIONS = 3;
279 auto* dimensions =
new unsigned int[NUMBER_OF_SPATIAL_DIMENSIONS];
285 inputImage->Initialize(pixelType, NUMBER_OF_SPATIAL_DIMENSIONS, dimensions);
287 float* data =
new float[4];
293 inputImage->SetImportVolume(data, mitk::Image::ImportMemoryManagementType::CopyMemory);
296 m_sO2->SetInput(1, inputImage);
307 std::vector<float> CorrectSO2Result1 = { 0, 0, 0, 0, 0 };
308 std::vector<float> Test1 = { 0,0,0,51 };
309 std::vector<float> CorrectSO2Result2 = { 0, 0.5, 0, 0.5, 0 };
310 std::vector<float> Test2 = { 1584, 0, 0, 0 };
311 std::vector<float> CorrectSO2Result3 = { 0.5, 0.5, 0, 0.5, 0 };
312 std::vector<float> Test3 = { 0, 1536, 0, 0 };
313 std::vector<float> CorrectSO2Result4 = { 0.5, 0.5, 0, 0.5, 0 };
314 std::vector<float> Test4 = { 0, 0, 3072, 49 };
315 std::vector<float> CorrectSO2Result5 = { 0.5, 0.5, 0.5, 0.5, 0 };
316 std::vector<float> Test5 = { 1, 1, 1, 49 };
318 std::vector<std::vector<float>> TestList;
319 std::vector<std::vector<float>> ResultList;
321 TestList.push_back(Test1);
322 TestList.push_back(Test2);
323 TestList.push_back(Test3);
324 TestList.push_back(Test4);
325 TestList.push_back(Test5);
327 ResultList.push_back(CorrectSO2Result1);
328 ResultList.push_back(CorrectSO2Result2);
329 ResultList.push_back(CorrectSO2Result3);
330 ResultList.push_back(CorrectSO2Result4);
331 ResultList.push_back(CorrectSO2Result5);
335 myfile.open(
"SO2TestResult.txt");
337 for (
int k = 0;
k < 5; ++
k)
339 std::vector<float> SO2Settings = TestList[
k];
340 std::vector<float> m_CorrectSO2Result = ResultList[
k];
342 m_sO2->SetInput(0, inputImage);
343 m_sO2->SetInput(1, inputImage);
344 for (
unsigned int i = 0; i < SO2Settings.size(); ++i)
345 m_sO2->AddSO2Settings(SO2Settings[i]);
350 const float* inputDataArray = ((
const float*)readAccess.GetData());
352 for (
unsigned int Pixel = 0; Pixel < inputImage->GetDimensions()[2]; ++Pixel)
354 auto Value = inputDataArray[Pixel];
356 myfile <<
"Output(Test " <<
k <<
") " << Pixel <<
": " <<
"\n" << Value <<
"\n";
357 myfile <<
"Correct Result: " <<
"\n" << m_CorrectSO2Result[Pixel] <<
"\n";
359 CPPUNIT_ASSERT(std::abs(Value - m_CorrectSO2Result[Pixel]) < threshold);
367 void testWavelengthExceptions()
369 MITK_INFO <<
"START WavelengthExceptions TEST ... ";
372 m_SpectralUnmixingFilter->Verbose(
false);
373 m_SpectralUnmixingFilter->RelativeError(
false);
374 m_SpectralUnmixingFilter->SetInput(inputImage);
375 m_SpectralUnmixingFilter->AddOutputs(2);
377 m_SpectralUnmixingFilter->AddChromophore(
378 mitk::pa::PropertyCalculator::ChromophoreType::OXYGENATED);
379 m_SpectralUnmixingFilter->AddChromophore(
380 mitk::pa::PropertyCalculator::ChromophoreType::DEOXYGENATED);
382 m_SpectralUnmixingFilter->SetAlgorithm(mitk::pa::LinearSpectralUnmixingFilter::AlgortihmType::HOUSEHOLDERQR);
385 m_SpectralUnmixingFilter->Update();
388 m_SpectralUnmixingFilter->AddWavelength(300);
391 m_SpectralUnmixingFilter->Update();
394 m_SpectralUnmixingFilter->AddWavelength(299);
397 m_SpectralUnmixingFilter->Update();
403 void testNoChromophoresSelected()
405 MITK_INFO <<
"testNoChromophoresSelected";
408 m_SpectralUnmixingFilter->Verbose(
false);
409 m_SpectralUnmixingFilter->RelativeError(
false);
410 m_SpectralUnmixingFilter->SetInput(inputImage);
411 m_SpectralUnmixingFilter->AddOutputs(2);
414 for (
unsigned int imageIndex = 0; imageIndex < m_inputWavelengths.size(); imageIndex++)
416 unsigned int wavelength = m_inputWavelengths[imageIndex];
417 m_SpectralUnmixingFilter->AddWavelength(wavelength);
420 m_SpectralUnmixingFilter->SetAlgorithm(mitk::pa::LinearSpectralUnmixingFilter::AlgortihmType::HOUSEHOLDERQR);
423 m_SpectralUnmixingFilter->Update();
428 void testInputImage()
431 inputImage =
nullptr;
434 m_SpectralUnmixingFilter->Verbose(
false);
435 m_SpectralUnmixingFilter->RelativeError(
false);
437 m_SpectralUnmixingFilter->AddOutputs(2);
440 for (
unsigned int imageIndex = 0; imageIndex < m_inputWavelengths.size(); imageIndex++)
442 unsigned int wavelength = m_inputWavelengths[imageIndex];
443 m_SpectralUnmixingFilter->AddWavelength(wavelength);
446 m_SpectralUnmixingFilter->AddChromophore(
447 mitk::pa::PropertyCalculator::ChromophoreType::OXYGENATED);
448 m_SpectralUnmixingFilter->AddChromophore(
449 mitk::pa::PropertyCalculator::ChromophoreType::DEOXYGENATED);
451 m_SpectralUnmixingFilter->SetAlgorithm(mitk::pa::LinearSpectralUnmixingFilter::AlgortihmType::HOUSEHOLDERQR);
454 m_SpectralUnmixingFilter->Update();
459 const int NUMBER_OF_SPATIAL_DIMENSIONS = 3;
460 auto* dimensions =
new unsigned int[NUMBER_OF_SPATIAL_DIMENSIONS];
466 inputImage->Initialize(pixelType, NUMBER_OF_SPATIAL_DIMENSIONS, dimensions);
468 double* data =
new double[6];
475 inputImage->SetImportVolume(data, mitk::Image::ImportMemoryManagementType::CopyMemory);
478 m_SpectralUnmixingFilter->SetInput(inputImage);
481 m_SpectralUnmixingFilter->Update();
492 m_SpectralUnmixingFilter->Verbose(
false);
493 m_SpectralUnmixingFilter->RelativeError(
false);
494 m_SpectralUnmixingFilter->SetInput(inputImage);
497 for (
unsigned int imageIndex = 0; imageIndex < m_inputWavelengths.size(); imageIndex++)
499 unsigned int wavelength = m_inputWavelengths[imageIndex];
500 m_SpectralUnmixingFilter->AddWavelength(wavelength);
503 m_SpectralUnmixingFilter->AddChromophore(
504 mitk::pa::PropertyCalculator::ChromophoreType::OXYGENATED);
505 m_SpectralUnmixingFilter->AddChromophore(
506 mitk::pa::PropertyCalculator::ChromophoreType::DEOXYGENATED);
508 m_SpectralUnmixingFilter->SetAlgorithm(mitk::pa::LinearSpectralUnmixingFilter::AlgortihmType::HOUSEHOLDERQR);
510 for (
int i = 0; i < 4; ++i)
516 m_SpectralUnmixingFilter->AddOutputs(i);
517 m_SpectralUnmixingFilter->Update();
522 m_SpectralUnmixingFilter->AddOutputs(2);
523 m_SpectralUnmixingFilter->Update();
524 for (
int i = 0; i < 2; ++i)
528 const float* inputDataArray = ((
const float*)readAccess.GetData());
529 auto pixel = inputDataArray[0];
530 auto pixel2 = inputDataArray[1];
532 CPPUNIT_ASSERT(std::abs(pixel - m_CorrectResult[i]) < threshold);
533 CPPUNIT_ASSERT(std::abs(pixel2 - m_CorrectResult[i + 2]) < threshold);
540 void testWeightsError()
546 m_SpectralUnmixingFilter->Verbose(
false);
547 m_SpectralUnmixingFilter->RelativeError(
false);
548 m_SpectralUnmixingFilter->SetInput(inputImage);
549 m_SpectralUnmixingFilter->AddOutputs(2);
552 for (
unsigned int imageIndex = 0; imageIndex < m_inputWavelengths.size(); imageIndex++)
554 unsigned int wavelength = m_inputWavelengths[imageIndex];
555 m_SpectralUnmixingFilter->AddWavelength(wavelength);
558 m_SpectralUnmixingFilter->AddChromophore(
559 mitk::pa::PropertyCalculator::ChromophoreType::OXYGENATED);
560 m_SpectralUnmixingFilter->AddChromophore(
561 mitk::pa::PropertyCalculator::ChromophoreType::DEOXYGENATED);
563 m_SpectralUnmixingFilter->SetAlgorithm(mitk::pa::SpectralUnmixingFilterVigra::VigraAlgortihmType::WEIGHTED);
566 m_SpectralUnmixingFilter->Update();
569 m_SpectralUnmixingFilter->AddWeight(50);
571 m_SpectralUnmixingFilter->Update();
574 m_SpectralUnmixingFilter->AddWeight(50);
575 m_SpectralUnmixingFilter->Update();
577 for (
int i = 0; i < 2; ++i)
581 const float* inputDataArray = ((
const float*)readAccess.GetData());
582 auto pixel = inputDataArray[0];
583 auto pixel2 = inputDataArray[1];
585 CPPUNIT_ASSERT(std::abs(pixel - m_CorrectResult[i]) < threshold);
586 CPPUNIT_ASSERT(std::abs(pixel2 - m_CorrectResult[i + 2]) < threshold);
597 m_SpectralUnmixingFilter->Verbose(
false);
598 m_SpectralUnmixingFilter->RelativeError(
false);
599 m_SpectralUnmixingFilter->SetInput(inputImage);
600 m_SpectralUnmixingFilter->AddOutputs(2);
603 for (
unsigned int imageIndex = 0; imageIndex < m_inputWavelengths.size(); imageIndex++)
605 unsigned int wavelength = m_inputWavelengths[imageIndex];
606 m_SpectralUnmixingFilter->AddWavelength(wavelength);
609 m_SpectralUnmixingFilter->AddChromophore(
610 mitk::pa::PropertyCalculator::ChromophoreType::OXYGENATED);
611 m_SpectralUnmixingFilter->AddChromophore(
612 mitk::pa::PropertyCalculator::ChromophoreType::DEOXYGENATED);
614 m_SpectralUnmixingFilter->SetAlgorithm(mitk::pa::LinearSpectralUnmixingFilter::AlgortihmType::HOUSEHOLDERQR);
616 m_SpectralUnmixingFilter->Update();
618 for (
int i = 0; i < 2; ++i)
622 const float* inputDataArray = ((
const float*)readAccess.GetData());
623 auto pixel = inputDataArray[0];
624 auto pixel2 = inputDataArray[1];
626 CPPUNIT_ASSERT(std::abs(pixel - m_CorrectResult[i]) < threshold);
627 CPPUNIT_ASSERT(std::abs(pixel2 - m_CorrectResult[i + 2]) < threshold);
630 CPPUNIT_ASSERT(inputImage->GetDimensions()[0] == output->GetDimensions()[0]);
631 CPPUNIT_ASSERT(inputImage->GetDimensions()[0] == output->GetDimensions()[1]);
632 CPPUNIT_ASSERT(2 == output->GetDimensions()[2]);
633 CPPUNIT_ASSERT(output->GetPixelType() == mitk::MakeScalarPixelType<float>());
671 void tearDown()
override 673 m_SpectralUnmixingFilter =
nullptr;
674 inputImage =
nullptr;
675 m_inputWavelengths.clear();
676 m_CorrectResult.clear();
#define MITK_TEST_FOR_EXCEPTION_END(EXCEPTIONCLASS)
MITK_TEST_SUITE_REGISTRATION(mitkImageToItk)
#define MITK_TEST(TESTMETHOD)
Adds a test to the current test suite.
Test fixture for parameterized tests.
#define MITK_TEST_FOR_EXCEPTION_BEGIN(EXCEPTIONCLASS)
Begin block which should be checked for exceptions.
ImageReadAccessor class to get locked read access for a particular image part.
Class for defining the data type of pixels.