Skip to content
Snippets Groups Projects
Commit a1b00917 authored by Cyrille Valladeau's avatar Cyrille Valladeau
Browse files

ENH: improve to handle neighborhood

parent a5113bdf
No related branches found
No related tags found
No related merge requests found
...@@ -20,7 +20,6 @@ ...@@ -20,7 +20,6 @@
#include "otbSpectralAngleDataNodeFeatureFunction.h" #include "otbSpectralAngleDataNodeFeatureFunction.h"
//#include "itkImageIteratorWithIndex.h"
namespace otb namespace otb
{ {
...@@ -95,16 +94,13 @@ typename SpectralAngleDataNodeFeatureFunction<TImage, TCoordRep, TPrecision> ...@@ -95,16 +94,13 @@ typename SpectralAngleDataNodeFeatureFunction<TImage, TCoordRep, TPrecision>
typename LineType::VertexListConstIteratorType it1 = path->GetVertexList()->Begin(); typename LineType::VertexListConstIteratorType it1 = path->GetVertexList()->Begin();
typename LineType::VertexListConstIteratorType it2 = path->GetVertexList()->Begin(); typename LineType::VertexListConstIteratorType it2 = path->GetVertexList()->Begin();
typename LineType::VertexListConstIteratorType itStop = path->GetVertexList()->End(); typename LineType::VertexListConstIteratorType itStop = path->GetVertexList()->End();
++it2; ++it2;
if( it2 == itStop ) if( it2 == itStop )
{ {
itkExceptionMacro(<< "Invalid DataNode, must at least contain two points"); itkExceptionMacro(<< "Invalid DataNode, must at least contain two points");
} }
//unsigned int count = 0;
while ( it1 != itStop && it2 != itStop) while ( it1 != itStop && it2 != itStop)
{ {
IndexType id1, id2; IndexType id1, id2;
...@@ -114,7 +110,6 @@ typename SpectralAngleDataNodeFeatureFunction<TImage, TCoordRep, TPrecision> ...@@ -114,7 +110,6 @@ typename SpectralAngleDataNodeFeatureFunction<TImage, TCoordRep, TPrecision>
id2[1] = static_cast<int>(it2.Value()[1]); id2[1] = static_cast<int>(it2.Value()[1]);
splitedLineIdCentral.push_back(IndexPairType( id1, id2 )); splitedLineIdCentral.push_back(IndexPairType( id1, id2 ));
for(unsigned int j=m_StartNeighborhoodRadius; j<m_StopNeighborhoodRadius; j++) for(unsigned int j=m_StartNeighborhoodRadius; j<m_StopNeighborhoodRadius; j++)
{ {
IndexType shift11, shift12; IndexType shift11, shift12;
...@@ -127,41 +122,21 @@ typename SpectralAngleDataNodeFeatureFunction<TImage, TCoordRep, TPrecision> ...@@ -127,41 +122,21 @@ typename SpectralAngleDataNodeFeatureFunction<TImage, TCoordRep, TPrecision>
shift21[1] = id2[1]-j; shift21[1] = id2[1]-j;
shift22[0] = id2[0]+j; shift22[0] = id2[0]+j;
shift22[1] = id2[1]+j; shift22[1] = id2[1]+j;
splitedLineIdNeigh.push_back(IndexPairType( shift11, shift21 )); splitedLineIdNeigh.push_back(IndexPairType( shift11, shift21 ));
splitedLineIdNeigh.push_back(IndexPairType( shift12, shift22 )); splitedLineIdNeigh.push_back(IndexPairType( shift12, shift22 ));
} }
++it1; ++it1;
++it2; ++it2;
} }
// in FEATURE_POLYGON case, first point appears twice (fisrt vertex and last vertew, thus we create a line of 1 point...)
if( node.GetNodeType() == FEATURE_POLYGON ) if( node.GetNodeType() == FEATURE_POLYGON )
{ {
it2--; splitedLineIdCentral.pop_back();
IndexType id1, id2; splitedLineIdNeigh.pop_back();
id1[0] = static_cast<int>(path->GetVertexList()->Begin().Value()[0]); splitedLineIdNeigh.pop_back();
id1[1] = static_cast<int>(path->GetVertexList()->Begin().Value()[1]);
id2[0] = static_cast<int>(it2.Value()[0]);
id2[1] = static_cast<int>(it2.Value()[1]);
splitedLineIdCentral.push_back(IndexPairType( id1, id2 ));
for(unsigned int j=m_StartNeighborhoodRadius; j<m_StopNeighborhoodRadius; j++)
{
IndexType shift11, shift12;
shift11[0] = id1[0]-j;
shift11[1] = id1[1]-j;
shift12[0] = id1[0]+j;
shift12[1] = id1[1]+j;
IndexType shift21, shift22;
shift21[0] = id2[0]-j;
shift21[1] = id2[1]-j;
shift22[0] = id2[0]+j;
shift22[1] = id2[1]+j;
splitedLineIdNeigh.push_back(IndexPairType( shift11, shift21 ));
splitedLineIdNeigh.push_back(IndexPairType( shift12, shift22 ));
}
} }
...@@ -172,20 +147,11 @@ typename SpectralAngleDataNodeFeatureFunction<TImage, TCoordRep, TPrecision> ...@@ -172,20 +147,11 @@ typename SpectralAngleDataNodeFeatureFunction<TImage, TCoordRep, TPrecision>
{ {
LineIteratorType lineIt( this->GetInputImage(), splitedLineIdCentral[i].first, splitedLineIdCentral[i].second); LineIteratorType lineIt( this->GetInputImage(), splitedLineIdCentral[i].first, splitedLineIdCentral[i].second);
lineIt.GoToBegin(); lineIt.GoToBegin();
//itk::ImageIteratorWithIndex<TImage> lol(this->GetInputImage());
while(!lineIt.IsAtEnd()) while(!lineIt.IsAtEnd())
{ {
if(this->IsInsideBuffer(lineIt.GetIndex())) if(this->IsInsideBuffer(lineIt.GetIndex()))
{ {
/*
std::cout << "m_SpectralAngleFunctor : "
<< m_SpectralAngleFunctor(lineIt.Get(), this->GetRefPixel())
<< " - currentPixel : "
<< lineIt.Get()
<< " - RefPixel : "
<< this->GetRefPixel()
<< std::endl;
*/
PixelType currPixel; PixelType currPixel;
currPixel.SetSize(std::min(this->GetRefPixel().Size(), lineIt.Get().Size())); currPixel.SetSize(std::min(this->GetRefPixel().Size(), lineIt.Get().Size()));
for (unsigned int i=0; i<std::min(this->GetRefPixel().Size(), lineIt.Get().Size()); i++) for (unsigned int i=0; i<std::min(this->GetRefPixel().Size(), lineIt.Get().Size()); i++)
...@@ -204,22 +170,13 @@ typename SpectralAngleDataNodeFeatureFunction<TImage, TCoordRep, TPrecision> ...@@ -204,22 +170,13 @@ typename SpectralAngleDataNodeFeatureFunction<TImage, TCoordRep, TPrecision>
for(unsigned int i=0; i<splitedLineIdNeigh.size(); i++) for(unsigned int i=0; i<splitedLineIdNeigh.size(); i++)
{ {
LineIteratorType lineIt( this->GetInputImage(), splitedLineIdCentral[i].first, splitedLineIdCentral[i].second); LineIteratorType lineIt( this->GetInputImage(), splitedLineIdNeigh[i].first, splitedLineIdNeigh[i].second);
lineIt.GoToBegin(); lineIt.GoToBegin();
while(!lineIt.IsAtEnd()) while(!lineIt.IsAtEnd())
{ {
if(this->IsInsideBuffer(lineIt.GetIndex())) if(this->IsInsideBuffer(lineIt.GetIndex()))
{ {
/*
std::cout << "m_SpectralAngleFunctor : "
<< m_SpectralAngleFunctor(lineIt.Get(), this->GetRefPixel())
<< " - currentPixel : "
<< lineIt.Get()
<< " - RefPixel : "
<< this->GetRefPixel()
<< std::endl;
*/
PixelType currPixel; PixelType currPixel;
currPixel.SetSize(std::min(this->GetRefPixel().Size(), lineIt.Get().Size())); currPixel.SetSize(std::min(this->GetRefPixel().Size(), lineIt.Get().Size()));
for (unsigned int i=0; i<std::min(this->GetRefPixel().Size(), lineIt.Get().Size()); i++) for (unsigned int i=0; i<std::min(this->GetRefPixel().Size(), lineIt.Get().Size()); i++)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment