Loading...
Searching...
No Matches
AnoRack.h
1
11#ifndef ANORACK_H_
12#define ANORACK_H_ "AnoRack v0.1"
13
14#include "radar/Constants.h" // radar
15#include "radar/Andre.h"
16
17using namespace drain::image;
18
19namespace anorack
20{
21
23
27template <class T = unsigned char,class T2 = unsigned char>
28class AnoRackShip : public rack::AndreDetector<T,T2>
29{
30public:
31
32
33 AnoRackShip(const std::string & p="64,4,5")
34 : rack::AndreDetector<T,T2>("ship","Detects ships","threshold,size,sidelobe",p){
35
36 };
37
38
39 void filter(const Image<T> &src, Image<T2> &dst) const {
40
41 makeCompatible(src,dst);
42
43 const int threshold = this->getParameter("threshold",64);
44 const int size = this->getParameter("size",4);
45 const int sidelobe = this->getParameter("sidelobe",5);
46
47 /*
48 HighBoostOp<T> high;
49 high.setParameter("width",3);
50 high.setParameter("height",3);
51 //high.filter(src,this->tmp);
52 high.filter(src,dst);
53 */
54
56 area.setParameter("mapping","f"); // bilinear inverse
57 area.setParameter("min",threshold);
58 area.setParameter("targetSize",size);
59 area.setParameter("halfWidth",size/2);
60 area.filter(src,dst);
61 MultiplicationOp<T,T>().filter(src,dst,dst);
62
63 if (sidelobe > 0){
65 //DistanceTransformLinearOp<T,T> dist;
66 dist.setParameter("horz",1);
67 dist.setParameter("vert",sidelobe);
68 dist.setParameter("diag",1);
69 dist.filter(dst,dst);
70 }
71
72 };
73};
74
76
80template <class T = unsigned char,class T2 = unsigned char>
81class AnoRackRadomeAttenuation : public rack::AndreDetector<T,T2>
82{
83public:
84
85
86 AnoRackRadomeAttenuation(const std::string & p="45,10,20,2")
87 : rack::AndreDetector<T,T2>("aRadome","Detects radome attenuation.","dBZmax,binStart,binEnd,power",p) {
88 };
89
90
91 void filter(const Image<T> &src,Image<T2> &dst) const {
92
93 makeCompatible(src,dst);
94
95 const unsigned int width = src.getWidth();
96 const unsigned int height = src.getHeight();
97
98 const float dBZmax = this->getParameter("dBZmax",45);
99 const unsigned int binStart = std::min(this->getParameter("binStart",10u),width-1);
100 const unsigned int binEnd = std::min(this->getParameter("binEnd",20u),width-1);
101 const double power = this->getParameter("power",2.0);
102
103 // TODO generalize FMI scale
104 const double byteMax = dBZmax*2.0 + 64.0;
105
106 std::cerr << binStart << ':' << binEnd << '\n';
107
108 double sum = 0.0;
109 double x;
110 for (unsigned int i = binStart; i < binEnd; ++i) {
111 for (unsigned int j = 0; j < height; ++j) {
112 x = src.at(i,j);
113 x = std::min(x,byteMax);
114 //dst.at(i,j) = x;
115 sum += ::pow(x/byteMax,power);
116 }
117 //std::cerr << "sumRaw=" << sum << '\n';
118 }
119
120 //std::cerr << "sumRaw=" << sum << '\n';
121 sum = //255*pow(sum/(width*(binEnd-binStart)),1.0/power);
122 255*(sum/(width*(binEnd-binStart)));
123 std::cerr << "sum=" << sum << '\n';
124
125
126 // TODO replace with single value!
127 for (unsigned int i = 0; i < width; ++i) {
128 for (unsigned int j = 0; j < height; ++j) {
129 dst.at(i,j) = static_cast<T>(sum);
130 }
131 }
132
133 };
134};
135
136// Computes attenuation caused by \em precipitation.
156template <class T = unsigned char,class T2 = unsigned char>
157class AnoRackAttenuation : public rack::AndreDetector<T,T2>
158{
159public:
160
161 AnoRackAttenuation(const std::string & p="1.12e-4,0.62,0,0")
162 : rack::AndreDetector<T,T2>("aAttenuation","Computes attenuation using cZe^p + c2Ze^p2. Alternatively, set c 'rain' or 'snow'.","c,p,c2,p2",p){
163 };
164
165
166 void filter(const Image<T> &src,Image<T2> &dst) const {
167 const std::string & cStr = this->parameters.get("c","1.12e-4");
168 double c = this->parameters.get("c",1.12e-4);
169 double p = this->parameters.get("p",0.62);
170 double c2 = this->parameters.get("c2",0);
171 double p2 = this->parameters.get("p2",0);
172
173 if (cStr == "rain"){
174 c = 1.12E-7;
175 p = 0.62;
176 c2 = 0;
177 p2 = 0;
178 }
179 else if (cStr == "snow"){
180 c = 1.1E-7;
181 p = 1;
182 c2 = 2.1E-5;
183 p2 = 0.5;
184 }
185 else if (cStr == "erad"){
186 c = 1e-14;
187 p = 0.65;
188 c2 = 0.0;
189 p2 = 0.0;
190 }
191 else if (cStr == "demo"){
192 c = 1.11e-11;
193 p = 0.9;
194 c2 = 0.0;
195 p2 = 0.0;
196 }
197 else if (cStr == "demo2"){
198 c = 1.12e-03;
199 p = 0.12;
200 c2 = 0.0;
201 p2 = 0.0;
202 }
203
204 const unsigned int srcWidth = src.getGeometry().getWidth();
205 const unsigned int srcHeight = src.getGeometry().getHeight();
206 const unsigned int srcChannels = src.getGeometry().getImageChannelCount();
207 dst.setGeometry(srcWidth,srcHeight,srcChannels);
208
209 std::cout << "Attn: << " << src.getGeometry() << "\n";
210 std::cout << "Attn: << " << dst.getGeometry() << "\n";
211
212 float binDepth = src.properties.get("BIN_DEPTH",500.0f);
213
214 std::cerr << "Attn:" << c << ','<< p << ','<< c2 << ','<< p2 << '\n';
215
216 // Main loops
217
219 double dbzObs;
220
222 double zAttnBin;
223
225 double zAttnCumulated=0;
226
228 double confidence;
229 //dbzAttnCumulated;
230
232 double zTrue;
233
234 //double dbzTrue;
235
236 for (unsigned int k = 0; k < srcChannels; ++k) {
237 for (unsigned int j = 0; j < srcHeight; ++j) {
238 zAttnCumulated = 0;
239 for (unsigned int i = 0; i < srcWidth; ++i) {
240 dbzObs = (src.at(i,j,k)-64)*2; // FMI
241
243 zTrue = rack::dbzToZ( dbzObs ) + zAttnCumulated;
244
247 // TODO: bin width should be in the exponent?
248 zAttnBin = c*::pow(zTrue,p) * binDepth * 2.0;
249 zAttnCumulated += zAttnBin;
250
251 //confidence = (::radar::zToDbz(zAttnCumulated)+64)*4; // TODO
252 confidence = zAttnCumulated/100.0; // TODO
253 //confidence = 255.0 - 255.0/(1+confidence*confidence);
254 confidence = 245.0 - 245.0/(1.0+confidence);
255 //dbzTrue = ::radar::zToDbz( zTrue );
256
257 //if (j&3 == 3) dst.at(i,j,k) = static_cast<T2>(255.0-confidence);
258 //else
259 //dst.at(i,j,k) = static_cast<T2>(drain::radar::zToDbz(drain::radar::dbzToZ( dbzObs ) )/2 + 64);
260 //dst.at(i,j,k) = static_cast<T2>(zToDbz(zAttnCumulated));
261 dst.at(i,j,k) = static_cast<T2>(confidence);
262 }
263 //std::cerr << "attn = " << zAttnCumulated << "\n";
264 }
265 }
266
267
268 }
269};
270
271
272template <class T = unsigned char,class T2 = unsigned char>
273class AnoRack : public rack::Andre<T,T2> {
274public:
275
276 AnoRackShip<T,T2> ship2;
277 AnoRackAttenuation<T,T2> attenuation;
279 //AnoRackRadomeAttenuation<T,T2> radome;
280
281 AnoRack(){
282 }
283
284 virtual void addDefaultOps(){
285 rack::Andre<T,T2>::addDefaultOps();
286 addOperator("ship2",ship2);
287 addOperator("attenuation",attenuation);
288 addOperator("radome",radome);
289 }
290
291 virtual ~AnoRack(){};
292};
293
294
295} // anorack
296
297
298#endif /* ANORACK_H_ */
Definition AnoRack.h:158
void filter(const Image< T > &src, Image< T2 > &dst) const
Definition AnoRack.h:166
Detects speckle noise.
Definition AnoRack.h:82
Detects speckle noise.
Definition AnoRack.h:29
Definition AnoRack.h:273
void setParameter(const std::string &p, const Castable &value)
Sets a single parameter.
Definition BeanLike.h:211
std::string get(const std::string &key, const std::string &defaultValue) const
Retrieves a value, or default value if value is unset.
Definition SmartMap.h:127
Definition DistanceTransformOp.h:513
FlexVariableMap properties
Container for user-defined KEY=VALUE metadata.
Definition ImageFrame.h:369
Class for multi-channel digital images. Supports dynamic typing with base types (char,...
Definition Image.h:184
virtual void setGeometry(size_t width, size_t height, size_t imageChannels=1, size_t alphaChannels=0)
Resizes the image, keeps the current type.
Definition Image.h:95
Computes sizes of connected pixel areas.
Definition SegmentAreaOp.h:97
Namespace for images and image processing tools.
Definition AccumulationArray.cpp:45
double dbzToZ(const T &dBZ)
Definition Constants.h:69