WPOCT Software Developer's Kit (SDK)
SDK For using Wasatch Photonics OCT Spectrometers
Background.h
Go to the documentation of this file.
1 
6 #pragma once
7 
8 #include "OCTTypeDefs.h"
9 #include <boost/signals2.hpp>
10 #include <boost/bind.hpp>
11 #include <vector>
12 #include <mutex>
13 #include "ScanProcessor.h"
14 
15 // Forward class declarations.
16 
18 {
19 public:
20  Background(ScanProcessor* scanProcessor);
21  virtual ~Background();
22 
23  // Getters
24 
25  bool GetUseBackgroundSubtract () const { return _useBackgroundSubtract; }
26  bool GetUseAverageBG () const { return _useAverageBG; }
27  bool GetUseAutoDC () const { return _useAutoDC; }
28  bool GetAutoSaveBG () const { return _autoSaveBG; }
29 
30  // Setters
31 
32  void SetUseBackgroundSubtract (bool value) { _useBackgroundSubtract = value; }
33  void SetUseAverageBG (bool value) { _useAverageBG = value; }
34  void SetUseAutoDC (bool value) { _useAutoDC = value; }
35  void SetAutoSaveBG (bool value) { _autoSaveBG = value; }
36 
37  bool GetBackgroundImage (float* buffer, int size);
38  bool UpdateImage (float* buffer = nullptr, int size = 0);
39 
40  void AdjustForBackground (const U16* raw, SGL *&inputData);
41 
55  template <typename T, typename F>
56  void BackgroundAverageAutoDCMethod(const T* raw, F *&inputData)
57  {
58  int j;
59  int width = _scanProcessor->GetWidth();
60  int height = _scanProcessor->GetHeight();
61 
62  for (int i = 0; i < width; i++)
63  {
64  //- for each a-scan, sum all the pixels
65  float aSum = 0;
66  float dcComp = 0;
67  for (j = 0; j < height; j++)
68  {
69  aSum += static_cast<F>(*(raw + j + i * height)) / height;
70  }
71 
72  dcComp = aSum - _averageSum;
73  if (_scanProcessor->GetUseApodization())
74  {
75  //not tested
76  for (j = 0; j < height; j++)
77  {
78  *(inputData + i * height + j) = _maxIntensity *
79  (static_cast<F>(*(raw + i * height + j)) - dcComp - _avgBgLine[j]) /
80  (dcComp - _avgBgLine[j]);
81  }
82  }
83  else
84  {
85  for (j = 0; j < height; j++)
86  {
87  *(inputData + i * height + j) = static_cast<F>(*(raw + i * height + j)) -
88  dcComp - _avgBgLine[j];
89  }
90  }
91  }
92  }
93 
109  template <typename T, typename F>
110  void BackgroundAverageMethod(const T* raw, F *&inputData)
111  {
112  long imageSize = _scanProcessor->GetWidth() *_scanProcessor->GetHeight();
113  if (_avgBgImage.size() != imageSize)
114  {
116  }
117 
118  //Apodization
119  if (_scanProcessor->GetUseApodization())
120  {
121  //smessage("using apodization cpu");
122  for (int i = 0; i < imageSize; i++)
123  {
124  *(inputData + i) = _maxIntensity * (static_cast<F>(*(raw + i)) -
125  _avgBgImage[i]) / _avgBgImage[i];
126  }
127  }
128  else
129  {
130  // use regular bg subtract
131  for (int i = 0; i < imageSize; i++)
132  {
133  *(inputData + i) = static_cast<F>(*(raw + i)) - _avgBgImage[i];
134  }
135  }
136  }
137 
145  template <typename T, typename F>
146  void BackgroundImageMethod(const T* raw, F *&inputData)
147  {
148  long imageSize = _scanProcessor->GetWidth() *_scanProcessor->GetHeight();
149  for (int i = 0; i < imageSize; i++)
150  {
151  *(inputData + i) = static_cast<F>(*(raw + i)) - _bgImage[i];
152  }
153  }
154 
162  template <typename T, typename F>
163  void NoImageMethod(const T* raw, F *&inputData)
164  {
165  long imageSize = _scanProcessor->GetWidth() *_scanProcessor->GetHeight();
166 
167  for (int i = 0; i < imageSize; i++)
168  {
169  *(inputData + i) = static_cast<F>(*(raw + i));
170  }
171  }
172 
173  virtual void InitGPUMethods (int programIndex) { }
174  virtual void OnWidthHeightChanged (int width, int height) { }
175 
176  virtual int Subtract (const unsigned short *raw);
177 
178 
179 protected:
180  bool _initialized;
181  bool _updateImage;
182  bool _useAveragedImage;
183 
184  static std::vector<SGL> _bgImage;
185  static std::vector<SGL> _avgBgImage;
186  static std::vector<SGL> _avgBgLine;
187 
189  static int _numObjects;
190 
191  ScanProcessor* _scanProcessor;
192 
193  static float _maxIntensity;
194  static float _averageSum;
195  static float _maxBG;
196 
197  static bool _useBackgroundSubtract;
198  static bool _useAverageBG;
199  static bool _useAutoDC;
200  static bool _autoSaveBG;
201 
202  static std::mutex _mutexSubtract;
203 
205  void SetBackgroundImagePtr (const U16 *sourceptr);
206 
207  virtual void InitStorage ();
208  virtual void ReleaseStorage () { }
209  virtual void UpdateBackgroundArray (float *Background, float maxgb) { }
210 
211 private:
212  boost::signals2::connection _widthHeightConnection;
213 
214  void Init();
215 };
typedefs used across UtensilConverter
Interface of the ScanProcessor class.
Definition: Background.h:18
void BackgroundImageMethod(const T *raw, F *&inputData)
Use the entire background image frame and do a line by line subtraction with raw to get inputData.
Definition: Background.h:146
bool UpdateImage(float *buffer=nullptr, int size=0)
Update the background image.
Definition: Background.cpp:145
void BackgroundAverageMethod(const T *raw, F *&inputData)
For the averaged background, create a single a-scan by averaging the background image.
Definition: Background.h:110
void NoImageMethod(const T *raw, F *&inputData)
Just copy raw to indata.
Definition: Background.h:163
void BackgroundAverageAutoDCMethod(const T *raw, F *&inputData)
Pre-processing methods to move raw data to input data.
Definition: Background.h:56
bool GetBackgroundImage(float *buffer, int size)
Gets the one A-scan wide background image and places it in the buffer.
Definition: Background.cpp:122
void ComputeAveragedBackground()
this takes into account the apodization regardless - 4/24/2015 for apodization only need maxbg
Definition: Background.cpp:176
static int _numObjects
Reference counter to keep track of number of background objects.
Definition: Background.h:189
Class that processes scans.
Definition: ScanProcessor.h:32