IB-0.2
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
IBVoxImageScanner.h
Go to the documentation of this file.
1 /*////////////////////////////////////////////////////////////////////////////
2  Copyright 2018 Istituto Nazionale di Fisica Nucleare
3 
4  Licensed under the EUPL, Version 1.2 or - as soon they will be approved by
5  the European Commission - subsequent versions of the EUPL (the "Licence").
6  You may not use this work except in compliance with the Licence.
7 
8  You may obtain a copy of the Licence at:
9 
10  https://joinup.ec.europa.eu/software/page/eupl
11 
12  Unless required by applicable law or agreed to in writing, software
13  distributed under the Licence is distributed on an "AS IS" basis, WITHOUT
14  WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15  Licence for the specific language governing permissions and limitations under
16  the Licence.
18 
19 
20 
21 #ifndef IBVOXIMAGESCANNER_H
22 #define IBVOXIMAGESCANNER_H
23 
24 #include "Math/VoxImage.h"
25 
26 using namespace uLib;
27 
28 template<class T>
29 class IBVoxImageScanner
30 {
31 public:
32  IBVoxImageScanner() : m_Image(NULL) {}
33  IBVoxImageScanner(T * image) : m_Image(image) {}
34  IBVoxImageScanner(T& image) : m_Image(&image) {}
35  template<class A>
36  class A::ScanData ScanImage(class A::ScanOption opt)
37  {
38  A scanner;
39  scanner.template LoadImageData<T>(m_Image);
40  return scanner.Scan(opt);
41  }
42 
43  inline T* GetImage() const { return this->m_Image; }
44 
45  inline void SetImage(T* image) { this->m_Image = image; }
46 
47 private:
48  T * m_Image;
49 };
50 
51 // TODO: interface for std::vector<float> ImageData
52 // TODO: Threshold Scanner Interface
53 // TODO: in SubImageGrabber a mapper between V3i/int of Image and SubImage;
54 // move in a separate file to be included!!!
55 
59 class SimpleThresholdScan
60 {
61 public:
62  typedef std::vector<float> ImageData;
63  struct ScanData {
64  float Percent;
65  float Intensity;
66  };
67  struct ScanOption {
68  float Threshold;
69  };
70  SimpleThresholdScan() {}
71 
72  template<class T>
73  void LoadImageData(T * image);
74 
75  ScanData Scan(ScanOption opt);
76 
77  inline void ResetScanData()
78  {
79  m_ScanData.Percent = 0.0;
80  m_ScanData.Intensity = 0.0;
81  }
82 
83  inline ScanData GetScanData() { return m_ScanData; }
84 
85 protected:
86  ImageData m_ImageData;
87  ScanData m_ScanData;
88 };
89 
90 template<class T>
91 void SimpleThresholdScan::LoadImageData(T * image)
92 {
93  for(int i=0; i<image->Data().size(); ++i)
94  this->m_ImageData.push_back(image->At(i).Value);
95 }
96 
97 // get rid of inline when moving to separate file!
98 inline SimpleThresholdScan::ScanData SimpleThresholdScan::Scan(
99  SimpleThresholdScan::ScanOption opt)
100 {
101  this->ResetScanData();
102  float found = 0;
103  for(int i=0; i<m_ImageData.size(); ++i) {
104  if(m_ImageData.at(i)>=opt.Threshold) {
105  found++;
106  m_ScanData.Intensity += pow(m_ImageData.at(i)/opt.Threshold,2)-1.;
107  }
108  }
109  m_ScanData.Intensity /= found;
110  m_ScanData.Percent = 100 * ((float)found / m_ImageData.size());
111  if(m_ScanData.Percent==0.f)
112  m_ScanData.Intensity = 0.f;
113  return m_ScanData;
114 }
115 
119 
120 class RangeThresholdScan : public SimpleThresholdScan
121 {
122 public:
123  typedef SimpleThresholdScan BaseClass;
124  typedef std::vector<BaseClass::ScanOption> ScanOption;
125  typedef std::vector<BaseClass::ScanData> ScanData;
126 
127  RangeThresholdScan() : BaseClass() {}
128  ScanData Scan(ScanOption opt);
129  inline void ResetScanData() { m_ScanData.clear(); }
130 
131 protected:
132  ScanData m_ScanData;
133 };
134 
135 RangeThresholdScan::ScanData RangeThresholdScan::Scan(
136  RangeThresholdScan::ScanOption opt)
137 {
138  this->ResetScanData();
139  for(int i=0; i<opt.size(); ++i) {
140  BaseClass::ScanData partial_data;
141  partial_data = BaseClass::Scan(opt.at(i));
142  m_ScanData.push_back(partial_data);
143  }
144  return m_ScanData;
145 }
146 
147 #endif // IBVOXIMAGESCANNER_H