21 #ifndef otbLandsatTMSRBC_h
22 #define otbLandsatTMSRBC_h
62 template <
class TInput,
class TOutput>
190 return "LandsatTM SpectralRuleBasedClassifier";
209 LVType lvf = LVType();
210 lvf.SetSAT(this->
m_SAT);
211 typename LVType::OutputPixelType lv = lvf(newPixel);
215 TKCLSRType tkclsrf = TKCLSRType();
216 tkclsrf.SetTV1(this->
m_TV1);
217 tkclsrf.SetTV2(this->
m_TV2);
218 tkclsrf.SetSAT(this->
m_SAT);
220 bool tkclsr = tkclsrf(newPixel);
223 TNCLSRType tnclsrf = TNCLSRType();
224 tnclsrf.SetTV1(this->
m_TV1);
225 tnclsrf.SetTV2(this->
m_TV2);
226 tnclsrf.SetSAT(this->
m_SAT);
228 bool tnclsr = tnclsrf(newPixel);
230 bool lBright = (lv[LVType::bright] == LVType::Low);
231 bool lVis = (lv[LVType::vis] == LVType::Low);
232 bool lNIR = (lv[LVType::nir] == LVType::Low);
233 bool hNDSIVis = (lv[LVType::ndsivis] == LVType::High);
234 bool lMIR1 = (lv[LVType::mir1] == LVType::Low);
235 bool lMIR2 = (lv[LVType::mir2] == LVType::Low);
236 bool hTIR = (lv[LVType::tir] == LVType::High);
237 bool hMIRTIR = (lv[LVType::mirtir] == LVType::High);
238 bool mMIRTIR = (lv[LVType::mirtir] == LVType::Medium);
239 bool lMIRTIR = (lv[LVType::mirtir] == LVType::Low);
243 bool clsc = (tkclsr || tnclsr) && !(lBright || lVis || lNIR || hNDSIVis || lMIR1 || lMIR2 || hTIR || hMIRTIR);
247 return static_cast<TOutput
>(
TKCL);
251 return static_cast<TOutput
>(
TNCL);
255 SNICSRType snicsrf = SNICSRType();
256 snicsrf.SetTV1(this->
m_TV1);
257 snicsrf.SetTV2(this->
m_TV2);
258 snicsrf.SetSAT(this->
m_SAT);
260 bool snicsr = snicsrf(newPixel);
262 bool lNDBSI = (lv[LVType::ndbsi] == LVType::Low);
263 bool lNDSIVis = (lv[LVType::ndsivis] == LVType::Low);
264 bool hMIR1 = (lv[LVType::mir1] == LVType::High);
265 bool hMIR2 = (lv[LVType::mir2] == LVType::High);
268 bool snicsc = (snicsr && lNDBSI && !(lBright || lVis || lNDSIVis || lNIR || hMIR1 || hMIR2 || hTIR));
271 if (snicsc && hNDSIVis)
272 return static_cast<TOutput
>(
SN);
274 bool mNDSIVis = (lv[LVType::ndsivis] == LVType::Medium);
276 if (snicsc && mNDSIVis)
277 return static_cast<TOutput
>(
ICSN);
281 WASHSRType washsrf = WASHSRType();
282 washsrf.SetTV1(this->
m_TV1);
283 washsrf.SetTV2(this->
m_TV2);
284 washsrf.SetSAT(this->
m_SAT);
286 bool washsr = washsrf(newPixel);
289 bool lNDVI = (lv[LVType::ndvi] == LVType::Low);
290 bool lTIR = (lv[LVType::tir] == LVType::Low);
292 bool washsc = washsr && lBright && lVis && lNDVI && lNIR && lMIR1 && lMIR2 && !(lTIR);
296 if (washsc && hNDSIVis)
297 return static_cast<TOutput
>(
DPWASH);
300 if (washsc && !(hNDSIVis))
301 return static_cast<TOutput
>(
SLWASH);
305 PBGHSRType pbghsrf = PBGHSRType();
306 pbghsrf.SetTV1(this->
m_TV1);
307 pbghsrf.SetTV2(this->
m_TV2);
308 pbghsrf.SetSAT(this->
m_SAT);
310 bool pbghsr = pbghsrf(newPixel);
313 bool pbsc = pbghsr && lMIR1 && lMIR2 && lNDBSI && !(lNIR);
315 bool mNDVI = (lv[LVType::ndvi] == LVType::Medium);
316 bool hNDVI = (lv[LVType::ndvi] == LVType::High);
319 return static_cast<TOutput
>(
PBHNDVI);
321 return static_cast<TOutput
>(
PBMNDVI);
323 return static_cast<TOutput
>(
PBLNDVI);
327 VSRType vsrf = VSRType();
328 vsrf.SetTV1(this->
m_TV1);
329 vsrf.SetTV2(this->
m_TV2);
330 vsrf.SetSAT(this->
m_SAT);
332 bool vsr = vsrf(newPixel);
334 bool hNDBSI = (lv[LVType::ndbsi] == LVType::High);
335 bool hNIR = (lv[LVType::nir] == LVType::High);
338 bool svsc = vsr && hNDVI && !(hMIR1 || hMIR2 || hNDBSI);
341 return static_cast<TOutput
>(
SVHNIR);
343 return static_cast<TOutput
>(
SVLNIR);
346 SHVSRType shvsrf = SHVSRType();
347 shvsrf.SetTV1(this->
m_TV1);
348 shvsrf.SetTV2(this->
m_TV2);
349 shvsrf.SetSAT(this->
m_SAT);
351 bool shvsr = shvsrf(newPixel);
355 DBSRType dbsrf = DBSRType();
356 dbsrf.SetTV1(this->
m_TV1);
357 dbsrf.SetTV2(this->
m_TV2);
358 dbsrf.SetSAT(this->
m_SAT);
360 bool dbsr = dbsrf(newPixel);
363 bool avsc = (vsr || shvsr) && mNDVI && !(hMIR1 || hMIR2 || hNDBSI || dbsr);
366 return static_cast<TOutput
>(
AVHNIR);
368 return static_cast<TOutput
>(
AVLNIR);
371 RSRType rsrf = RSRType();
372 rsrf.SetTV1(this->
m_TV1);
373 rsrf.SetTV2(this->
m_TV2);
374 rsrf.SetSAT(this->
m_SAT);
376 bool rsr = rsrf(newPixel);
379 bool wvsc = (vsr || rsr || shvsr) && lNDVI && lNDBSI && lMIR1 && lMIR2 && !(dbsr);
382 return static_cast<TOutput
>(
WVHNIR);
384 return static_cast<TOutput
>(
WVLNIR);
386 bool mNDBSI = (lv[LVType::ndbsi] == LVType::Medium);
388 bool ssrsc = rsr && hNDVI && mNDBSI;
390 return static_cast<TOutput
>(
SSRHNIR);
391 if (ssrsc && !(hNIR))
392 return static_cast<TOutput
>(
SSRLNIR);
395 WESRType wesrf = WESRType();
396 wesrf.SetTV1(this->
m_TV1);
397 wesrf.SetTV2(this->
m_TV2);
398 wesrf.SetSAT(this->
m_SAT);
400 bool wesr = wesrf(newPixel);
403 bool asrsc = rsr && mNDVI && mNDBSI && !(shvsr || wesr);
405 return static_cast<TOutput
>(
ASRHNIR);
406 if (asrsc && !(hNIR))
407 return static_cast<TOutput
>(
ASRLNIR);
411 bool shrsc = rsr && hNDVI && hNDBSI;
413 return static_cast<TOutput
>(
SHR);
416 BBCSRType bbcsrf = BBCSRType();
417 bbcsrf.SetTV1(this->
m_TV1);
418 bbcsrf.SetTV2(this->
m_TV2);
419 bbcsrf.SetSAT(this->
m_SAT);
421 bool bbcsr = bbcsrf(newPixel);
423 bool ahrsc = (rsr || bbcsr) && mNDVI && hNDBSI;
425 return static_cast<TOutput
>(
AHR);
428 bool drsc = (vsr || rsr) && lNDVI && lMIR2 && !(hNIR || hMIR1 || lNDBSI);
430 return static_cast<TOutput
>(
DR);
433 bool bbbsc = bbcsr && hNIR && lNDVI && hNDBSI && !(lMIR1 || lMIR2);
435 bool lNDBBBI = (lv[LVType::ndbbbi] == LVType::Low);
437 bool bbbhtirsc = bbbsc && hTIR;
439 if (bbbhtirsc && !(lNDBBBI))
440 return static_cast<TOutput
>(
BBBHTIRF);
441 if (bbbhtirsc && lNDBBBI)
444 bool bbbltirsc = bbbsc && !(hTIR);
445 if (bbbltirsc && !(lNDBBBI))
446 return static_cast<TOutput
>(
BBBLTIRF);
447 if (bbbltirsc && lNDBBBI)
451 FBBSRType fbbsrf = FBBSRType();
452 fbbsrf.SetTV1(this->
m_TV1);
453 fbbsrf.SetTV2(this->
m_TV2);
454 fbbsrf.SetSAT(this->
m_SAT);
456 bool fbbsr = fbbsrf(newPixel);
458 bool sbbsc = (bbcsr || fbbsr) && lNDVI && hNDBSI && !(hNIR || lMIR1);
460 bool sbbhtirsc = sbbsc && hTIR;
462 if (sbbhtirsc && (dbsr || fbbsr))
463 return static_cast<TOutput
>(
SBBHTIRF);
464 if (sbbhtirsc && !(dbsr || fbbsr))
467 bool sbbltirsc = sbbsc && !(hTIR);
468 if (sbbltirsc && (dbsr || fbbsr))
469 return static_cast<TOutput
>(
SBBLTIRF);
470 if (sbbltirsc && !((dbsr || fbbsr)))
474 bool abbsc = (bbcsr || fbbsr) && lNDVI && mNDBSI && !(lMIR1);
476 bool abbhtirsc = abbsc && hTIR;
478 if (abbhtirsc && !(lNDBBBI))
479 return static_cast<TOutput
>(
ABBHTIRF);
480 if (abbhtirsc && lNDBBBI)
483 bool abbltirsc = abbsc && !(hTIR);
484 if (abbltirsc && !(lNDBBBI))
485 return static_cast<TOutput
>(
ABBLTIRF);
486 if (abbltirsc && lNDBBBI)
490 bool dbbsc = (bbcsr || fbbsr) && lNDVI && lMIR1 && !(hNIR || hMIR2 || lNDBSI);
492 bool dbbhtirsc = dbbsc && hTIR;
494 if (dbbhtirsc && (dbsr || fbbsr))
495 return static_cast<TOutput
>(
DBBHTIRF);
496 if (dbbhtirsc && !(dbsr || fbbsr))
499 bool dbbltirsc = dbbsc && !(hTIR);
500 if (dbbltirsc && (dbsr || fbbsr))
501 return static_cast<TOutput
>(
DBBLTIRF);
502 if (dbbltirsc && !((dbsr || fbbsr)))
506 bool wrsc = rsr && lNDVI && !(lNDBSI);
508 return static_cast<TOutput
>(
WR);
511 bool shvsc = dbsr && shvsr && lBright && lVis && lNIR && lMIR1 && lMIR2 && !(hNDVI);
513 return static_cast<TOutput
>(
SHV);
516 SHBSRType shbsrf = SHBSRType();
517 shbsrf.SetTV1(this->
m_TV1);
518 shbsrf.SetTV2(this->
m_TV2);
519 shbsrf.SetSAT(this->
m_SAT);
521 bool shbsr = shbsrf(newPixel);
523 bool shbsc = dbsr && shbsr && lBright && lVis && lNDVI && lNIR && lMIR1 && lMIR2;
525 return static_cast<TOutput
>(
SHB);
528 SHCLSNSRType shclsnsrf = SHCLSNSRType();
529 shclsnsrf.SetTV1(this->
m_TV1);
530 shclsnsrf.SetTV2(this->
m_TV2);
531 shclsnsrf.SetSAT(this->
m_SAT);
533 bool shclsnsr = shclsnsrf(newPixel);
535 bool shclsc = dbsr && shclsnsr && !(hNDSIVis || lNIR || lBright || lVis || hNDBSI || hTIR);
537 return static_cast<TOutput
>(
SHCL);
539 bool hBright = (lv[LVType::bright] == LVType::High);
540 bool hVis = (lv[LVType::vis] == LVType::High);
542 bool twashsnsc = dbsr && shclsnsr && hNDSIVis && lNIR && lMIR1 && lMIR2 && !(hBright || hVis || hNDBSI || hTIR);
544 return static_cast<TOutput
>(
TWASHSN);
547 bool wesc = dbsr && wesr && lBright && lVis && lNIR && lMIR1 && lMIR2 && !(hNDVI || hNDBSI || lNDSIVis);
549 return static_cast<TOutput
>(
WE);
552 bool twasc = dbsr && lNDVI && lMIR1 && lMIR2 && !(hBright || hVis || hNIR || lNDSIVis);
554 return static_cast<TOutput
>(
TWA);
556 return static_cast<TOutput
>(
SU);