diff --git a/Code/BasicFilters/otbEdgeDetectorImageFilter.txx b/Code/BasicFilters/otbEdgeDetectorImageFilter.txx index 604da9634bd1c26c087eccf9094e1c6474fff371..1d566a798d31b724033e39ee721bd5a9c0f27054 100644 --- a/Code/BasicFilters/otbEdgeDetectorImageFilter.txx +++ b/Code/BasicFilters/otbEdgeDetectorImageFilter.txx @@ -58,8 +58,9 @@ EdgeDetectorImageFilter<TInputImage, TOutputImage, TEdgeDetection> ::GenerateData() { m_Detector->SetInput( this->GetInput() ); - m_BinaryFilter->SetInput( m_Detector->GetOutput() ); +m_Detector->Update(); + m_BinaryFilter->SetInput( m_Detector->GetOutput() ); m_BinaryFilter->GraftOutput(this->GetOutput()); m_BinaryFilter->Update(); this->GraftOutput(m_BinaryFilter->GetOutput()); diff --git a/Code/FeatureExtraction/otbUrbanAreaDetectionImageFilter.h b/Code/FeatureExtraction/otbUrbanAreaDetectionImageFilter.h index dd59b3639a1ca28b41e9ada02808a8237531105f..38fb144b8b7bac848cfffe57b8d3c4138e3222be 100644 --- a/Code/FeatureExtraction/otbUrbanAreaDetectionImageFilter.h +++ b/Code/FeatureExtraction/otbUrbanAreaDetectionImageFilter.h @@ -39,6 +39,7 @@ PURPOSE. See the above copyright notices for more information. // POUR TEST #include "otbStreamingImageFileWriter.h" +#include "itkMultiplyImageFilter.h" namespace otb @@ -67,7 +68,6 @@ class RadiometricNonWaterNonVegetationIndexFunctor void SetGreenIndex(int id){ m_WaterFunctor.SetGIndex(id); }; void SetNIRIndex(int id){ m_VegetationFunctor.SetNIRIndex(id); m_WaterFunctor.SetNIRIndex(id); }; - unsigned int GetGreenIndex(){ return m_WaterFunctor.GetGIndex(); }; RadiometricNonWaterNonVegetationIndexFunctor(){} ~RadiometricNonWaterNonVegetationIndexFunctor(){}; @@ -85,7 +85,7 @@ class RadiometricNonWaterNonVegetationIndexFunctor lWIval = static_cast<ValueType>(std::max(0.,m_WaterFunctor(pInPix))); - lOutPix = vcl_sqrt(vcl_abs((1-lVIval)*(1-lWIval))); //sqrt : PAS MAL DU TOUT + lOutPix = vcl_sqrt(vcl_abs((1-lVIval)*(1-lWIval))); //sqrt // OU //lOutPix = vcl_sqrt((1-lVIval)*(1-lVIval)+(1-lWIval)*(1-lWIval)); // eucl : bof bof @@ -96,7 +96,10 @@ class RadiometricNonWaterNonVegetationIndexFunctor //lOutPix = vcl_sqrt(vcl_abs(1-lVIval)*vcl_abs(1-lWIval)); //sqrt2 : pareil que sqrt //lOutPix = 1-vcl_sqrt(vcl_abs(lVIval)*vcl_abs(lWIval)); //sqrt2 : NUUUUUUL //lOutPix = 1. - (vcl_abs(lVIval)+vcl_abs(lWIval)/2.);//Div : PAS MAL - //lOutPix = 1 - std::max(lVIval,lWIval); //MAX : PAS MAL DU TOUT +// if( lVIval || lWIval ) +// { +// lOutPix = 1 - std::max(lVIval,lWIval); //MAX : PAS MAL DU TOUT +// } /* Tester avec le log if(lVIval*lWIval) @@ -124,8 +127,7 @@ template<class TInput,class TOutput> class RadiometricNonWaterNonVegetationDetectionFunctor { public: - // utilise template double parsk sinon cast un truc entre 0 et 1 en unsigned char ce qui donne toujours 1... donc image constante a 1 a la sortie du filtre!!!! - typedef RadiometricNonWaterNonVegetationIndexFunctor<TInput /*, TOutput*/> RadiometricNonWaterNonVegetationIndexFunctorType; + typedef RadiometricNonWaterNonVegetationIndexFunctor<TInput> RadiometricNonWaterNonVegetationIndexFunctorType; RadiometricNonWaterNonVegetationDetectionFunctor() { @@ -136,13 +138,9 @@ public: ~RadiometricNonWaterNonVegetationDetectionFunctor() {}; inline TOutput operator()(const TInput& inPix) { - // The vegetation and water areas are put to 0. double indexesVal = static_cast<double>(m_RadiometricNonWaterNonVegetationIndexFunctor(inPix)); -// if(indexesVal>1e6) -// std::cout<<indexesVal<<std::endl; - if ( (indexesVal > m_LowerThreshold) && (indexesVal <= m_UpperThreshold) ) { return static_cast<TOutput>(1); @@ -162,8 +160,6 @@ public: void SetGreenIndex(int id){ m_RadiometricNonWaterNonVegetationIndexFunctor.SetGreenIndex(id); }; void SetNIRIndex(int id){ m_RadiometricNonWaterNonVegetationIndexFunctor.SetNIRIndex(id); }; - unsigned int GetGreenIndex(){ return m_RadiometricNonWaterNonVegetationIndexFunctor.GetGreenIndex(); }; - protected: RadiometricNonWaterNonVegetationIndexFunctorType m_RadiometricNonWaterNonVegetationIndexFunctor; @@ -206,22 +202,23 @@ public: typedef double SingleImagePixelType; typedef Image<SingleImagePixelType, 2> SingleImageType; typedef SingleImageType::SizeType SizeType; - typedef unsigned char BinaryImagePixelType; - typedef Image<BinaryImagePixelType, 2> BinaryImageType; + typedef typename OutputImageType::PixelType OutputImagePixelType; typedef typename VectorImageType::PixelType VectorImagePixelType; - typedef typename OutputImageType::PixelType OutputPixelType; + /** Filters typedefs */ // NonVegetationNonWaterIndexFilter - typedef Functor::RadiometricNonWaterNonVegetationDetectionFunctor< VectorImagePixelType, BinaryImagePixelType > FunctorType; - typedef MultiChannelRAndGAndNIRIndexImageFilter < VectorImageType,BinaryImageType, FunctorType > UrbanAreaExtractionFilterType; + typedef Functor::RadiometricNonWaterNonVegetationDetectionFunctor< VectorImagePixelType, OutputImagePixelType > FunctorType; + //typedef Functor::RadiometricNonWaterNonVegetationIndexFunctor< VectorImagePixelType, OutputImagePixelType > FunctorType; + typedef MultiChannelRAndGAndNIRIndexImageFilter < VectorImageType,OutputImageType, FunctorType > UrbanAreaExtractionFilterType; + typedef typename UrbanAreaExtractionFilterType::Pointer UrbanAreaExtrationFilterPointerType; // Erode/Dilate Filters - typedef typename itk::BinaryBallStructuringElement< BinaryImagePixelType, 2 > StructuringElementType; - typedef typename itk::BinaryErodeImageFilter<BinaryImageType,BinaryImageType,StructuringElementType> ErodeFilterType; - typedef typename itk::BinaryDilateImageFilter<BinaryImageType,BinaryImageType,StructuringElementType> DilateFilterType; + typedef typename itk::BinaryBallStructuringElement< OutputImagePixelType, 2 > StructuringElementType; + typedef typename itk::BinaryErodeImageFilter<OutputImageType,OutputImageType,StructuringElementType> ErodeFilterType; + typedef typename itk::BinaryDilateImageFilter<OutputImageType,OutputImageType,StructuringElementType> DilateFilterType; // MaskImageFilter - typedef typename itk::MaskImageFilter<VectorImageType,BinaryImageType> MaskImageFilterType; + typedef typename itk::MaskImageFilter<VectorImageType,OutputImageType> MaskImageFilterType; typedef typename MaskImageFilterType::Pointer MaskImageFilterPointerType; // Intensity typedef VectorImageToIntensityImageFilter<VectorImageType, SingleImageType> IntensityFilterType; @@ -233,13 +230,14 @@ public: typedef EdgeDensityImageFilter<SingleImageType, SingleImageType, SobelDetectorType, CountFunctionType> EdgeDensityFilterType; typedef typename EdgeDensityFilterType::Pointer EdgeDensityFilterPointerType; // Threshold - typedef itk::BinaryThresholdImageFilter<SingleImageType,BinaryImageType> ThresholdFilterType; - typedef ThresholdFilterType::Pointer ThresholdFilterPointerType; - - + typedef itk::BinaryThresholdImageFilter<SingleImageType,OutputImageType> ThresholdFilterType; + typedef typename ThresholdFilterType::Pointer ThresholdFilterPointerType; + // Multiply + typedef itk::MultiplyImageFilter<VectorImageType,OutputImageType,VectorImageType> MultiplyImageFilterType; + typedef typename MultiplyImageFilterType::Pointer MultiplyImageFilterPointerType; /** Get/Set indices */ - void SetRedIndex(int id){ m_UrbanAreaExtractionFilter->SetRedIndex( id ); }; /*GetFunctor().*/ + void SetRedIndex(int id){ m_UrbanAreaExtractionFilter->SetRedIndex( id ); }; void SetGreenIndex(int id){ m_UrbanAreaExtractionFilter->SetGreenIndex( id ); }; void SetNIRIndex(int id){ m_UrbanAreaExtractionFilter->SetNIRIndex( id ); }; unsigned int GetRedIndex(){ return m_UrbanAreaExtractionFilter->GetRedIndex(); }; @@ -248,9 +246,8 @@ public: /** Get/Set threshold values */ itkGetMacro(ThresholdValue, double); itkSetMacro(ThresholdValue, double); - itkSetMacro(ThresholdDensity, double); itkGetMacro(ThresholdDensity, double); - + itkSetMacro(ThresholdDensity, double); /** Methods */ virtual void GenerateData(); @@ -265,7 +262,7 @@ private: /** Filters */ IntensityFilterPointerType m_IntensityFilter; - EdgeDensityFilterType::Pointer m_EdgeDetectorFilter; + EdgeDensityFilterType::Pointer m_EdgeDensityFilter; SobelDetectorType::Pointer m_SobelFilter; ThresholdFilterPointerType m_Thresholder; UrbanAreaExtrationFilterPointerType m_UrbanAreaExtractionFilter; @@ -274,10 +271,11 @@ private: // DilateFilterType::Pointer m_DilateFilter; // ErodeFilterType::Pointer m_ErodeFilter2; // DilateFilterType::Pointer m_DilateFilter2; + MultiplyImageFilterPointerType m_MultiplyFilter; - /** MaxThreshold */ + /** Thresholds */ double m_ThresholdValue; double m_ThresholdDensity; diff --git a/Code/FeatureExtraction/otbUrbanAreaDetectionImageFilter.txx b/Code/FeatureExtraction/otbUrbanAreaDetectionImageFilter.txx index 44d621e15431412dba206e6bef1f82187f021568..eb4d93e9bef64aaed74667b6c3ef330d1e0d53ab 100644 --- a/Code/FeatureExtraction/otbUrbanAreaDetectionImageFilter.txx +++ b/Code/FeatureExtraction/otbUrbanAreaDetectionImageFilter.txx @@ -37,25 +37,27 @@ UrbanAreaDetectionImageFilter<TInputImage, TOutputImage, TFunction> // m_ErodeFilter2 = ErodeFilterType::New(); // m_DilateFilter2 = DilateFilterType::New(); m_IntensityFilter = IntensityFilterType::New(); - m_EdgeDetectorFilter = EdgeDensityFilterType::New(); + m_EdgeDensityFilter = EdgeDensityFilterType::New(); m_SobelFilter = SobelDetectorType::New(); m_Thresholder = ThresholdFilterType::New(); m_MaskImageFilter = MaskImageFilterType::New(); m_UrbanAreaExtractionFilter = UrbanAreaExtractionFilterType::New(); + m_MultiplyFilter = MultiplyImageFilterType::New(); + /** Init the Pipeline */ - // Intensity Image of the input image -// m_IntensityFilter->SetInput(this->GetInput()); // EdgeDensity - m_EdgeDetectorFilter->SetInput(m_IntensityFilter->GetOutput()); - m_EdgeDetectorFilter->SetDetector(m_SobelFilter); + m_EdgeDensityFilter->SetInput(m_IntensityFilter->GetOutput()); + m_EdgeDensityFilter->SetDetector(m_SobelFilter); // Threshold - m_Thresholder->SetInput(m_EdgeDetectorFilter->GetOutput()); + m_Thresholder->SetInput(m_EdgeDensityFilter->GetOutput()); // Mask Image -// m_MaskImageFilter->SetInput1(this->GetInput()); - m_MaskImageFilter->SetInput2(m_Thresholder->GetOutput()); + // m_MaskImageFilter->SetInput2(m_Thresholder->GetOutput()); + +m_MultiplyFilter->SetInput2(m_Thresholder->GetOutput()); // NonVegetationNonWaterIndex - m_UrbanAreaExtractionFilter->SetInput(m_MaskImageFilter->GetOutput()); + //m_UrbanAreaExtractionFilter->SetInput(m_MaskImageFilter->GetOutput()); +m_UrbanAreaExtractionFilter->SetInput(m_MultiplyFilter->GetOutput()); m_ThresholdValue = 0.5; m_ThresholdDensity = 0.1; @@ -70,17 +72,33 @@ UrbanAreaDetectionImageFilter<TInputImage, TOutputImage, TFunction> ::GenerateData() { + +typedef StreamingImageFileWriter<SingleImageType> WriterType; +typedef StreamingImageFileWriter<OutputImageType> WriterType2; +typedef StreamingImageFileWriter<VectorImageType> WriterType3; + + // Intensity m_IntensityFilter->SetInput(this->GetInput()); - m_MaskImageFilter->SetInput1(this->GetInput()); + +// WriterType::Pointer writer = WriterType::New(); +// writer->SetInput(m_IntensityFilter->GetOutput()); +// writer->SetFileName("Intensity.tif"); +// writer->Update(); // Edge Density m_SobelFilter->SetLowerThreshold(-100.0); - m_SobelFilter->SetUpperThreshold(100.0); + m_SobelFilter->SetUpperThreshold(200.0); SizeType lSize; lSize[0] = static_cast<unsigned int>(10); lSize[1] = static_cast<unsigned int>(10); - m_EdgeDetectorFilter->SetNeighborhoodRadius(lSize); + m_EdgeDensityFilter->SetNeighborhoodRadius(lSize); + +/* +WriterType::Pointer writer2 = WriterType::New(); +writer2->SetInput(m_EdgeDensityFilter->GetOutput()); +writer2->SetFileName("Edge.tif"); +writer2->Update();*/ // Threshold m_Thresholder->SetInsideValue(0); @@ -88,13 +106,36 @@ UrbanAreaDetectionImageFilter<TInputImage, TOutputImage, TFunction> m_Thresholder->SetLowerThreshold( 0. ); m_Thresholder->SetUpperThreshold( m_ThresholdDensity ); - // Appli the mask on the input image - m_MaskImageFilter->SetOutsideValue(0); + +// typename WriterType2::Pointer writer3 = WriterType2::New(); +// writer3->SetInput(m_Thresholder->GetOutput()); +// writer3->SetFileName("Thresh.tif"); +// writer3->Update(); + + // Apply the mask on the input image +m_MultiplyFilter->SetInput1(this->GetInput()); + //m_MaskImageFilter->SetInput1(this->GetInput()); + + //VectorImagePixelType lVectorZero; + //lVectorZero.Fill(0); + //m_MaskImageFilter->SetOutsideValue(lVectorZero); + +// BIBI THERE THERE TESTER MULTIPLI !!!!!!!!!! + +// typename WriterType3::Pointer writer4 = WriterType3::New(); +// writer4->SetInput(m_MultiplyFilter->GetOutput()); +// writer4->SetFileName("Mask.tif"); +// writer4->Update(); // Give a threshold to urbanAreaFilter m_UrbanAreaExtractionFilter->GetFunctor().SetLowerThreshold( m_ThresholdValue ); +// typename WriterType2::Pointer writer5 = WriterType2::New(); +// writer5->SetInput(m_UrbanAreaExtractionFilter->GetOutput()); +// writer5->SetFileName("Last.tif"); +// writer5->Update(); + // Erode/Dilate 2 times // StructuringElementType structuringElement; // structuringElement.SetRadius( 1 ); // 3x3 structuring element