18 #ifndef __otbLandsatTMIndices_h
19 #define __otbLandsatTMIndices_h
61 template<
class TInput,
class TOutput>
74 return !(*
this != other);
78 LandsatTMIndexBase() :
m_EpsilonToBeConsideredAsZero(0.0000001),
m_TM1(0),
m_TM2(1),
m_TM3(2),
m_TM4(3),
m_TM5(4),
m_TM60(5),
m_TM61(5),
m_TM62(6),
m_TM7(7),
m_SAT(
L7),
m_Degree(
Celsius),
m_Reflectance(
Normalized) {}
263 TInput newPix( inputPixel );
281 newPix[this->
m_TM60] = newPix[this->
m_TM60]/100.-273.15;
285 newPix[this->
m_TM61] = newPix[this->
m_TM61]/100.-273.15;
286 newPix[this->
m_TM62] = newPix[this->
m_TM62]/100.-273.15;
291 newPix[this->
m_TM1] = newPix[this->
m_TM1]/1000.;
292 newPix[this->
m_TM2] = newPix[this->
m_TM2]/1000.;
293 newPix[this->
m_TM3] = newPix[this->
m_TM3]/1000.;
294 newPix[this->
m_TM4] = newPix[this->
m_TM4]/1000.;
295 newPix[this->
m_TM5] = newPix[this->
m_TM5]/1000.;
296 newPix[this->
m_TM7] = newPix[this->
m_TM7]/1000.;
328 template <
class TInput,
class TOutput>
334 inline TOutput
operator ()(
const TInput& inputPixel)
const;
337 virtual std::string
GetName()
const = 0;
360 template <
class TInput,
class TOutput>
377 double result = (newPixel[this->
m_TM1]+newPixel[this->
m_TM2]+2*newPixel[this->
m_TM3]+2*newPixel[this->
m_TM4]+newPixel[this->
m_TM5]+newPixel[this->
m_TM7])/8.0;
378 return static_cast<TOutput
>(result);
399 template <
class TInput,
class TOutput>
415 double result = (newPixel[this->
m_TM1]+newPixel[this->
m_TM2]+newPixel[this->
m_TM3])/3.0;
416 return static_cast<TOutput
>(result);
430 template <
class TInput,
class TOutput>
446 double result = newPixel[this->
m_TM4];
447 return static_cast<TOutput
>(result);
460 template <
class TInput,
class TOutput>
476 double result = newPixel[this->
m_TM5];
477 return static_cast<TOutput
>(result);
490 template <
class TInput,
class TOutput>
506 double result = newPixel[this->
m_TM7];
507 return static_cast<TOutput
>(result);
520 template <
class TInput,
class TOutput>
536 double result = newPixel[this->
m_TM62];
539 result = newPixel[this->
m_TM60];
541 return static_cast<TOutput
>(result);
564 template <
class TInput,
class TOutput>
580 double tir = newPixel[this->
m_TM62];
581 double mir1 = newPixel[this->
m_TM5];
584 tir = newPixel[this->
m_TM60];
586 double result = 255*(1 - mir1)*(tir+100)/100.;
588 return static_cast<TOutput
>(result);
602 template <
class TInput,
class TOutput>
618 double result = (newPixel[this->
m_TM4] - newPixel[this->
m_TM3])/
621 return static_cast<TOutput
>(result);
647 template <
class TInput,
class TOutput>
663 double result = (newPixel[this->
m_TM5] - newPixel[this->
m_TM4])/
666 return static_cast<TOutput
>(result);
688 template <
class TInput,
class TOutput>
704 double result = ((newPixel[this->
m_TM5] + newPixel[this->
m_TM3])
705 - (newPixel[this->
m_TM4] + newPixel[this->
m_TM1]))
706 /((newPixel[this->
m_TM5] + newPixel[this->
m_TM3])
707 + (newPixel[this->
m_TM4] + newPixel[this->
m_TM1]));
709 return static_cast<TOutput
>(result);
732 template <
class TInput,
class TOutput>
748 double result = (newPixel[this->
m_TM2] - newPixel[this->
m_TM5])
751 return static_cast<TOutput
>(result);
787 template <
class TInput,
class TOutput>
803 double vis = (newPixel[this->
m_TM1]+newPixel[this->
m_TM2]+newPixel[this->
m_TM3])/3.0;
806 return static_cast<TOutput
>(result);
830 template <
class TInput,
class TOutput>
846 double result = (newPixel[this->
m_TM1] - newPixel[this->
m_TM5])
848 return static_cast<TOutput
>(result);
873 template <
class TInput>
883 enum Indices {
MINid=0,
bright=
MINid,
vis,
nir,
mir1,
mir2,
tir,
mirtir,
ndsivis,
ndbbbi,
ndvi,
MAXid=10,
ndbsi=MAXid };
888 return "LandsatTM Linguistic Variables";
905 PrecisionType maximumValue = itk::NumericTraits<PrecisionType>::max();
906 PrecisionType minimumValue = itk::NumericTraits<PrecisionType>::NonpositiveMin();
909 m_FvBright->SetMembership(
Low, minimumValue, minimumValue, 40/255., 40/255.);
911 m_FvBright->SetMembership(
High, 60/255., 60/255., maximumValue, maximumValue);
913 m_FvVis->SetMembership(
Low, minimumValue, minimumValue, 30/255., 30/255.);
914 m_FvVis->SetMembership(
Medium, 30/255., 30/255., 50/255., 50/255.);
915 m_FvVis->SetMembership(
High, 50/255., 50/255., maximumValue, maximumValue);
917 m_FvNIR->SetMembership(
Low, minimumValue, minimumValue, 40/255., 40/255.);
918 m_FvNIR->SetMembership(
Medium, 40/255., 40/255., 60/255., 60/255.);
919 m_FvNIR->SetMembership(
High, 60/255., 60/255., maximumValue, maximumValue);
921 m_FvMIR1->SetMembership(
Low, minimumValue, minimumValue, 40/255., 40/255.);
922 m_FvMIR1->SetMembership(
Medium, 40/255., 40/255., 60/255., 60/255.);
923 m_FvMIR1->SetMembership(
High, 60/255., 60/255., maximumValue, maximumValue);
925 m_FvMIR2->SetMembership(
Low, minimumValue, minimumValue, 30/255., 30/255.);
926 m_FvMIR2->SetMembership(
Medium, 30/255., 30/255., 50/255., 50/255.);
927 m_FvMIR2->SetMembership(
High, 50/255., 50/255., maximumValue, maximumValue);
929 m_FvTIR->SetMembership(
Low, minimumValue, minimumValue, 0, 0);
931 m_FvTIR->SetMembership(
High, 28, 28, maximumValue, maximumValue);
933 m_FvMIRTIR->SetMembership(
Low, minimumValue, minimumValue, 180, 180);
935 m_FvMIRTIR->SetMembership(
High, 220, 220, maximumValue, maximumValue);
937 m_FvNDSIVis->SetMembership(
Low, minimumValue, minimumValue, 0, 0);
939 m_FvNDSIVis->SetMembership(
High, 0.5, 0.5, maximumValue, maximumValue);
941 m_FvNDBBBI ->SetMembership(
Low, minimumValue, minimumValue, -0.20, -0.20);
943 m_FvNDBBBI->SetMembership(
High, 0.10, 0.10, maximumValue, maximumValue);
945 m_FvNDVI->SetMembership(
Low, minimumValue, minimumValue, 0.35, 0.35);
947 m_FvNDVI->SetMembership(
High, 0.6, 0.6, maximumValue, maximumValue);
949 m_FvNDBSI->SetMembership(
Low, minimumValue, minimumValue, -0.20, -0.20);
951 m_FvNDBSI->SetMembership(
High, 0.0, 0.0, maximumValue, maximumValue);
967 result[
mir2 ] =
m_FvMIR2->GetMaxVar(mir2F( newPixel ));
971 result[
tir ] =
m_FvTIR->GetMaxVar(tirF( newPixel ));
1020 template <
class TInput,
class TOutput>
1031 return "LandsatTM KernelSpectralRule";
1065 std::vector< PrecisionType > v13;
1066 v13.push_back(inputPixel[this->
m_TM1]);
1067 v13.push_back(inputPixel[this->
m_TM3]);
1069 *max13 = *(std::max_element ( v13.begin(), v13.end() ));
1072 std::vector< PrecisionType > v123;
1073 v123.push_back(inputPixel[this->m_TM1]);
1074 v123.push_back(inputPixel[this->
m_TM2]);
1075 v123.push_back(inputPixel[this->m_TM3]);
1077 *max123 = *(std::max_element ( v123.begin(), v123.end() ));
1078 *min123 = *(std::min_element ( v123.begin(), v123.end() ));
1081 std::vector< PrecisionType > v12347;
1082 v12347.push_back(inputPixel[this->m_TM1]);
1083 v12347.push_back(inputPixel[this->m_TM2]);
1084 v12347.push_back(inputPixel[this->m_TM3]);
1085 v12347.push_back(inputPixel[this->
m_TM4]);
1086 v12347.push_back(inputPixel[this->
m_TM7]);
1088 *max12347 = *(std::max_element ( v12347.begin(), v12347.end() ));
1089 *min12347 = *(std::min_element ( v12347.begin(), v12347.end() ));
1091 std::vector< PrecisionType > v234;
1092 v234.push_back(inputPixel[this->m_TM2]);
1093 v234.push_back(inputPixel[this->m_TM3]);
1094 v234.push_back(inputPixel[this->m_TM4]);
1096 *max234 = *(std::max_element ( v234.begin(), v234.end() ));
1098 std::vector< PrecisionType > v45;
1099 v45.push_back(inputPixel[this->m_TM4]);
1100 v45.push_back(inputPixel[this->
m_TM5]);
1102 *max45 = *(std::max_element ( v45.begin(), v45.end() ));
1119 template <
class TInput,
class TOutput>
1130 return "LandsatTM ThickCloudsSpectralRule";
1146 this->
SetMinMax(newPixel, &max13, &min123, &max123, &min12347, &max12347, &max234, &max45);
1149 ((min123 >= (this->
m_TV1 * max123)
1150 && (max123 <= this->
m_TV1 * newPixel[this->
m_TM4]))
1151 || ((newPixel[this->
m_TM2] >= this->
m_TV1 * max13)
1152 && (max123 <= newPixel[this->
m_TM4])))
1153 && (newPixel[this->
m_TM5] <= this->
m_TV1 * newPixel[this->m_TM4])
1154 && (newPixel[this->
m_TM5] >= this->
m_TV1 * max123)
1155 && (newPixel[this->
m_TM7] <= this->
m_TV1 * newPixel[this->m_TM4]));
1157 return static_cast<TOutput
>(result);
1175 template <
class TInput,
class TOutput>
1186 return "LandsatTM ThinCloudsSpectralRule";
1202 this->
SetMinMax(newPixel, &max13, &min123, &max123, &min12347, &max12347, &max234, &max45);
1205 bool result = (min123 >= (this->
m_TV1 * max123))
1206 && (newPixel[this->
m_TM4] >= max123)
1207 && !((newPixel[this->
m_TM1] <= newPixel[this->
m_TM2]
1208 && newPixel[this->
m_TM2] <= newPixel[this->
m_TM3]
1209 && newPixel[this->
m_TM3] <= newPixel[this->
m_TM4])
1212 && (newPixel[this->
m_TM5] >= this->
m_TV1 * newPixel[this->m_TM4])
1213 && (newPixel[this->
m_TM5] >= this->
m_TV1 * max123)
1216 return static_cast<TOutput
>(result);
1234 template <
class TInput,
class TOutput>
1245 return "LandsatTM SnowOrIceSpectralRule";
1261 this->
SetMinMax(newPixel, &max13, &min123, &max123, &min12347, &max12347, &max234, &max45);
1264 bool result = (min123 >= (this->
m_TV1 * max123))
1265 && (newPixel[this->
m_TM4] >= (this->
m_TV1 * max123))
1267 && (newPixel[this->
m_TM5] <= this->
m_TV1 * min123)
1268 && (newPixel[this->
m_TM5] <= this->
m_TV1 * max123)
1270 && (newPixel[this->
m_TM7] <= this->
m_TV1 * min123);
1272 return static_cast<TOutput
>(result);
1291 template <
class TInput,
class TOutput>
1302 return "LandsatTM WaterOrShadowSpectralRule";
1311 bool result = (newPixel[this->
m_TM1] >= newPixel[this->
m_TM2])
1312 && (newPixel[this->
m_TM2] >= newPixel[this->
m_TM3])
1313 && (newPixel[this->
m_TM3] >= newPixel[this->
m_TM4])
1314 && (newPixel[this->
m_TM4] >= newPixel[this->
m_TM5])
1315 && (newPixel[this->
m_TM4] >= newPixel[this->
m_TM7]);
1317 return static_cast<TOutput
>(result);
1336 template <
class TInput,
class TOutput>
1347 return "LandsatTM PitbogOrGreenhouseSpectralRule";
1363 this->
SetMinMax(newPixel, &max13, &min123, &max123, &min12347, &max12347, &max234, &max45);
1366 bool result = (newPixel[this->
m_TM3] >= this->
m_TV1 * newPixel[this->
m_TM1])
1368 && (max123 <= this->
m_TV1 * newPixel[this->
m_TM4])
1371 && (min123 >= this->
m_TV1 * newPixel[this->
m_TM7]);
1374 return static_cast<TOutput
>(result);
1392 template <
class TInput,
class TOutput>
1403 return "LandsatTM DominantBlueSpectralRule";
1412 bool result = (newPixel[this->
m_TM1] >= this->
m_TV1 * newPixel[this->
m_TM2])
1419 return static_cast<TOutput
>(result);
1438 template <
class TInput,
class TOutput>
1449 return "LandsatTM VegetationSpectralRule";
1465 this->
SetMinMax(newPixel, &max13, &min123, &max123, &min12347, &max12347, &max234, &max45);
1468 bool result = (newPixel[this->
m_TM2] >= this->
m_TV2 * newPixel[this->
m_TM1])
1471 && (newPixel[this->
m_TM4] > max123)
1473 && (newPixel[this->
m_TM5] >= this->
m_TV1 * newPixel[this->m_TM3])
1477 return static_cast<TOutput
>(result);
1496 template <
class TInput,
class TOutput>
1507 return "LandsatTM RangelandSpectralRule";
1523 this->
SetMinMax(newPixel, &max13, &min123, &max123, &min12347, &max12347, &max234, &max45);
1526 bool result = (newPixel[this->
m_TM2] >= this->
m_TV2 * newPixel[this->
m_TM1])
1528 && (newPixel[this->
m_TM4] > max123)
1529 && (newPixel[this->m_TM3] < this->
m_TV1 * newPixel[this->
m_TM4])
1531 && (newPixel[this->
m_TM5] >= this->
m_TV1 * newPixel[this->m_TM4])
1532 && (newPixel[this->
m_TM5] > max123)
1533 && (newPixel[this->
m_TM7] < this->
m_TV1 * max45)
1534 && (newPixel[this->
m_TM5] >= newPixel[this->
m_TM7]);
1537 return static_cast<TOutput
>(result);
1555 template <
class TInput,
class TOutput>
1566 return "LandsatTM BarrenLandOrBuiltUpOrCloudsSpectralRule";
1582 this->
SetMinMax(newPixel, &max13, &min123, &max123, &min12347, &max12347, &max234, &max45);
1585 bool result = (newPixel[this->
m_TM3] >= this->
m_TV2 * newPixel[this->
m_TM1])
1587 && (newPixel[this->
m_TM4] >= this->
m_TV1 * max123)
1588 && (newPixel[this->
m_TM5] >= max123)
1591 && (newPixel[this->
m_TM7] >= this->
m_TV2 * max45);
1593 return static_cast<TOutput
>(result);
1611 template <
class TInput,
class TOutput>
1622 return "LandsatTM FlatResponseBarrenLandOrBuiltUpSpectralRule";
1638 this->
SetMinMax(newPixel, &max13, &min123, &max123, &min12347, &max12347, &max234, &max45);
1641 bool result = (newPixel[this->
m_TM5] >= this->
m_TV1 * max12347)
1642 && (min12347 >= this->
m_TV2 * newPixel[this->
m_TM5]);
1644 return static_cast<TOutput
>(result);
1663 template <
class TInput,
class TOutput>
1674 return "LandsatTM ShadowWithBarrenLandSpectralRule";
1683 bool result = (newPixel[this->
m_TM1] >= newPixel[this->
m_TM2])
1684 && (newPixel[this->
m_TM2] >= newPixel[this->
m_TM3])
1686 && (newPixel[this->
m_TM1] >= newPixel[this->
m_TM5])
1688 && (newPixel[this->m_TM5] >= this->
m_TV1 * newPixel[this->
m_TM7]);
1690 return static_cast<TOutput
>(result);
1708 template <
class TInput,
class TOutput>
1719 return "LandsatTM ShadowWithVegetationSpectralRule";
1728 bool result = (newPixel[this->
m_TM1] >= newPixel[this->
m_TM2])
1729 && (newPixel[this->
m_TM2] >= newPixel[this->
m_TM3])
1731 && (newPixel[this->m_TM3] < this->
m_TV1 * newPixel[this->
m_TM4])
1733 && (newPixel[this->m_TM3] >= this->
m_TV2 * newPixel[this->
m_TM5])
1736 return static_cast<TOutput
>(result);
1754 template <
class TInput,
class TOutput>
1765 return "LandsatTM ShadowCloudOrSnowSpectralRule";
1781 this->
SetMinMax(newPixel, &max13, &min123, &max123, &min12347, &max12347, &max234, &max45);
1784 bool result = (newPixel[this->
m_TM1] >= this->
m_TV1 * max234)
1785 && (max234 >= this->
m_TV1 * newPixel[this->
m_TM1])
1786 && (newPixel[this->
m_TM5] < newPixel[this->
m_TM1])
1787 && (newPixel[this->
m_TM7] < this->
m_TV1 * newPixel[this->m_TM1]);
1789 return static_cast<TOutput
>(result);
1807 template <
class TInput,
class TOutput>
1818 return "LandsatTM WetlandSpectralRule";
1827 bool result = (newPixel[this->
m_TM1] >= newPixel[this->
m_TM2])
1828 && (newPixel[this->
m_TM2] >= newPixel[this->
m_TM3])
1830 && (newPixel[this->m_TM3] < newPixel[this->
m_TM4])
1832 && (newPixel[this->
m_TM5] >= this->
m_TV1 * newPixel[this->m_TM4])
1834 && (newPixel[this->
m_TM5] >= newPixel[this->
m_TM7]);
1836 return static_cast<TOutput
>(result);