Medical Imaging Interaction Toolkit  2018.04.99-def61b42
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 
54  inline itk::Array<double> zeropadding1d(itk::Array<double> unpaddedSpectrum, int paddedDimension)
55  {
56 
57  int initialDimension = unpaddedSpectrum.GetNumberOfElements();
58 
59  itk::Array<double> paddedSpectrum(paddedDimension);
60  paddedSpectrum.fill(0.);
61 
62  if(paddedDimension > initialDimension)
63  {
64  unsigned int padding = paddedDimension - initialDimension;
65 
66  for(int i=0; i<initialDimension ;++i)
67  {
68  paddedSpectrum.SetElement(i+padding/2, unpaddedSpectrum.GetElement(i));
69  }
70  }
71  return paddedSpectrum;
72  }
73 
76  inline itk::Array<double> unpadAndScale(itk::Array<double> convolutionResult, int initialDimension)
77  {
78  int transformationDimension = convolutionResult.size();
79  unsigned int padding = transformationDimension - initialDimension;
80 
81  itk::Array<double> scaledResult(initialDimension);
82  scaledResult.fill(0.0);
83 
84  for(int i = 0; i<initialDimension; ++i)
85  {
86  double value = convolutionResult(i+padding/2) / transformationDimension;
87  scaledResult.SetElement(i,value);
88  }
89  return scaledResult;
90  }
96  inline void prepareConvolution(const itk::Array<double>& kernel, const itk::Array<double>& spectrum, itk::Array<double>& preparedKernel, itk::Array<double>& preparedSpectrum ){
97  int convolutionDimensions = kernel.GetSize() + spectrum.GetSize();
98 
99 // itk::Array<double> paddedKernel = zeropadding1d(kernel,convolutionDimensions);
100  preparedKernel=zeropadding1d(kernel,convolutionDimensions);
101 
102  preparedSpectrum = zeropadding1d(spectrum,convolutionDimensions);
103 // preparedKernel = wrap1d(paddedKernel);
104  }
105 
106  }
107 
109  {
112  typedef itk::Array<double> ConvolutionResultType;
113  ConvolutionResultType convolution(timeGrid.GetSize());
114  convolution.fill(0.0);
115 
116  convolution(0) = 0;
117  for(unsigned int i = 0; i< (timeGrid.GetSize()-1); ++i)
118  {
119  double dt = timeGrid(i+1) - timeGrid(i);
120  double m = (aif(i+1) - aif(i))/dt;
121  double edt = exp(-lambda *dt);
122 
123  convolution(i+1) =edt * convolution(i)
124  + (aif(i) - m*timeGrid(i))/lambda * (1 - edt )
125  + m/(lambda * lambda) * ((lambda * timeGrid(i+1) - 1) - edt*(lambda*timeGrid(i) -1));
126 
127  }
128  return convolution;
129  }
130 
131 
133  {
136  typedef itk::Array<double> ConvolutionResultType;
137  ConvolutionResultType convolution(timeGrid.GetSize());
138  convolution.fill(0.0);
139 
140  convolution(0) = 0;
141  for(unsigned int i = 0; i< (timeGrid.GetSize()-1); ++i)
142  {
143  double dt = timeGrid(i+1) - timeGrid(i);
144  double m = (aif(i+1) - aif(i))/dt;
145 
146  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)));
147 
148  }
149  return convolution;
150  }
151 
152 }
153 
154 #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)