/usr/include/OTB-5.8/otbCBAMI.h is in libotb-dev 5.8.0+dfsg-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 | /*=========================================================================
Program: ORFEO Toolbox
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
See OTBCopyright.txt for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
#ifndef otbCBAMI_h
#define otbCBAMI_h
#include <vector>
#include "itkMath.h"
namespace otb
{
namespace Functor
{
template<class TInput1, class TInput2, class TOutput>
class CBAMI
{
public:
typedef typename std::vector<TOutput> VectorType;
typedef typename VectorType::iterator IteratorType;
typedef typename std::vector<VectorType> VectorOfVectorType;
typedef typename VectorOfVectorType::iterator VecOfVecIteratorType;
CBAMI() {}
virtual ~CBAMI() {}
inline TOutput operator ()(const TInput1& itA,
const TInput2& itB) const
{
double epsilon = 0.01;
VectorType vecA;
VectorType vecB;
for (unsigned long pos = 0; pos < itA.Size(); ++pos)
{
vecA.push_back(static_cast<double>(itA.GetPixel(pos)));
vecB.push_back(static_cast<double>(itB.GetPixel(pos)));
}
normalizeInPlace(vecA);
normalizeInPlace(vecB);
return static_cast<TOutput>(-vcl_log(static_cast<double>(PhiMI(vecA, vecB) + epsilon)));
}
protected:
inline void normalizeInPlace(VectorType vx) const
{
TOutput Ex = 0.0;
IteratorType itx;
for (itx = vx.begin(); itx < vx.end(); ++itx)
{
Ex += static_cast<TOutput>(*itx);
}
Ex /= (vx.size());
TOutput Vx = 0.0;
for (itx = vx.begin(); itx < vx.end(); ++itx)
{
Vx += static_cast<TOutput>(vcl_pow(static_cast<double>((*itx) - Ex), 2));
}
Vx /= (vx.size());
for (itx = vx.begin(); itx < vx.end(); ++itx)
{
(*itx) = ((*itx) - Ex) / static_cast<TOutput>(vcl_sqrt(static_cast<double>(Vx)));
}
}
inline TOutput Exyc(VectorType vx, VectorType vy) const
{
TOutput Exy = 0.0;
TOutput Ex = 0.0;
TOutput Ey = 0.0;
IteratorType itx;
IteratorType ity;
for (itx = vx.begin(), ity = vy.begin(); itx < vx.end(); ++itx, ++ity)
{
//Ex += (*itx);
//Ey += (*ity);
Exy += (*itx) * (*ity);
}
//Ex /= (vx.size());
//Ey /= (vy.size());
Exy /= (vx.size());
return Exy - Ex * Ey;
}
inline TOutput Exyztc(VectorType vx, VectorType vy, VectorType vz, VectorType vt) const
{
TOutput Exyzt = 0.0;
TOutput Exyz = 0.0;
TOutput Exyt = 0.0;
TOutput Exzt = 0.0;
TOutput Eyzt = 0.0;
TOutput Exy = 0.0;
TOutput Exz = 0.0;
TOutput Ext = 0.0;
TOutput Eyz = 0.0;
TOutput Eyt = 0.0;
TOutput Ezt = 0.0;
TOutput Ex = 0.0;
TOutput Ey = 0.0;
TOutput Ez = 0.0;
TOutput Et = 0.0;
IteratorType itx;
IteratorType ity;
IteratorType itz;
IteratorType itt;
for (itx = vx.begin(),
ity = vy.begin(),
itz = vz.begin(),
itt = vt.begin();
itx < vx.end();
++itx,
++ity,
itz++,
itt++)
{
//Ex += (*itx);
//Ey += (*ity);
//Ez += (*itz);
//Et += (*itt);
Exy += (*itx) * (*ity);
Exz += (*itx) * (*itz);
Ext += (*itx) * (*itt);
Eyz += (*ity) * (*itz);
Eyt += (*ity) * (*itt);
Ezt += (*itz) * (*itt);
Exyz += (*itx) * (*ity) * (*itz);
Exyt += (*itx) * (*ity) * (*itt);
Exzt += (*itx) * (*itz) * (*itt);
Eyzt += (*ity) * (*itz) * (*itt);
Exyzt += (*itx) * (*ity) * (*itz) * (*itt);
}
/*Ex /= (vx.size());
Ey /= (vx.size());
Ez /= (vx.size());
Et /= (vx.size()); */
Exy /= (vx.size());
Exz /= (vx.size());
Ext /= (vx.size());
Eyz /= (vx.size());
Eyt /= (vx.size());
Ezt /= (vx.size());
Exyz /= (vx.size());
Exyt /= (vx.size());
Exzt /= (vx.size());
Eyzt /= (vx.size());
TOutput result = Exyzt - Exyz * Et - Exyt * Ez - Exzt * Ey - Eyzt * Ex +
Exy * Ez * Et + Exz * Et * Ey + Ext * Ey * Ez + Eyz * Et * Ex + Eyt * Ex * Ez + Ezt * Ex * Ey -
3 * Ex * Ey * Ez * Et;
return result;
}
inline TOutput Rxy(VectorType va, VectorType vb) const
{
return Exyc(va, vb);
}
inline TOutput Qxijkl(VectorType va, VectorType vb, VectorType vc, VectorType vd) const
{
// IteratorType ita;
// IteratorType itb;
// IteratorType itc;
// IteratorType itd;
TOutput Eabcd_c = Exyztc(va, vb, vc, vd);
TOutput Eab_c = Exyc(va, vb);
TOutput Eac_c = Exyc(va, vc);
TOutput Ead_c = Exyc(va, vd);
TOutput Ecd_c = Exyc(vc, vd);
TOutput Ebd_c = Exyc(vb, vd);
TOutput Ebc_c = Exyc(vb, vc);
return Eabcd_c - Eab_c * Ecd_c - Eac_c * Ebd_c - Ead_c * Ebc_c;
}
inline TOutput PhiMI(VectorType v1, VectorType v2) const
{
VectorOfVectorType donnees;
donnees.push_back(v1);
donnees.push_back(v2);
VecOfVecIteratorType iti;
VecOfVecIteratorType itj;
VecOfVecIteratorType itk;
VecOfVecIteratorType itl;
TOutput termeR = 0.0;
TOutput termeQ = 0.0;
for (iti = donnees.begin(); iti < donnees.end(); ++iti)
for (itj = donnees.begin(); itj < donnees.end(); ++itj)
{
if (iti != itj) termeR += static_cast<TOutput>(vcl_pow(static_cast<double>(Rxy((*iti), (*itj))), 2));
for (itk = donnees.begin(); itk < donnees.end(); ++itk)
for (itl = donnees.begin(); itl < donnees.end(); itl++)
{
if ((iti != itj) || (iti != itk) ||
(iti !=
itl))
termeQ +=
static_cast<TOutput>(vcl_pow(static_cast<double>(Qxijkl((*iti), (*itj), (*itk), (*itl))), 2));
}
}
return 1.0 / 4.0 * termeR + 1.0 / 48.0 * termeQ;
}
};
}
}
#endif
|