Commit cec26863 authored by Manuel Grizonnet's avatar Manuel Grizonnet
Browse files

ENH: Use a bitset of size 16 to read mask from NASA

IMPORTANT: it includes a patch in the way that the bitset is interpreted.

Previously the test was (val&mask!0) but the proper test to do is (val&mask==mask)

It includes also a change in the ComputeMask application to read the input image as unsigned short (will works with theia and nasa products)
parent ce5759af
......@@ -18,7 +18,7 @@ public:
typedef itk::SmartPointer<Self> Pointer;
typedef itk::SmartPointer<const Self> ConstPointer;
typedef otb::Image<unsigned char, 2> InputImageType;
typedef otb::Image<unsigned short, 2> InputImageType;
typedef otb::Image<unsigned char, 2> OutputImageType;
typedef itk::UnaryCloudMaskImageFilter<InputImageType,OutputImageType> CloudMaskFilterType;
......@@ -45,7 +45,7 @@ public:
AddParameter(ParameterType_InputImage, "in", "Input image");
SetParameterDescription( "in", "Input cloud image");
AddParameter(ParameterType_Float, "cloudmaskvalue", "Value of the cloud mask");
AddParameter(ParameterType_Int, "cloudmaskvalue", "Value of the cloud mask");
SetParameterDescription("cloudmaskvalue", "Value of the input cloud mask to extract in the output mask");
MandatoryOn("cloudmaskvalue");
......@@ -75,7 +75,7 @@ public:
m_CloudMaskFilter = CloudMaskFilterType::New();
m_CloudMaskFilter->SetInput(0, inputCloudMask);
m_CloudMaskFilter->SetCloudMask(GetParameterFloat("cloudmaskvalue"));
m_CloudMaskFilter->SetCloudMask(GetParameterInt("cloudmaskvalue"));
// Set the output image
SetParameterOutputImage("out", m_CloudMaskFilter->GetOutput());
......
......@@ -23,19 +23,15 @@ namespace itk
inline TOutput operator()(const TInput& B) const
{
std::bitset<8> bits(B);
std::bitset<8> mask_bits(m_cloud_mask_value);
std::bitset<8> result;
// Allocate a bitset of size 8 to handle theia cloud mask coded on 8 bits and landsat8 L2A from nasa coded on 16 bits
std::bitset<16> bits(B);
std::bitset<16> mask_bits(m_cloud_mask_value);
std::bitset<16> result;
result = bits & mask_bits;
if(result != 0)
if(result == mask_bits)
return static_cast<TOutput>(1);
else
return static_cast<TOutput>(0);
/* if(result.to_ulong()>0) */
/* return static_cast<TOutput>(1); */
/* else */
/* return static_cast<TOutput>(0); */
}
bool operator==(const CloudMask &) const
{
......
......@@ -213,3 +213,26 @@ add_test(NAME cloud_removal_step3_test
add_test(NAME cloud_removal_step4_test
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/cloud_removal_step4_test.py)
ADD_EXECUTABLE(itkUnaryCloudMaskImageFilterTest itkUnaryCloudMaskImageFilterTest.cxx)
TARGET_LINK_LIBRARIES(itkUnaryCloudMaskImageFilterTest histo_utils)
add_test(NAME TvitkUnaryCloudMaskImageFilterTest
COMMAND ${CMAKE_BINARY_DIR}/bin/itkUnaryCloudMaskImageFilterTest
192
192
1)
add_test(NAME TvitkUnaryCloudMaskImageFilterTest2
COMMAND ${CMAKE_BINARY_DIR}/bin/itkUnaryCloudMaskImageFilterTest
64
192
1
)
add_test(NAME TvitkUnaryCloudMaskImageFilterTest3
COMMAND ${CMAKE_BINARY_DIR}/bin/itkUnaryCloudMaskImageFilterTest
2
4
0
)
/*=========================================================================
Program: lis
Language: C++
Copyright (c) Simon Gascoin
Copyright (c) Manuel Grizonnet
See lis-copyright.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 "itkUnaryCloudMaskImageFilter.h"
int main(int argc, char * argv [])
{
typedef unsigned short InputType;
typedef unsigned char OutputType;
typedef itk::Functor::CloudMask<InputType, OutputType> FunctorType;
FunctorType functor;
const int inputCloudMaskValue = atoi(argv[1]);
const int inputValue = atoi(argv[2]);
functor.SetCloudMask(inputCloudMaskValue);
OutputType result = static_cast<int>(functor(inputValue));
if ( result != atoi(argv[3]))
{
return EXIT_FAILURE;
}
else
{
return EXIT_SUCCESS;
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment