diff --git a/Code/FeatureExtraction/otbUrbanAreaDetectionImageFilter.h b/Code/FeatureExtraction/otbUrbanAreaDetectionImageFilter.h index 7264f2424b2453f3f2f1134764f9fbe2b019877a..38bb86fc39e6b38ee5e694766930896b3c23641d 100644 --- a/Code/FeatureExtraction/otbUrbanAreaDetectionImageFilter.h +++ b/Code/FeatureExtraction/otbUrbanAreaDetectionImageFilter.h @@ -75,47 +75,18 @@ class RadiometricNonWaterNonVegetationIndexFunctor inline TOutput operator()(const TInput& pInPix) { TOutput lVIval,lWIval,lOutPix; -/* - lVIval = static_cast<ValueType>(m_VegetationFunctor(pInPix)); - lWIval = static_cast<ValueType>(m_WaterFunctor(pInPix)); + TInput zero = pInPix; + zero.Fill(0); + if(pInPix!=zero) + { + lVIval = static_cast<ValueType>(std::max(0.,m_VegetationFunctor(pInPix))); + lWIval = static_cast<ValueType>(std::max(0.,m_WaterFunctor(pInPix))); -*/ -TInput zero = pInPix; -zero.Fill(0); -if(pInPix!=zero) -{ - lVIval = static_cast<ValueType>(std::max(0.,m_VegetationFunctor(pInPix))); - - lWIval = static_cast<ValueType>(std::max(0.,m_WaterFunctor(pInPix))); - - lOutPix = vcl_sqrt(vcl_abs((1-lVIval)*(1-lWIval))); //sqrt -} -else - lOutPix = 0; - -//std::cout<< " lOutPix "<<lOutPix<<std::endl; - -// OU - //lOutPix = vcl_sqrt((1-lVIval)*(1-lVIval)+(1-lWIval)*(1-lWIval)); // eucl : bof bof -// OU - //lOutPix = 1-vcl_sqrt((lVIval)*(lVIval)+(lWIval)*(lWIval)); // eucl2 : pas mal, un peu effet de flou par rappart a sqrt - - - //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 -// if( lVIval || lWIval ) -// { -// lOutPix = 1 - std::max(lVIval,lWIval); //MAX : PAS MAL DU TOUT -// } - -/* Tester avec le log - if(lVIval*lWIval) - lOutPix = 1 - 1 / ( lVIval*lWIval + 1 ); //Jordy's formula - else + lOutPix = vcl_sqrt(vcl_abs((1-lVIval)*(1-lWIval))); + } + else lOutPix = 0; -*/ return lOutPix; } @@ -218,9 +189,7 @@ public: /** Filters typedefs */ // NonVegetationNonWaterIndexFilter 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< OutputImagePixelType, 2 > StructuringElementType; @@ -276,10 +245,6 @@ private: ThresholdFilterPointerType m_Thresholder; UrbanAreaExtrationFilterPointerType m_UrbanAreaExtractionFilter; MaskImageFilterPointerType m_MaskImageFilter; -// ErodeFilterType::Pointer m_ErodeFilter; -// DilateFilterType::Pointer m_DilateFilter; -// ErodeFilterType::Pointer m_ErodeFilter2; -// DilateFilterType::Pointer m_DilateFilter2; MultiplyImageFilterPointerType m_MultiplyFilter; diff --git a/Code/FeatureExtraction/otbUrbanAreaDetectionImageFilter.txx b/Code/FeatureExtraction/otbUrbanAreaDetectionImageFilter.txx index 560aebffbabdca831a10ff7b93d11a28299da2c4..eb0112d5752221c8e16bcf3d248fb8b7f1e32226 100644 --- a/Code/FeatureExtraction/otbUrbanAreaDetectionImageFilter.txx +++ b/Code/FeatureExtraction/otbUrbanAreaDetectionImageFilter.txx @@ -19,7 +19,7 @@ PURPOSE. See the above copyright notices for more information. #define __otbUrbanAreaDetectionFilter_txx #include "otbUrbanAreaDetectionImageFilter.h" - +#include "itkProgressAccumulator.h" namespace otb { @@ -32,10 +32,6 @@ UrbanAreaDetectionImageFilter<TInputImage, TOutputImage, TFunction> ::UrbanAreaDetectionImageFilter() { -// m_ErodeFilter = ErodeFilterType::New(); -// m_DilateFilter = DilateFilterType::New(); -// m_ErodeFilter2 = ErodeFilterType::New(); -// m_DilateFilter2 = DilateFilterType::New(); m_IntensityFilter = IntensityFilterType::New(); m_EdgeDensityFilter = EdgeDensityFilterType::New(); m_SobelFilter = SobelDetectorType::New(); @@ -52,12 +48,11 @@ UrbanAreaDetectionImageFilter<TInputImage, TOutputImage, TFunction> // Threshold m_Thresholder->SetInput(m_EdgeDensityFilter->GetOutput()); // Mask Image - // m_MaskImageFilter->SetInput2(m_Thresholder->GetOutput()); - -m_MultiplyFilter->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_MultiplyFilter->GetOutput()); + m_UrbanAreaExtractionFilter->SetInput(m_MultiplyFilter->GetOutput()); m_ThresholdValue = 0.5; m_ThresholdDensity = 0.1; @@ -72,20 +67,9 @@ UrbanAreaDetectionImageFilter<TInputImage, TOutputImage, TFunction> ::GenerateData() { - -typedef StreamingImageFileWriter<SingleImageType> WriterType; -typedef StreamingImageFileWriter<OutputImageType> WriterType2; -typedef StreamingImageFileWriter<VectorImageType> WriterType3; - // Intensity m_IntensityFilter->SetInput(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(200.0); @@ -94,70 +78,26 @@ typedef StreamingImageFileWriter<VectorImageType> WriterType3; lSize[1] = static_cast<unsigned int>(10); 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); m_Thresholder->SetOutsideValue(1); - m_Thresholder->SetLowerThreshold( 0. ); + m_Thresholder->SetLowerThreshold( -10. ); m_Thresholder->SetUpperThreshold( m_ThresholdDensity ); - -// 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_MultiplyFilter->SetInput1(this->GetInput()); //m_MaskImageFilter->SetInput1(this->GetInput()); - //VectorImagePixelType lVectorZero; //lVectorZero.Fill(0); //m_MaskImageFilter->SetOutsideValue(lVectorZero); -/* -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 -// structuringElement.CreateStructuringElement(); -// -// m_DilateFilter->SetInput(m_UrbanAreaExtractionFilter->GetOutput()); -// m_DilateFilter->SetDilateValue(1); -// m_DilateFilter->SetKernel( structuringElement ); -// -// m_ErodeFilter->SetInput(m_DilateFilter->GetOutput()); -// m_ErodeFilter->SetErodeValue(1); -// m_ErodeFilter->SetKernel( structuringElement ); -// m_ErodeFilter->Update(); -// -// m_ErodeFilter2->SetInput(m_ErodeFilter->GetOutput()); -// m_ErodeFilter2->SetErodeValue(1); -// m_ErodeFilter2->SetKernel( structuringElement ); -// -// m_DilateFilter2->SetInput(m_ErodeFilter2->GetOutput()); -// m_DilateFilter2->SetDilateValue(1); -// m_DilateFilter2->SetKernel( structuringElement ); -// m_DilateFilter2->Update(); - + // Progress accumulator + itk::ProgressAccumulator::Pointer progress = itk::ProgressAccumulator::New(); + progress->SetMiniPipelineFilter(this); + progress->RegisterInternalFilter(m_UrbanAreaExtractionFilter, 0.5f); /** GraftOutput */ m_UrbanAreaExtractionFilter->GraftOutput(this->GetOutput()); diff --git a/Code/Radiometry/otbMultiChannelRAndGAndNIRIndexImageFilter.h b/Code/Radiometry/otbMultiChannelRAndGAndNIRIndexImageFilter.h index cf188aa0cf4785ed4cf1b46ecdec2a888c10e6fe..ff38dfbed33be4c804e0287427b36ff629091bcb 100644 --- a/Code/Radiometry/otbMultiChannelRAndGAndNIRIndexImageFilter.h +++ b/Code/Radiometry/otbMultiChannelRAndGAndNIRIndexImageFilter.h @@ -77,6 +77,8 @@ protected: /// Before generating data, set functor parameters virtual void BeforeThreadedGenerateData() { + +std::cout<<" MultichanR&G&NIR beforeThreaded" << m_RedIndex << std::endl; unsigned int lNbChan = this->GetInput()->GetNumberOfComponentsPerPixel(); if(m_RedIndex < 1 || m_GreenIndex < 1 || m_NIRIndex < 1 || m_RedIndex > lNbChan || m_GreenIndex > lNbChan || m_NIRIndex > lNbChan) diff --git a/Testing/Code/FeatureExtraction/CMakeLists.txt b/Testing/Code/FeatureExtraction/CMakeLists.txt index 08736ca6e315b8052ef9f4a96ad3ba380242a603..b0621656f32e768ddb9a1d2d6314fec5004037d6 100644 --- a/Testing/Code/FeatureExtraction/CMakeLists.txt +++ b/Testing/Code/FeatureExtraction/CMakeLists.txt @@ -1709,8 +1709,8 @@ ADD_TEST(raTuUrbanAreaDetectionImageFilterNew ${FEATUREEXTRACTION_TESTS14} ) ADD_TEST(raTvUrbanAreaDetectionImageFilter ${FEATUREEXTRACTION_TESTS14} -# --compare-image ${EPSILON_8} ${BASELINE}/raWaterIndex_NDWI_verySmallFSATSW.tif -# ${TEMP}/raWaterIndex_NDWI_verySmallFSATSW.tif + --compare-image ${EPSILON} ${BASELINE}/raTvUrbanAreaDetection.png + ${TEMP}/raTvUrbanAreaDetection.png otbUrbanAreaDetectionImageFilter ${INPUTDATA}/qb_RoadExtract2sub200x200.tif ${TEMP}/raTvUrbanAreaDetection.png