Medical Imaging Interaction Toolkit  2024.06.99-60d9b802
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
mitk::AIFBasedModelBase::AterialInputFunctionType
itk::Array< double > AterialInputFunctionType
Definition: mitkAIFBasedModelBase.h:62
mitk::convoluteAIFWithConstant
itk::Array< double > convoluteAIFWithConstant(mitk::ModelBase::TimeGridType timeGrid, mitk::AIFBasedModelBase::AterialInputFunctionType aif, double constant)
Definition: mitkConvolutionHelper.h:132
mitkAIFBasedModelBase.h
mitk::convolution::zeropadding1d
itk::Array< double > zeropadding1d(itk::Array< double > unpaddedSpectrum, int paddedDimension)
Function for zeropadding (adding zeros) of an Array/vnl_vector, so that is has size paddedDimensions.
Definition: mitkConvolutionHelper.h:54
MitkPharmacokineticsExports.h
mitk::convolution::unpadAndScale
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...
Definition: mitkConvolutionHelper.h:76
mitk
Find image slices visible on a given plane.
Definition: RenderingTests.dox:1
mitk::convolution::prepareConvolution
void prepareConvolution(const itk::Array< double > &kernel, const itk::Array< double > &spectrum, itk::Array< double > &preparedKernel, itk::Array< double > &preparedSpectrum)
Convenience function for preparing 2 array for convolution with each other. Takes both arrays of type...
Definition: mitkConvolutionHelper.h:96
mitk::convoluteAIFWithExponential
itk::Array< double > convoluteAIFWithExponential(mitk::ModelBase::TimeGridType timeGrid, mitk::AIFBasedModelBase::AterialInputFunctionType aif, double lambda)
Definition: mitkConvolutionHelper.h:108
mitk::convolution::wrap1d
itk::Array< double > wrap1d(itk::Array< double > kernel)
Function that wraps the kernel.
Definition: mitkConvolutionHelper.h:35
convolution
Helper for itk implementation of vnl fourier transformation This namespace provides functions for the...
mitk::ModelBase::TimeGridType
itk::Array< double > TimeGridType
Definition: mitkModelBase.h:62