/usr/include/OTB-5.8/otbSpectralAngleDataNodeFeatureFunction.txx 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 | /*=========================================================================
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 otbSpectralAngleDataNodeFeatureFunction_txx
#define otbSpectralAngleDataNodeFeatureFunction_txx
#include "otbSpectralAngleDataNodeFeatureFunction.h"
namespace otb
{
/**
* Constructor
*/
template<class TImage, class TCoordRep, class TPrecision>
SpectralAngleDataNodeFeatureFunction<TImage, TCoordRep, TPrecision>::SpectralAngleDataNodeFeatureFunction() :
m_Radius(2)
{
//Example for QuickBird images (on a specific image)
m_RefPixel.SetSize(4);
m_RefPixel.SetElement(0, 252.284);
m_RefPixel.SetElement(1, 357.3);
m_RefPixel.SetElement(2, 232.644);
m_RefPixel.SetElement(3, 261.558);
}
/**
* Standard "PrintSelf" method
*/
template<class TImage, class TCoordRep, class TPrecision>
void SpectralAngleDataNodeFeatureFunction<TImage, TCoordRep, TPrecision>::PrintSelf(std::ostream& os,
itk::Indent indent) const
{
Superclass::PrintSelf(os, indent);
os << indent << "Reference Pixel: " << m_RefPixel << std::endl;
}
template<class TImage, class TCoordRep, class TPrecision>
typename SpectralAngleDataNodeFeatureFunction<TImage, TCoordRep, TPrecision>::OutputType SpectralAngleDataNodeFeatureFunction<
TImage, TCoordRep, TPrecision>::Evaluate(const DataNodeType& node) const
{
// TODO faire avce un ikk
const typename ImageLineIteratorType::PathType* path;
switch (node.GetNodeType())
{
case FEATURE_POINT:
{
itkExceptionMacro(<< "This DataNode type is not handle yet");
break;
}
case FEATURE_LINE:
{
path = node.GetLine();
break;
}
case FEATURE_POLYGON:
{
path = node.GetPolygonExteriorRing();
break;
}
default:
{
itkExceptionMacro(<< "This DataNode type is not handle yet");
break;
}
}
std::vector<std::pair<IndexType, IndexType> > splitedLineIdNeigh;
std::vector<std::pair<IndexType, IndexType> > splitedLineIdCentral;
// Split line and polygon into segment (ie. line with two vertex
VertexListConstIteratorType it1 = path->GetVertexList()->Begin();
VertexListConstIteratorType it2 = path->GetVertexList()->Begin();
VertexListConstIteratorType itStop = path->GetVertexList()->End();
++it2;
if (it2 == itStop)
{
itkExceptionMacro(<< "Invalid DataNode, must at least contain two points");
}
while (it1 != itStop && it2 != itStop)
{
IndexType id1, id2;
id1[0] = static_cast<int> (it1.Value()[0]);
id1[1] = static_cast<int> (it1.Value()[1]);
id2[0] = static_cast<int> (it2.Value()[0]);
id2[1] = static_cast<int> (it2.Value()[1]);
// Compute the direction of the current line
itk::Vector<double, 2> direction;
direction[0] = it2.Value()[0] - it1.Value()[0];
direction[1] = it2.Value()[1] - it1.Value()[1];
direction.Normalize();
// Compute the orthogonal direction of the current line
itk::Vector<double, 2> orthogonalDirection;
orthogonalDirection[0] = direction[1];
orthogonalDirection[1] = -direction[0];
splitedLineIdCentral.push_back(IndexPairType(id1, id2));
for (unsigned int j = 1; j <= m_Radius; ++j)
{
IndexType shift11, shift12;
shift11[0] = id1[0] - j * orthogonalDirection[0];
shift11[1] = id1[1] - j * orthogonalDirection[1];
shift12[0] = id1[0] + j * orthogonalDirection[0];
shift12[1] = id1[1] + j * orthogonalDirection[1];
IndexType shift21, shift22;
shift21[0] = id2[0] - j * orthogonalDirection[0];
shift21[1] = id2[1] - j * orthogonalDirection[1];
shift22[0] = id2[0] + j * orthogonalDirection[0];
shift22[1] = id2[1] + j * orthogonalDirection[1];
splitedLineIdCentral.push_back(IndexPairType(shift11, shift21));
splitedLineIdCentral.push_back(IndexPairType(shift12, shift22));
}
++it1;
++it2;
}
// in FEATURE_POLYGON case, first point appears twice (first vertex and last vertew, thus we create a line of 1 point...)
if (node.GetNodeType() == FEATURE_POLYGON)
{
splitedLineIdCentral.pop_back();
}
double centralAccSpectralAngle = 0.;
//double centralAccSpectralAngleSecondOrder = 0.;
double centralNbVisitedPixel = 0.;
for (unsigned int i = 0; i < splitedLineIdCentral.size(); ++i)
{
LineIteratorType lineIt(this->GetInputImage(), splitedLineIdCentral[i].first, splitedLineIdCentral[i].second);
lineIt.GoToBegin();
while (!lineIt.IsAtEnd())
{
if (this->IsInsideBuffer(lineIt.GetIndex()))
{
PixelType currPixel = this->GetInputImage()->GetPixel( lineIt.GetIndex() );
double angle = m_SpectralAngleFunctor(currPixel, this->GetRefPixel());
centralAccSpectralAngle += angle;
//centralAccSpectralAngleSecondOrder += angle * angle;
centralNbVisitedPixel += 1;
}
++lineIt;
}
}
OutputType output;
double meanCentral = 0.;
//double stddevCentral = 0.;
if (centralNbVisitedPixel != 0.)
{
meanCentral = static_cast<double> (centralAccSpectralAngle) / centralNbVisitedPixel;
//stddevCentral = vcl_sqrt( centralAccSpectralAngleSecondOrder/centralNbVisitedPixel - meanCentral*meanCentral );
}
if (meanCentral == 0.)
{
output.push_back(static_cast<PrecisionType> (0.));
}
else
{
// Compute the descriptor here
// meanCentral is in [0, pi]
// We need a descriptor in [0 1]
double descriptor = meanCentral / otb::CONST_PI;
output.push_back(static_cast<PrecisionType>( descriptor ));
}
output.push_back(static_cast<PrecisionType> (centralAccSpectralAngle));
output.push_back(static_cast<PrecisionType> (centralNbVisitedPixel));
return output;
}
} // end namespace otb
#endif
|