RISA
interpolationFunctions.h
Go to the documentation of this file.
1 /*
2  * This file is part of the RISA-library.
3  *
4  * Copyright (C) 2016 Helmholtz-Zentrum Dresden-Rossendorf
5  *
6  * RISA is free software: You can redistribute it and/or modify
7  * it under the terms of the GNU Lesser General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * RISA is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with RISA. If not, see <http://www.gnu.org/licenses/>.
18  *
19  * Date: 30 November 2016
20  * Authors: Tobias Frust (FWCC) <t.frust@hzdr.de>
21  *
22  */
23 #ifndef INTERPOLATIONFUNCTIONS_H_
24 #define INTERPOLATIONFUNCTIONS_H_
25 
26 #include <vector>
27 
28 template <typename T>
29 auto findDefectDetectors(T* data, std::vector<double>& filterFunction, std::vector<int>& defectDetectors,
30  unsigned int numberOfDetectors, unsigned int numberOfProjections, double threshMin,
31  double threshMax) -> void {
32 
33  std::vector<double> var(numberOfDetectors, 0.0);
34  unsigned int scale = 2;
35 
36  for(auto detInd = 0u; detInd < numberOfDetectors; detInd++){
37  double varMax = data[detInd];
38  double varMin = varMax;
39  for(auto projInd = 0u; projInd < numberOfProjections - 1; projInd++){
40  var[detInd] += std::abs((double)data[detInd + projInd*numberOfDetectors] - (double)data[detInd + (projInd+1)*numberOfDetectors]);
41  if(data[detInd + projInd*numberOfDetectors] > varMax)
42  varMax = (double)data[detInd + projInd*numberOfDetectors];
43  if(data[detInd + projInd*numberOfDetectors] < varMin)
44  varMin = (double)data[detInd + projInd*numberOfDetectors];
45  }
46  var[detInd] *= std::pow(varMax - varMin, scale);
47  }
48  int addNeighboursToFlickering{2};
49  for(auto detectorSeg = 0; detectorSeg < 2; detectorSeg++){
50  for(auto i = 0u; i < numberOfDetectors/2; i++){
51  double thresh_segment = 0.0;
52  for(auto j = 0; j < 9; j++){
53  int ind = (i - j) % (numberOfDetectors/2);
54  thresh_segment += filterFunction[j] * var[ind + detectorSeg * (numberOfDetectors/2)];
55  ind = (i + j) % (numberOfDetectors/2);
56  thresh_segment += filterFunction[j] * var[ind + detectorSeg * (numberOfDetectors/2)];
57  }
58  unsigned int detInd = detectorSeg * (numberOfDetectors/2) + i;
59  if(var[detInd] < threshMin*thresh_segment){
60  defectDetectors[detInd] = 1;
61  //std::cout << "Thresh: " << threshMin_*thresh_segment << "Defect: " << detInd << std::endl;
62  }
63  if(var[detInd] > threshMax * thresh_segment){
64  for(int offset = -addNeighboursToFlickering; offset <= addNeighboursToFlickering; offset++){
65  defectDetectors[(detInd+offset)%numberOfDetectors] = 1;
66  //std::cout << "Defect: " << (detInd+offset)%numberOfDetectors_ << std::endl;
67  }
68  }
69  }
70  }
71 }
72 
73 template <typename T>
74 auto interpolateDefectDetectors(T* data, std::vector<int>& defectDetectors,
75  unsigned int numberOfDetectors, unsigned int numberOfProjections) -> void {
76  unsigned int detID = 0;
77  //interpolate
78  while(detID < numberOfDetectors){
79  if(defectDetectors[detID]){
80  unsigned int det0 = detID;
81  //BOOST_LOG_TRIVIAL(info) << "Interpolation from " << det0;
82  while(defectDetectors[detID] && defectDetectors[(detID+1)%numberOfDetectors]){
83  detID++;
84  }
85  //BOOST_LOG_TRIVIAL(info) << "to " << detID;
86  for(auto i = det0; i <= detID; i++){
87  float w1 = ((float)i - (float)det0 + 1.0)/((float)detID - (float)det0 + 2.0);
88  float w0 = 1.0 - w1;
89  for(auto projId = 0u; projId < numberOfProjections; projId++){
90  data[(i%numberOfDetectors) + projId*numberOfDetectors] = w0 * data[(det0-1)%numberOfDetectors + projId*numberOfDetectors] +
91  w1 * data[(detID+1)%numberOfDetectors + projId*numberOfDetectors];
92  }
93  }
94  }
95  detID++;
96  }
97 }
98 
99 
100 #endif /* INTERPOLATIONFUNCTIONS_H_ */
auto interpolateDefectDetectors(T *data, std::vector< int > &defectDetectors, unsigned int numberOfDetectors, unsigned int numberOfProjections) -> void
auto findDefectDetectors(T *data, std::vector< double > &filterFunction, std::vector< int > &defectDetectors, unsigned int numberOfDetectors, unsigned int numberOfProjections, double threshMin, double threshMax) -> void
__constant__ float scale[1]