Medical Imaging Interaction Toolkit  2018.4.99-1bab67a2
Medical Imaging Interaction Toolkit
mitkMultiComponentImageDataComparisonFilter.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 // mitk includes
16 #include "mitkImageReadAccessor.h"
17 
18 // other includes
19 // #include <omp.h>
20 
21 namespace mitk
22 {
24  : ImageToImageFilter(), m_Tolerance(0.0f), m_CompareResult(false), m_CompareDetails(nullptr)
25  {
26  this->SetNumberOfRequiredInputs(2);
27  }
28 
31  {
32  if (!m_CompareResult)
33  {
34  return false;
35  }
36 
38  {
39  return false;
40  }
41 
42  return true;
43  }
44 
50  {
51  m_CompareDetails = results;
52  }
53 
56  {
57  // check inputs
58  const Image *testInput = this->GetTestImage();
59  const Image *validInput = this->GetValidImage();
60 
61  // Generally this filter is part of the mitk::Image::Equal() method and only checks the equality of the image data
62  // so no further image type comparison is performed!
63  // CAVE: If the images differ in a parameter other then the image data, the filter may fail!!
64 
65  PixelType type = validInput->GetPixelType();
66 
67  if (type.GetComponentType() == itk::ImageIOBase::CHAR)
68  {
69  CompareMultiComponentImage<char>(testInput, validInput);
70  }
71  else if (type.GetComponentType() == itk::ImageIOBase::UCHAR)
72  {
73  CompareMultiComponentImage<unsigned char>(testInput, validInput);
74  }
75  else if (type.GetComponentType() == itk::ImageIOBase::INT)
76  {
77  CompareMultiComponentImage<int>(testInput, validInput);
78  }
79  else if (type.GetComponentType() == itk::ImageIOBase::UINT)
80  {
81  CompareMultiComponentImage<unsigned int>(testInput, validInput);
82  }
83  else if (type.GetComponentType() == itk::ImageIOBase::SHORT)
84  {
85  CompareMultiComponentImage<short>(testInput, validInput);
86  }
87  else if (type.GetComponentType() == itk::ImageIOBase::USHORT)
88  {
89  CompareMultiComponentImage<unsigned short>(testInput, validInput);
90  }
91  else if (type.GetComponentType() == itk::ImageIOBase::LONG)
92  {
93  CompareMultiComponentImage<long>(testInput, validInput);
94  }
95  else if (type.GetComponentType() == itk::ImageIOBase::ULONG)
96  {
97  CompareMultiComponentImage<unsigned long>(testInput, validInput);
98  }
99  else if (type.GetComponentType() == itk::ImageIOBase::FLOAT)
100  {
101  CompareMultiComponentImage<float>(testInput, validInput);
102  }
103  else if (type.GetComponentType() == itk::ImageIOBase::DOUBLE)
104  {
105  CompareMultiComponentImage<double>(testInput, validInput);
106  }
107  else
108  {
109  mitkThrow() << "Pixel component type not supported!";
110  }
111  }
112 
113  template <typename TPixel>
115  const Image *validImage)
116  {
117  unsigned int noOfTimes = validImage->GetDimension(3);
118  unsigned int noOfPixels = validImage->GetDimension(0) * validImage->GetDimension(1) * validImage->GetDimension(2);
119  unsigned int noOfComponents = validImage->GetPixelType().GetNumberOfComponents();
120 
121  for (unsigned int t = 0; t < noOfTimes; ++t)
122  {
123  ImageReadAccessor readAccTImage(testImage, testImage->GetVolumeData(t));
124  ImageReadAccessor readAccVImage(validImage, validImage->GetVolumeData(t));
125 
126  for (unsigned int p = 0; p < noOfPixels * noOfComponents; ++p)
127  {
128  TPixel vDataItem = static_cast<TPixel *>(const_cast<void *>(readAccVImage.GetData()))[p];
129  TPixel tDataItem = static_cast<TPixel *>(const_cast<void *>(readAccTImage.GetData()))[p];
130 
131  if (std::abs(static_cast<double>(tDataItem - vDataItem)) > m_Tolerance)
132  {
134 
136  std::max(m_CompareDetails->m_MaximumDifference, std::abs(static_cast<double>(tDataItem - vDataItem)));
137 
138  double min =
139  std::min(m_CompareDetails->m_MinimumDifference, std::abs(static_cast<double>(tDataItem - vDataItem)));
140 
141  if (min != 0.0f) // a difference of zero is not a difference!
143 
144  m_CompareDetails->m_TotalDifference += std::abs(static_cast<double>(tDataItem - vDataItem));
145  }
146  }
147  }
149  {
152  m_CompareResult = false;
153  }
154  else
155  {
156  m_CompareResult = true;
157  }
159  }
160 
161 } // end namespace mitk
const mitk::PixelType GetPixelType(int n=0) const
Returns the PixelType of channel n.
Definition: mitkImage.cpp:101
vcl_size_t GetNumberOfComponents() const
Get the number of components of which each element consists.
virtual void SetInput(const InputImageType *image)
DataCollection - Class to facilitate loading/accessing structured data.
void CompareMultiComponentImage(const Image *testImage, const Image *validImage)
int GetComponentType() const
Get the component type (the scalar (!) type). Each element may contain m_NumberOfComponents (more tha...
unsigned int GetDimension() const
Get dimension of the image.
Definition: mitkImage.cpp:106
#define mitkThrow()
virtual ImageDataItemPointer GetVolumeData(int t=0, int n=0, void *data=nullptr, ImportMemoryManagementType importMemoryManagement=CopyMemory) const
Definition: mitkImage.cpp:326
Image class for storing images.
Definition: mitkImage.h:72
A simple struct to hold the result of the comparison filter.
static T max(T x, T y)
Definition: svm.cpp:56
Superclass of all classes having one or more Images as input and generating Images as output...
static T min(T x, T y)
Definition: svm.cpp:53
InputImageType * GetInput(void)
ImageReadAccessor class to get locked read access for a particular image part.
Class for defining the data type of pixels.
Definition: mitkPixelType.h:51