DMRITool  v0.1.1-139-g860d86b4
Diffusion MRI Tool
DWINoiseGenerator.cxx
Go to the documentation of this file.
1 
19 #include "utl.h"
21 
22 #include "DWINoiseGeneratorCLP.h"
23 
27 int
28 main (int argc, char const* argv[])
29 {
30 
31  // GenerateCLP
32  PARSE_ARGS;
33 
34  // Time Probe
35  itk::TimeProbe clock;
36 
37  // Input and Output Image Types
38  typedef itk::VectorImage<double, 3> ImageType;
39 
40  typedef itk::Image<double, 3> MaskImageType;
41  typedef itk::Image<double, 3> B0ImageType;
42 
43  ImageType::Pointer dwi;
44  ImageType::Pointer dwiNoise;
45  B0ImageType::Pointer b0;
46  MaskImageType::Pointer mask;
47 
49  AddNoiseFilterType::Pointer addNoiseFilter = AddNoiseFilterType::New();
50 
51  itk::ReadVectorImage<double>(_InputFile, dwi);
52  // utlPrintVar1(true, dwi->GetSpacing());
53  addNoiseFilter->SetInput(dwi);
54  if (_b0FileArg.isSet())
55  {
56  itk::ReadImage<B0ImageType>(_b0File, b0);
57  // utlPrintVar1(true, b0->GetSpacing());
58  addNoiseFilter->SetB0Image(b0);
59  }
60  if (_maskFileArg.isSet())
61  {
62  itk::ReadImage<MaskImageType>(_maskFile, mask);
63  addNoiseFilter->SetMaskImage(mask);
64  }
65 
66  utlException(_NoiseSigmaArg.isSet() && _SNRArg.isSet(), "Only one of these is allowed: --noisesigma or --snr");
67  utlException(!_NoiseSigmaArg.isSet() && !_SNRArg.isSet(), "Set --noisesigma or --snr");
68  if (_NoiseSigmaArg.isSet())
69  addNoiseFilter->SetSigma(_NoiseSigma);
70  if (_SNRArg.isSet())
71  addNoiseFilter->SetSigma(1.0/_SNR);
72 
73  if (_Noisetype=="GAUSSIAN")
74  addNoiseFilter->SetNoisetype(AddNoiseFilterType::GAUSSIAN);
75  if (_Noisetype=="RICIAN")
76  addNoiseFilter->SetNoisetype(AddNoiseFilterType::RICIAN);
77 
78  // Generate NoiseGenerate
79  // addNoiseFilter->Print(std::cout<<"addNoiseFilter\n");
80  addNoiseFilter->Update();
81 
82  dwiNoise = addNoiseFilter->GetOutput();
83  itk::SaveImage<ImageType>(dwiNoise,_OutputFile);
84 
85 
86  return EXIT_SUCCESS;
87 }
helper functions specifically used in dmritool
#define utlException(cond, expout)
Definition: utlCoreMacro.h:548
int main(int argc, char const *argv[])
add Gaussian or Rician noise to DWI data