DMRITool  v0.1.1-139-g860d86b4
Diffusion MRI Tool
CorrectBValues.cxx
Go to the documentation of this file.
1 
18 #include "utlCore.h"
19 #include "CorrectBValuesCLP.h"
20 
21 
28 int
29 main (int argc, char const* argv[])
30 {
31 
32  // GenerateCLP
33  PARSE_ARGS;
34 
35  typedef std::vector<double> STDVectorType;
36  STDVectorType bVector;
37  std::cout << "Read b values from " << _InputFile << std::endl << std::flush;
38  utl::ReadVector(_InputFile,bVector);
39 
40  std::vector<STDVectorType> bVectors;
41  std::vector<std::vector<int> > bIndices;
42  STDVectorType bMax, bMin;
43  for ( int i = 0; i < bVector.size(); i += 1 )
44  {
45  double b = bVector[i];
46  int j=0;
47  for ( j = 0; j < bVectors.size(); j += 1 )
48  {
49  if (b>=bMin[j]-_BThreshold && b<=bMax[j]+_BThreshold)
50  {
51  bVectors[j].push_back(b);
52  bIndices[j].push_back(i);
53  if (b<bMin[j])
54  bMin[j] = b;
55  else if (b>bMax[j])
56  bMax[j] = b;
57  break;
58  }
59  }
60  if (j==bVectors.size())
61  {
62  STDVectorType bVecTemp;
63  bVecTemp.push_back(b);
64  bVectors.push_back(bVecTemp);
65  std::vector<int> bIndexTemp;
66  bIndexTemp.push_back(i);
67  bIndices.push_back(bIndexTemp);
68  bMin.push_back(b);
69  bMax.push_back(b);
70  }
71  }
72 
73  for ( int j = 0; j < bVectors.size(); j += 1 )
74  {
75  utlAssert(bMax[j]-bMin[j]<100.0, "the range of b values is larger than 100, which can not be in the same shell");
76  std::cout << "shell " << j << ": bMin=" << bMin[j] << " ,bMax=" << bMax[j] << ", " << bVectors[j].size() << " b values." << std::endl << std::flush;
77  double bMean=0;
78  for ( int k = 0; k < bVectors[j].size(); k += 1 )
79  bMean += bVectors[j][k];
80  bMean /= bVectors[j].size();
81  if (bMean<_BThreshold)
82  bMean=0.0;
83  for ( int k = 0; k < bVectors[j].size(); k += 1 )
84  {
85  bVector[bIndices[j][k] ] = bMean;
86  }
87  }
88 
89  std::cout << "Save corrected b values to " << _OutputFile << std::endl << std::flush;
90  utl::SaveVector(bVector, _OutputFile);
91 
92  return 0;
93 }
void SaveVector(const VectorType &vv, const int NSize, const std::string &vectorStr, const bool is_save_number=false)
Definition: utlCore.h:1213
int main(int argc, char const *argv[])
b values whose distance is smallter the threshold will be considered in the same shell, and they will be replaced as their mean b value.
void ReadVector(const std::string &vectorStr, std::vector< T > &vec, const char *cc=" ")
Definition: utlCore.h:1159
#define utlAssert(cond, expout)
Definition: utlCoreMacro.h:550