From a1b00917e899deb73df8f9251bc895eaf7f49b88 Mon Sep 17 00:00:00 2001 From: Cyrille Valladeau <cyrille.valladeau@c-s.fr> Date: Wed, 18 May 2011 18:42:22 +0200 Subject: [PATCH] ENH: improve to handle neighborhood --- ...tbSpectralAngleDataNodeFeatureFunction.txx | 61 +++---------------- 1 file changed, 9 insertions(+), 52 deletions(-) diff --git a/Code/BasicFilters/otbSpectralAngleDataNodeFeatureFunction.txx b/Code/BasicFilters/otbSpectralAngleDataNodeFeatureFunction.txx index 12883167db..756cd50f04 100644 --- a/Code/BasicFilters/otbSpectralAngleDataNodeFeatureFunction.txx +++ b/Code/BasicFilters/otbSpectralAngleDataNodeFeatureFunction.txx @@ -20,7 +20,6 @@ #include "otbSpectralAngleDataNodeFeatureFunction.h" -//#include "itkImageIteratorWithIndex.h" namespace otb { @@ -95,16 +94,13 @@ typename SpectralAngleDataNodeFeatureFunction<TImage, TCoordRep, TPrecision> typename LineType::VertexListConstIteratorType it1 = path->GetVertexList()->Begin(); typename LineType::VertexListConstIteratorType it2 = path->GetVertexList()->Begin(); typename LineType::VertexListConstIteratorType itStop = path->GetVertexList()->End(); - + ++it2; if( it2 == itStop ) { itkExceptionMacro(<< "Invalid DataNode, must at least contain two points"); } - - - //unsigned int count = 0; while ( it1 != itStop && it2 != itStop) { IndexType id1, id2; @@ -114,7 +110,6 @@ typename SpectralAngleDataNodeFeatureFunction<TImage, TCoordRep, TPrecision> 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; @@ -127,41 +122,21 @@ typename SpectralAngleDataNodeFeatureFunction<TImage, TCoordRep, TPrecision> 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 )); } ++it1; ++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 ) { - it2--; - IndexType id1, id2; - id1[0] = static_cast<int>(path->GetVertexList()->Begin().Value()[0]); - 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 )); - } + splitedLineIdCentral.pop_back(); + splitedLineIdNeigh.pop_back(); + splitedLineIdNeigh.pop_back(); } @@ -172,20 +147,11 @@ typename SpectralAngleDataNodeFeatureFunction<TImage, TCoordRep, TPrecision> { LineIteratorType lineIt( this->GetInputImage(), splitedLineIdCentral[i].first, splitedLineIdCentral[i].second); lineIt.GoToBegin(); - //itk::ImageIteratorWithIndex<TImage> lol(this->GetInputImage()); + while(!lineIt.IsAtEnd()) { 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; 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++) @@ -204,22 +170,13 @@ typename SpectralAngleDataNodeFeatureFunction<TImage, TCoordRep, TPrecision> 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(); while(!lineIt.IsAtEnd()) { 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; 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++) -- GitLab