From f472af9de14f2156a6b8f60b11bafe18a72308af Mon Sep 17 00:00:00 2001 From: Julien Michel <julien.michel@orfeo-toolbox.org> Date: Fri, 6 Jun 2014 14:44:43 +0200 Subject: [PATCH] Backed out changeset 341332139c20 Changes commited by mistake --- ...OfOrientedGradientCovariantImageFunction.h | 3 - ...OrientedGradientCovariantImageFunction.txx | 60 ++++--------------- 2 files changed, 11 insertions(+), 52 deletions(-) diff --git a/Code/FeatureExtraction/otbHistogramOfOrientedGradientCovariantImageFunction.h b/Code/FeatureExtraction/otbHistogramOfOrientedGradientCovariantImageFunction.h index 2ae484cf3a..dc864dfa6d 100644 --- a/Code/FeatureExtraction/otbHistogramOfOrientedGradientCovariantImageFunction.h +++ b/Code/FeatureExtraction/otbHistogramOfOrientedGradientCovariantImageFunction.h @@ -126,7 +126,6 @@ public: itkSetMacro( NumberOfOrientationBins, unsigned int ); itkGetConstReferenceMacro( NumberOfOrientationBins, unsigned int ); - itkGetMacro(PrincipalOrientation,double); protected: HistogramOfOrientedGradientCovariantImageFunction(); @@ -142,8 +141,6 @@ private: // Number of bins in the orientation unsigned int m_NumberOfOrientationBins; - - mutable double m_PrincipalOrientation; }; } // namespace otb diff --git a/Code/FeatureExtraction/otbHistogramOfOrientedGradientCovariantImageFunction.txx b/Code/FeatureExtraction/otbHistogramOfOrientedGradientCovariantImageFunction.txx index d57f5be35a..94bbfd8695 100644 --- a/Code/FeatureExtraction/otbHistogramOfOrientedGradientCovariantImageFunction.txx +++ b/Code/FeatureExtraction/otbHistogramOfOrientedGradientCovariantImageFunction.txx @@ -33,7 +33,7 @@ namespace otb template <class TInputImage, class TOutputPrecision, class TCoordRep> HistogramOfOrientedGradientCovariantImageFunction<TInputImage, TOutputPrecision, TCoordRep> ::HistogramOfOrientedGradientCovariantImageFunction() : m_NeighborhoodRadius(8), - m_NumberOfOrientationBins(72) + m_NumberOfOrientationBins(18) {} template <class TInputImage, class TOutputPrecision, class TCoordRep> @@ -56,14 +56,12 @@ HistogramOfOrientedGradientCovariantImageFunction<TInputImage, TOutputPrecision, // Check for input image if( !this->GetInputImage() ) { - std::cerr<<"No input image."<<std::endl; return hog; } // Check for out of buffer if ( !this->IsInsideBuffer( index ) ) { - std::cerr<<"Outside of image buffer (idx="<<index<<")"<<std::endl; return hog; } @@ -122,11 +120,11 @@ HistogramOfOrientedGradientCovariantImageFunction<TInputImage, TOutputPrecision, // Determine the bin index (shift of otb::CONST_PI since atan2 values // lies in [-pi, pi] - unsigned int binIndex = vcl_floor((otb::CONST_PI + angle)/orientationBinWidth+0.5); + unsigned int binIndex = vcl_floor((otb::CONST_PI + angle)/orientationBinWidth); - //Handle special case where angle = pi, and binIndex is out-of-bound + // Handle special case where angle = pi, and binIndex is out-of-bound if(binIndex == m_NumberOfOrientationBins) - binIndex= 0; + binIndex=m_NumberOfOrientationBins-1; // Cumulate values globalOrientationHistogram[binIndex]+= magnitude * gWeight; @@ -144,8 +142,6 @@ HistogramOfOrientedGradientCovariantImageFunction<TInputImage, TOutputPrecision, // Retrieve current value double currentValue = globalOrientationHistogram[i]; - std::cout<<i<<"\t"<<currentValue<<"\t"<<maxOrientationHistogramValue<<std::endl; - // Look for new maximum if(maxOrientationHistogramValue<currentValue) { @@ -154,10 +150,8 @@ HistogramOfOrientedGradientCovariantImageFunction<TInputImage, TOutputPrecision, } } - std::cout<<"bin: "<<maxOrientationHistogramBin<<", "<<orientationBinWidth<<", "<<maxOrientationHistogramBin * orientationBinWidth<<std::endl; - // Derive principal orientation - m_PrincipalOrientation = (maxOrientationHistogramBin) * orientationBinWidth - otb::CONST_PI; + double principalOrientation = maxOrientationHistogramBin * orientationBinWidth - otb::CONST_PI; // Initialize the five spatial bins std::vector<TOutputPrecision> centerHistogram(m_NumberOfOrientationBins, 0.); @@ -187,7 +181,7 @@ HistogramOfOrientedGradientCovariantImageFunction<TInputImage, TOutputPrecision, InputPixelType gradient = it.GetPixel(offset); // Then, compute the compensated gradient orientation - double angle = vcl_atan2(gradient[1], gradient[0]) - m_PrincipalOrientation; + double angle = vcl_atan2(gradient[1], gradient[0]) - principalOrientation; // Angle is supposed to lie with [-pi, pi], so we ensure that // compenstation did not introduce out-of-range values @@ -205,13 +199,13 @@ HistogramOfOrientedGradientCovariantImageFunction<TInputImage, TOutputPrecision, // Determine the bin index (shift of otb::CONST_PI since atan2 values // lies in [-pi, pi] - unsigned int binIndex = vcl_floor((otb::CONST_PI + angle)/orientationBinWidth + 0.5); + unsigned int binIndex = vcl_floor((otb::CONST_PI + angle)/orientationBinWidth); if(binIndex == m_NumberOfOrientationBins) binIndex=m_NumberOfOrientationBins-1; // Compute the angular position - double angularPosition = otb::CONST_PI + vcl_atan2((double)j, (double)i) - m_PrincipalOrientation; + double angularPosition = vcl_atan2((double)j, (double)i) - principalOrientation; // Angle is supposed to lie within [-pi, pi], so we ensure that // the compensation did not introduce out-of-range values @@ -253,35 +247,9 @@ HistogramOfOrientedGradientCovariantImageFunction<TInputImage, TOutputPrecision, } // Cumulate values - // globalOrientationHistogram[binIndex]+= magnitude * gWeight; - } - } - } - - bool m_SymetryCheck = true; - - if(m_SymetryCheck) - { - // Use the formula to check for symmetry - unsigned int sym_idx = 0; - double sym_max = 0; - - for(unsigned int i = 0; i < m_NumberOfOrientationBins/2;++i) - { - double current_sym_value = 0; - - for(unsigned int j = 0; j < m_NumberOfOrientationBins/2;++j) - { - current_sym_value+=globalOrientationHistogram[(i+j)%m_NumberOfOrientationBins]*globalOrientationHistogram[(i-j)%m_NumberOfOrientationBins]; - } - - if(current_sym_value > sym_max) - { - sym_idx = i; - sym_max = current_sym_value; + globalOrientationHistogram[binIndex]+= magnitude * gWeight; } } - m_PrincipalOrientation = (sym_idx+0.5) * orientationBinWidth - otb::CONST_PI; } // Build the final output @@ -291,13 +259,6 @@ HistogramOfOrientedGradientCovariantImageFunction<TInputImage, TOutputPrecision, hog.push_back(lowerRightHistogram); hog.push_back(lowerLeftHistogram); - - - - hog.push_back(globalOrientationHistogram); - - - // Normalize each histogram for(typename OutputType::iterator oIt = hog.begin(); oIt!=hog.end(); ++oIt) { @@ -316,7 +277,8 @@ HistogramOfOrientedGradientCovariantImageFunction<TInputImage, TOutputPrecision, (*vIt)*=scale; } } - + + // Return result return hog; } -- GitLab