18 #ifndef __itkAddNoiseToDWIImageFilter_hxx 19 #define __itkAddNoiseToDWIImageFilter_hxx 29 template <
class TInputImage,
class TB0Image,
class TMaskImage>
33 this->SetNumberOfRequiredInputs(1);
39 template <
class TInputImage,
class TB0Image,
class TMaskImage>
44 Superclass::PrintSelf(os, indent);
47 PrintVar1(this->GetInput(), this->GetInput(), os<<indent <<
"dwi");
48 PrintVar1(this->GetB0Image(), this->GetB0Image(), os<<indent <<
"b0");
49 PrintVar1(this->GetMaskImage(), this->GetMaskImage(), os<<indent <<
"mask");
53 template<
class TInputImage,
class TB0Image,
class TMaskImage>
57 utlException(m_Sigma<=0,
"need to set sigma to generate noise");
59 typename InputImageType::ConstPointer inputPtr = this->GetInput();
60 typename MaskImageType::ConstPointer maskPtr = this->GetMaskImage();
61 typename MaskImageType::ConstPointer b0Ptr = this->GetB0Image();
64 typename InputImageType::Pointer outputPtr = this->GetOutput();
65 outputPtr->SetRequestedRegion(inputPtr->GetRequestedRegion());
66 outputPtr->SetBufferedRegion(inputPtr->GetBufferedRegion());
67 outputPtr->Allocate();
69 ImageRegionIterator<InputImageType> outputIt(outputPtr, outputPtr->GetLargestPossibleRegion());
70 ImageRegionConstIterator<InputImageType> inputIt(inputPtr, inputPtr->GetLargestPossibleRegion());
71 ImageRegionConstIterator<MaskImageType> maskIt;
74 maskIt = ImageRegionConstIterator<MaskImageType>(maskPtr, maskPtr->GetLargestPossibleRegion());
76 itk::ImageRegionConstIterator<B0ImageType> b0It;
78 b0It = ImageRegionConstIterator<B0ImageType>(b0Ptr, b0Ptr->GetLargestPossibleRegion());
86 zeroPixel.SetSize(inputPtr->GetNumberOfComponentsPerPixel());
89 double realSigma = m_Sigma;
91 while(!outputIt.IsAtEnd())
93 if ((!maskPtr || (maskPtr && maskIt.Get()>0) )
94 && (!b0Ptr || (b0Ptr && b0It.Get()>0)))
96 pixel = inputIt.Get();
98 realSigma = m_Sigma * b0It.Get();
99 if (m_Noisetype==GAUSSIAN)
100 pixel = utl::AddNoise<PixelType>(pixel, pixel.GetSize(), realSigma,
false);
101 if (m_Noisetype==RICIAN)
102 pixel = utl::AddNoise<PixelType>(pixel, pixel.GetSize(), realSigma,
true);
106 outputIt.Set(zeroPixel);
#define PrintVar1(cond, var, os)
helper functions specifically used in dmritool
InputImageType::PixelType PixelType
#define utlException(cond, expout)
void PrintSelf(std::ostream &os, Indent indent) const ITK_OVERRIDE
AddNoiseToDWIImageFilter()
virtual void GenerateData() ITK_OVERRIDE