Medical Imaging Interaction Toolkit  2018.4.99-eed36131
Medical Imaging Interaction Toolkit
mitkPhotoacousticNoiseGeneratorTest.cpp
Go to the documentation of this file.
1 /*============================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center (DKFZ)
6 All rights reserved.
7 
8 Use of this source code is governed by a 3-clause BSD license that can be
9 found in the LICENSE file.
10 
11 ============================================================================*/
12 
13 #include <mitkTestFixture.h>
14 #include <mitkTestingMacros.h>
15 
16 #include <mitkImageReadAccessor.h>
17 
18 #include "mitkPAVolume.h"
19 #include "mitkPANoiseGenerator.h"
20 
21 class mitkPhotoacousticNoiseGeneratorTestSuite : public mitk::TestFixture
22 {
23  CPPUNIT_TEST_SUITE(mitkPhotoacousticNoiseGeneratorTestSuite);
24  MITK_TEST(testNoiseGenerator);
25  CPPUNIT_TEST_SUITE_END();
26 
27 private:
28 
29 public:
30 
31  mitk::pa::Volume::Pointer m_Volume;
32 
33  void setUp() override
34  {
35  }
36 
37  void testNoiseGenerator()
38  {
39  int size = 1000 * 100 * 100;
40  auto* volume = new double[size];
41  for (int i = 0; i < size; i++)
42  {
43  volume[i] = 1;
44  }
45  m_Volume = mitk::pa::Volume::New(volume, 1000, 100, 100, 1);
46  mitk::pa::NoiseGenerator::ApplyNoiseModel(m_Volume, 0.75, 0.1);
47 
48  int negativecounter = 0;
49 
50  for (int i = 0; i < size; i++)
51  {
52  if (m_Volume->GetData()[i] <= 0)
53  {
54  negativecounter++;
55  }
56  }
57  CPPUNIT_ASSERT_EQUAL_MESSAGE("More than one negative: " +
58  std::to_string(negativecounter) + " (" +
59  std::to_string((((double)negativecounter) / size) * 100) + "%)", negativecounter, 0);
60  }
61 
62  void tearDown() override
63  {
64  }
65 };
66 
67 MITK_TEST_SUITE_REGISTRATION(mitkPhotoacousticNoiseGenerator)
MITK_TEST_SUITE_REGISTRATION(mitkImageToItk)
#define MITK_TEST(TESTMETHOD)
Adds a test to the current test suite.
Test fixture for parameterized tests.
static void ApplyNoiseModel(mitk::pa::Volume::Pointer image, double detectorNoise, double speckleNoise)
ApplyNoiseModel Applies noise to an image.
static Volume::Pointer New(double *data, unsigned int xDim, unsigned int yDim, unsigned int zDim, double spacing)
returns smartpointer reference to a new instance of this objects. The given data array will be freed ...