Medical Imaging Interaction Toolkit  2018.4.99-4c24e3cb
Medical Imaging Interaction Toolkit
mitkConvolutionHelper.h
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 #ifndef mitkConvolutionHelper_h
13 #define mitkConvolutionHelper_h
14 
15 #include "itkArray.h"
16 #include "mitkAIFBasedModelBase.h"
17 #include <iostream>
19 
20 namespace mitk {
26  namespace convolution {
27 
35 inline itk::Array<double> wrap1d(itk::Array<double> kernel)
36  {
37  int dim = kernel.GetNumberOfElements();
38  itk::Array<double> wrappedKernel(dim);
39  wrappedKernel.fill(0.);
40  for(int i=0; i< dim; ++i)
41  {
42  wrappedKernel.SetElement(i, kernel.GetElement((i+(dim/2))%dim));
43  }
44 
45  return wrappedKernel;
46  }
47 
53  inline itk::Array<double> zeropadding1d(itk::Array<double> unpaddedSpectrum, int paddedDimension)
54  {
55 
56  int initialDimension = unpaddedSpectrum.GetNumberOfElements();
57 
58  itk::Array<double> paddedSpectrum(paddedDimension);
59  paddedSpectrum.fill(0.);
60 
61  if(paddedDimension > initialDimension)
62  {
63  unsigned int padding = paddedDimension - initialDimension;
64 
65  for(int i=0; i<initialDimension ;++i)
66  {
67  paddedSpectrum.SetElement(i+padding/2, unpaddedSpectrum.GetElement(i));
68  }
69  }
70  return paddedSpectrum;
71  }
72 
75  inline itk::Array<double> unpadAndScale(itk::Array<double> convolutionResult, int initialDimension)
76  {
77  int transformationDimension = convolutionResult.size();
78  unsigned int padding = transformationDimension - initialDimension;
79 
80  itk::Array<double> scaledResult(initialDimension);
81  scaledResult.fill(0.0);
82 
83  for(int i = 0; i<initialDimension; ++i)
84  {
85  double value = convolutionResult(i+padding/2) / transformationDimension;
86  scaledResult.SetElement(i,value);
87  }
88  return scaledResult;
89  }
95  inline void prepareConvolution(const itk::Array<double>& kernel, const itk::Array<double>& spectrum, itk::Array<double>& preparedKernel, itk::Array<double>& preparedSpectrum ){
96  int convolutionDimensions = kernel.GetSize() + spectrum.GetSize();
97 
98 // itk::Array<double> paddedKernel = zeropadding1d(kernel,convolutionDimensions);
99  preparedKernel=zeropadding1d(kernel,convolutionDimensions);
100 
101  preparedSpectrum = zeropadding1d(spectrum,convolutionDimensions);
102 // preparedKernel = wrap1d(paddedKernel);
103  }
104 
105  }
106 
108  {
111  typedef itk::Array<double> ConvolutionResultType;
112  ConvolutionResultType convolution(timeGrid.GetSize());
113  convolution.fill(0.0);
114 
115  convolution(0) = 0;
116  for(unsigned int i = 0; i< (timeGrid.GetSize()-1); ++i)
117  {
118  double dt = timeGrid(i+1) - timeGrid(i);
119  double m = (aif(i+1) - aif(i))/dt;
120  double edt = exp(-lambda *dt);
121 
122  convolution(i+1) =edt * convolution(i)
123  + (aif(i) - m*timeGrid(i))/lambda * (1 - edt )
124  + m/(lambda * lambda) * ((lambda * timeGrid(i+1) - 1) - edt*(lambda*timeGrid(i) -1));
125 
126  }
127  return convolution;
128  }
129 
130 
132  {
135  typedef itk::Array<double> ConvolutionResultType;
136  ConvolutionResultType convolution(timeGrid.GetSize());
137  convolution.fill(0.0);
138 
139  convolution(0) = 0;
140  for(unsigned int i = 0; i< (timeGrid.GetSize()-1); ++i)
141  {
142  double dt = timeGrid(i+1) - timeGrid(i);
143  double m = (aif(i+1) - aif(i))/dt;
144 
145  convolution(i+1) = convolution(i) + constant * (aif(i)*dt + m*timeGrid(i)*dt + m/2*(timeGrid(i+1)*timeGrid(i+1) - timeGrid(i)*timeGrid(i)));
146 
147  }
148  return convolution;
149  }
150 
151 }
152 
153 #endif // mitkConvolutionHelper_h
Helper for itk implementation of vnl fourier transformation This namespace provides functions for the...
DataCollection - Class to facilitate loading/accessing structured data.
itk::Array< double > TimeGridType
Definition: mitkModelBase.h:62
itk::Array< double > zeropadding1d(itk::Array< double > unpaddedSpectrum, int paddedDimension)
Fuction for zeropadding (adding zeros) of an Array/vnl_vector, so that is has size paddedDimensions...
itk::Array< double > convoluteAIFWithConstant(mitk::ModelBase::TimeGridType timeGrid, mitk::AIFBasedModelBase::AterialInputFunctionType aif, double constant)
itk::Array< double > wrap1d(itk::Array< double > kernel)
Function that wraps the kernel.
itk::Array< double > unpadAndScale(itk::Array< double > convolutionResult, int initialDimension)
Follow up function after back transformation from fourier space bwd_transform. removes padding and sc...
void prepareConvolution(const itk::Array< double > &kernel, const itk::Array< double > &spectrum, itk::Array< double > &preparedKernel, itk::Array< double > &preparedSpectrum)
Convinience function for preparing 2 array for convolution with each other. Takes both arrays of type...
itk::Array< double > AterialInputFunctionType
itk::Array< double > convoluteAIFWithExponential(mitk::ModelBase::TimeGridType timeGrid, mitk::AIFBasedModelBase::AterialInputFunctionType aif, double lambda)