Skip to content
Snippets Groups Projects
Commit 85b278f8 authored by Julien Michel's avatar Julien Michel
Browse files

TEST: Adding test for ImageToNoDataMaskFilter. Test is standalone and does not...

TEST: Adding test for ImageToNoDataMaskFilter. Test is standalone and does not require ulages or baselines from OTB-Data
parent 1e121101
No related branches found
No related tags found
No related merge requests found
......@@ -71,6 +71,7 @@ otbFunctionWithNeighborhoodToImageFilterNew.cxx
otbEuclideanDistanceMetricWithMissingValue.cxx
otbEuclideanDistanceMetricWithMissingValueNew.cxx
otbChangeNoDataValueFilter.cxx
otbImageToNoDataMaskFilter.cxx
)
add_executable(otbImageManipulationTestDriver ${OTBImageManipulationTests})
......@@ -672,4 +673,7 @@ otb_add_test(NAME bfTuEuclideanDistanceMetricWithMissingValueNew COMMAND otbImag
otbEuclideanDistanceMetricWithMissingValueNew)
otb_add_test(NAME filteringImageManipulationChangeNoDataValueFilter COMMAND otbImageManipulationTestDriver
otbChangeNoDataValueFilter)
otbChangeNoDataValueFilter)
otb_add_test(NAME filteringImageManipulationImageToNoDataMaskFilter COMMAND otbImageManipulationTestDriver
otbImageToNoDataMaskFilter)
......@@ -77,4 +77,5 @@ void RegisterTests()
REGISTER_TEST(otbEuclideanDistanceMetricWithMissingValue);
REGISTER_TEST(otbEuclideanDistanceMetricWithMissingValueNew);
REGISTER_TEST(otbChangeNoDataValueFilter);
REGISTER_TEST(otbImageToNoDataMaskFilter);
}
/*=========================================================================
Program: ORFEO Toolbox
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
See OTBCopyright.txt for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
#include "otbImage.h"
#include "otbImageToNoDataMaskFilter.h"
#include "itkImageRegionIterator.h"
int otbImageToNoDataMaskFilter(int itkNotUsed(argc),char * itkNotUsed(argv) [])
{
// Build an image
typedef otb::Image<double> ImageType;
ImageType::Pointer img = ImageType::New();
ImageType::SizeType size;
size.Fill(20);
ImageType::RegionType region;
region.SetSize(size);
// Fill it with a default value
img->SetRegions(region);
img->Allocate();
img->FillBuffer(10);
// Write no-data flags to it
std::vector<bool> flags(1,true);
std::vector<double> values(1,-10.);
otb::WriteNoDataFlags(flags,values,img->GetMetaDataDictionary());
// Fill half of the pixels with no-data values
itk::ImageRegionIterator<ImageType> it(img,region);
unsigned int count = 0;
for(it.GoToBegin();!it.IsAtEnd();++it,++count)
{
if (count%2 == 0)
it.Set(-10.);
}
// Instanciate filter
typedef otb::ImageToNoDataMaskFilter<ImageType,ImageType> FilterType;
FilterType::Pointer filter = FilterType::New();
filter->SetInput(img);
filter->SetInsideValue(255);
filter->SetOutsideValue(0);
filter->Update();
// Check output
it = itk::ImageRegionIterator<ImageType>(filter->GetOutput(),region);
count = 0;
bool failed = false;
for(it.GoToBegin();!it.IsAtEnd();++it,++count)
{
if (count%2 == 0 and it.Get()!=0)
{
std::cerr<<"Pixel should be masked"<<std::endl;
failed = true;
}
else if(count%2 == 1 and it.Get()!=255)
{
std::cerr<<"Pixel should not be masked"<<std::endl;
failed = true;
}
}
if(failed)
return EXIT_FAILURE;
return EXIT_SUCCESS;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment