diff --git a/Modules/DiffusionImaging/DiffusionCore/Testing/files.cmake b/Modules/DiffusionImaging/DiffusionCore/Testing/files.cmake index 140722ceaa..1636461432 100644 --- a/Modules/DiffusionImaging/DiffusionCore/Testing/files.cmake +++ b/Modules/DiffusionImaging/DiffusionCore/Testing/files.cmake @@ -1,11 +1,12 @@ set(MODULE_TESTS mitkFactoryRegistrationTest.cpp mitkDiffusionImageEqualTest.cpp ) set(MODULE_CUSTOM_TESTS mitkPyramidImageRegistrationMethodTest.cpp mitkDWHeadMotionCorrectionTest.cpp mitkImageReconstructionTest.cpp + itkNonLocalMeansDenoisingTest.cpp ) diff --git a/Modules/DiffusionImaging/DiffusionCore/Testing/itkNonLocalMeansDenoisingTest.cpp b/Modules/DiffusionImaging/DiffusionCore/Testing/itkNonLocalMeansDenoisingTest.cpp new file mode 100644 index 0000000000..71694b4f44 --- /dev/null +++ b/Modules/DiffusionImaging/DiffusionCore/Testing/itkNonLocalMeansDenoisingTest.cpp @@ -0,0 +1,124 @@ +/*=================================================================== + +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 "mitkDiffusionImage.h" +#include "mitkIOUtil.h" +#include "mitkTestingMacros.h" +#include "mitkTestFixture.h" +#include "itkNonLocalMeansDenoisingFilter.h" + +class itkNonLocalMeansDenoisingTestSuite : public mitk::TestFixture +{ + + CPPUNIT_TEST_SUITE(itkNonLocalMeansDenoisingTestSuite); + MITK_TEST(Denoise_NLMr_1_1_shouldReturnTrue); + MITK_TEST(Denoise_NLMv_1_1_1_shouldReturnTrue); + CPPUNIT_TEST_SUITE_END(); + +private: + + /** Members used inside the different (sub-)tests. All members are initialized via setUp().*/ + mitk::DiffusionImage::Pointer m_Image; + mitk::DiffusionImage::Pointer m_ReferenceImage; + mitk::DiffusionImage::Pointer m_DenoisedImage; + itk::Image::Pointer m_ImageMask; + itk::NonLocalMeansDenoisingFilter::Pointer m_DenoisingFilter; + +public: + + /** +* @brief Setup Always call this method before each Test-case to ensure correct and new intialization of the used members for a new test case. (If the members are not used in a test, the method does not need to be called). +*/ + void setUp() + { + //generate test images + std::string imagePath = GetTestDataFilePath("DiffusionImaging/Denoising/test_multi.dwi"); + std::string maskPath = GetTestDataFilePath("DiffusionImaging/Denoising/denoising_mask.nrrd"); + + m_Image = static_cast*>( mitk::IOUtil::LoadImage(imagePath).GetPointer()); + mitk::Image::Pointer imageMask = static_cast( mitk::IOUtil::LoadImage(maskPath).GetPointer()); + mitk::CastToItkImage(imageMask, m_ImageMask); + m_ReferenceImage = NULL; + m_DenoisedImage = mitk::DiffusionImage::New(); + + //initialise Filter + m_DenoisingFilter = itk::NonLocalMeansDenoisingFilter::New(); + m_DenoisingFilter->SetInputImage(m_Image->GetVectorImage()); + m_DenoisingFilter->SetInputMask(m_ImageMask); + m_DenoisingFilter->SetNumberOfThreads(1); + m_DenoisingFilter->SetComparisonRadius(1); + m_DenoisingFilter->SetSearchRadius(1); + } + + void tearDown() + { + m_Image = NULL; + m_ImageMask = NULL; + m_ReferenceImage = NULL; + m_DenoisingFilter = NULL; + m_DenoisedImage = NULL; + } + + void Denoise_NLMr_1_1_shouldReturnTrue() + { + std::string referenceImagePath = GetTestDataFilePath("DiffusionImaging/Denoising/test_multi_NLMr_1-1.dwi"); + m_ReferenceImage = static_cast*>( mitk::IOUtil::LoadImage(referenceImagePath).GetPointer()); + + m_DenoisingFilter->SetUseJointInformation(false); + try + { + m_DenoisingFilter->Update(); + } + catch(std::exception& e) + { + MITK_ERROR << e.what(); + } + + m_DenoisedImage->SetVectorImage(m_DenoisingFilter->GetOutput()); + m_DenoisedImage->SetReferenceBValue(m_Image->GetReferenceBValue()); + m_DenoisedImage->SetDirections(m_Image->GetDirections()); + m_DenoisedImage->InitializeFromVectorImage(); + + MITK_ASSERT_EQUAL( m_DenoisedImage, m_ReferenceImage, "NLMr should always return the same result."); + } + + void Denoise_NLMv_1_1_1_shouldReturnTrue() + { + std::string referenceImagePath = GetTestDataFilePath("DiffusionImaging/Denoising/test_multi_NLMv_1-1-1.dwi"); + m_ReferenceImage = static_cast*>( mitk::IOUtil::LoadImage(referenceImagePath).GetPointer()); + + m_DenoisingFilter->SetChannelRadius(1); + m_DenoisingFilter->SetUseJointInformation(true); + try + { + m_DenoisingFilter->Update(); + } + catch(std::exception& e) + { + MITK_ERROR << e.what(); + } + + m_DenoisedImage->SetVectorImage(m_DenoisingFilter->GetOutput()); + m_DenoisedImage->SetReferenceBValue(m_Image->GetReferenceBValue()); + m_DenoisedImage->SetDirections(m_Image->GetDirections()); + m_DenoisedImage->InitializeFromVectorImage(); + + MITK_ASSERT_EQUAL( m_DenoisedImage, m_ReferenceImage, "NLMv should always return the same result."); + } + +}; + +MITK_TEST_SUITE_REGISTRATION(itkNonLocalMeansDenoising)