diff --git a/Modules/Fusion/MajorityVoting/include/otbNeighborhoodMajorityVotingImageFilter.txx b/Modules/Fusion/MajorityVoting/include/otbNeighborhoodMajorityVotingImageFilter.txx index a9bc792d6f8a931420291f1b3eb713ca10ddd3a6..3d7e6f14c16e09ed3234ec4fe414aff0feb5b1ca 100644 --- a/Modules/Fusion/MajorityVoting/include/otbNeighborhoodMajorityVotingImageFilter.txx +++ b/Modules/Fusion/MajorityVoting/include/otbNeighborhoodMajorityVotingImageFilter.txx @@ -61,7 +61,7 @@ typename NeighborhoodMajorityVotingImageFilter<TInputImage, TOutputImage, //Get a histogram of label frequencies where the 2 highest are at the beginning and sorted unsigned int freqCenterLabel = this->FillNeighborhoodHistogram(histoNeighVec, nit, kernelBegin, kernelEnd); - if(m_OnlyIsolatedPixels && freqCenterLabel > m_IsolatedThreshold) + if(m_OnlyIsolatedPixels && freqCenterLabel < m_IsolatedThreshold) { //If we want to filter only isolated pixels, keep the label if //there are enough pixels with the center label to consider that diff --git a/Modules/Fusion/MajorityVoting/test/CMakeLists.txt b/Modules/Fusion/MajorityVoting/test/CMakeLists.txt index 0707461b77ab37723ce805cf8af1a77f3dc8e2fe..66ce3e10e24168e6ec5f7fc1c62f0d0308db5573 100644 --- a/Modules/Fusion/MajorityVoting/test/CMakeLists.txt +++ b/Modules/Fusion/MajorityVoting/test/CMakeLists.txt @@ -45,6 +45,10 @@ otb_add_test(NAME leTvNeighborhoodMajorityVotingIsolPixTest COMMAND otbMajorityV 1 #OnlyIsolatedPixels ) +otb_add_test(NAME leTvNeighborhoodMajorityVotingIsolThresPixTest COMMAND otbMajorityVotingTestDriver + otbNeighborhoodMajorityVotingImageFilterIsolatedTest + ) + otb_add_test(NAME leTvSVMImageClassificationFilterWithNeighborhoodMajorityVoting COMMAND otbMajorityVotingTestDriver --compare-image ${NOTOL} ${BASELINE}/leSVMImageClassificationWithNMVFilterOutput.tif diff --git a/Modules/Fusion/MajorityVoting/test/otbMajorityVotingTestDriver.cxx b/Modules/Fusion/MajorityVoting/test/otbMajorityVotingTestDriver.cxx index 3a961ec71e79efcfcd093dd8b4d72c45a08b3552..a3a3809011a04089e7ba5efff515975ae4fd416f 100644 --- a/Modules/Fusion/MajorityVoting/test/otbMajorityVotingTestDriver.cxx +++ b/Modules/Fusion/MajorityVoting/test/otbMajorityVotingTestDriver.cxx @@ -3,4 +3,5 @@ void RegisterTests() { REGISTER_TEST(otbNeighborhoodMajorityVotingImageFilterNew); REGISTER_TEST(otbNeighborhoodMajorityVotingImageFilterTest); + REGISTER_TEST(otbNeighborhoodMajorityVotingImageFilterIsolatedTest); } diff --git a/Modules/Fusion/MajorityVoting/test/otbNeighborhoodMajorityVotingImageFilterTest.cxx b/Modules/Fusion/MajorityVoting/test/otbNeighborhoodMajorityVotingImageFilterTest.cxx index 4726e8e0f4b6426ca51a9fcaa452110ea6a7e14e..0f97f0cae0e98368a77b25fca4f9547a039bb185 100644 --- a/Modules/Fusion/MajorityVoting/test/otbNeighborhoodMajorityVotingImageFilterTest.cxx +++ b/Modules/Fusion/MajorityVoting/test/otbNeighborhoodMajorityVotingImageFilterTest.cxx @@ -112,3 +112,104 @@ int otbNeighborhoodMajorityVotingImageFilterTest(int argc, char* argv[]) return EXIT_SUCCESS; } + +int otbNeighborhoodMajorityVotingImageFilterIsolatedTest(int argc, char* argv[]) +{ + typedef unsigned char PixelType; // 8 bits + const unsigned int Dimension = 2; + + typedef otb::Image<PixelType, Dimension> ImageType; + + ImageType::Pointer image = ImageType::New(); + ImageType::IndexType start; + + start[0] = 0; + start[1] = 0; + + ImageType::SizeType size; + size[0] = 100; + size[1] = 100; + + ImageType::RegionType region; + + region.SetSize(size); + region.SetIndex(start); + image->SetRegions(region); + image->Allocate(); + image->FillBuffer(itk::NumericTraits<PixelType>::Zero); + + // Neighborhood majority voting filter type + typedef otb::NeighborhoodMajorityVotingImageFilter<ImageType> NeighborhoodMajorityVotingFilterType; + + // Binary ball Structuring Element type + typedef NeighborhoodMajorityVotingFilterType::KernelType StructuringType; + typedef StructuringType::RadiusType RadiusType; + + + // Neighborhood majority voting filter + NeighborhoodMajorityVotingFilterType::Pointer NeighMajVotingFilter; + NeighMajVotingFilter = NeighborhoodMajorityVotingFilterType::New(); + + NeighMajVotingFilter->SetInput(image); + + StructuringType seBall; + RadiusType rad; + + + NeighMajVotingFilter->SetKeepOriginalLabelBool(true); + + rad[0] = 1; + rad[1] = 1; + + NeighMajVotingFilter->SetLabelForNoDataPixels(10); + + NeighMajVotingFilter->SetLabelForUndecidedPixels(7); + + seBall.SetRadius(rad); + seBall.CreateStructuringElement(); + NeighMajVotingFilter->SetKernel(seBall); + + NeighMajVotingFilter->SetOnlyIsolatedPixels(true); + + PixelType value = 255; + ImageType::IndexType coordinate; + coordinate[0] = 10; + coordinate[1] = 10; + + image->SetPixel(coordinate, value); + image->Update(); + NeighMajVotingFilter->SetIsolatedThreshold(1); + NeighMajVotingFilter->Update(); + + if(NeighMajVotingFilter->GetOutput()->GetPixel(coordinate) == value) + { + std::cout << "one pixel\n"; + return EXIT_FAILURE; + } + + coordinate[0] = 10; + coordinate[1] = 11; + image->SetPixel(coordinate, value); + image->Update(); + + NeighMajVotingFilter->SetIsolatedThreshold(1); + NeighMajVotingFilter->Update(); + + if(NeighMajVotingFilter->GetOutput()->GetPixel(coordinate) == value) + { + std::cout << "2 pixels thres = 1" << '\n'; + return EXIT_FAILURE; + } + + NeighMajVotingFilter->SetIsolatedThreshold(3); + NeighMajVotingFilter->Update(); + + if(NeighMajVotingFilter->GetOutput()->GetPixel(coordinate) != value) + { + std::cout << "2 pixels thres = 2" << '\n'; + return EXIT_FAILURE; + } + + + return EXIT_SUCCESS; +}