12 #ifndef mitkConvolutionHelper_h
13 #define mitkConvolutionHelper_h
35 inline itk::Array<double>
wrap1d(itk::Array<double> kernel)
37 int dim = kernel.GetNumberOfElements();
38 itk::Array<double> wrappedKernel(dim);
39 wrappedKernel.fill(0.);
40 for(
int i=0; i< dim; ++i)
42 wrappedKernel.SetElement(i, kernel.GetElement((i+(dim/2))%dim));
54 inline itk::Array<double>
zeropadding1d(itk::Array<double> unpaddedSpectrum,
int paddedDimension)
57 int initialDimension = unpaddedSpectrum.GetNumberOfElements();
59 itk::Array<double> paddedSpectrum(paddedDimension);
60 paddedSpectrum.fill(0.);
62 if(paddedDimension > initialDimension)
64 unsigned int padding = paddedDimension - initialDimension;
66 for(
int i=0; i<initialDimension ;++i)
68 paddedSpectrum.SetElement(i+padding/2, unpaddedSpectrum.GetElement(i));
71 return paddedSpectrum;
76 inline itk::Array<double>
unpadAndScale(itk::Array<double> convolutionResult,
int initialDimension)
78 int transformationDimension = convolutionResult.size();
79 unsigned int padding = transformationDimension - initialDimension;
81 itk::Array<double> scaledResult(initialDimension);
82 scaledResult.fill(0.0);
84 for(
int i = 0; i<initialDimension; ++i)
86 double value = convolutionResult(i+padding/2) / transformationDimension;
87 scaledResult.SetElement(i,value);
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();
102 preparedSpectrum =
zeropadding1d(spectrum,convolutionDimensions);
112 typedef itk::Array<double> ConvolutionResultType;
113 ConvolutionResultType
convolution(timeGrid.GetSize());
117 for(
unsigned int i = 0; i< (timeGrid.GetSize()-1); ++i)
119 double dt = timeGrid(i+1) - timeGrid(i);
120 double m = (aif(i+1) - aif(i))/dt;
121 double edt = exp(-lambda *dt);
124 + (aif(i) - m*timeGrid(i))/lambda * (1 - edt )
125 + m/(lambda * lambda) * ((lambda * timeGrid(i+1) - 1) - edt*(lambda*timeGrid(i) -1));
136 typedef itk::Array<double> ConvolutionResultType;
137 ConvolutionResultType
convolution(timeGrid.GetSize());
141 for(
unsigned int i = 0; i< (timeGrid.GetSize()-1); ++i)
143 double dt = timeGrid(i+1) - timeGrid(i);
144 double m = (aif(i+1) - aif(i))/dt;
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)));