diff --git a/Modules/Applications/AppImageUtils/app/otbManageNoData.cxx b/Modules/Applications/AppImageUtils/app/otbManageNoData.cxx index 2449029c861368d5d34121d875608b009e79a530..fa327c4a6dd3abce4299130b3755d20c92ac99b8 100644 --- a/Modules/Applications/AppImageUtils/app/otbManageNoData.cxx +++ b/Modules/Applications/AppImageUtils/app/otbManageNoData.cxx @@ -20,6 +20,10 @@ #include "otbImageToNoDataMaskFilter.h" #include "otbChangeNoDataValueFilter.h" +#include "itkMaskImageFilter.h" +#include "otbVectorImageToImageListFilter.h" +#include "otbImageListToVectorImageFilter.h" +#include "otbChangeInformationImageFilter.h" namespace otb { @@ -44,6 +48,12 @@ public: typedef otb::ImageToNoDataMaskFilter<FloatVectorImageType,UInt8ImageType> FilterType; typedef otb::ChangeNoDataValueFilter<FloatVectorImageType,FloatVectorImageType> ChangeNoDataFilterType; + typedef otb::ImageList<FloatImageType> ImageListType; + typedef otb::VectorImageToImageListFilter<FloatVectorImageType,ImageListType> VectorToListFilterType; + typedef otb::ImageListToVectorImageFilter<ImageListType,FloatVectorImageType> ListToVectorFilterType; + typedef itk::MaskImageFilter<FloatImageType,UInt8ImageType,FloatImageType> MaskFilterType; + typedef otb::ChangeInformationImageFilter<FloatVectorImageType> ChangeInfoFilterType; + private: void DoInit() { @@ -89,8 +99,14 @@ private: SetParameterDescription("mode.changevalue.newv","The new no-data value"); SetDefaultParameterInt("mode.changevalue.newv",0); + AddChoice("mode.apply","Apply a mask as no-data"); + + SetParameterDescription("mode.apply","Apply an external mask to an image using the no-data value of the input image"); + AddParameter(ParameterType_InputImage, "mode.apply.mask", "Mask image"); + SetParameterDescription("mode.apply.mask","Mask to be applied on input image (valid pixels have non null values)"); + SetParameterString("mode","buildmask"); - + AddRAMParameter(); // Doc example parameter settings @@ -132,10 +148,66 @@ private: { SetParameterOutputImage("out",m_ChangeNoDataFilter->GetOutput()); } + else if (GetParameterString("mode") == "apply") + { + m_MaskFilters.clear(); + UInt8ImageType::Pointer maskPtr = this->GetParameterImage<UInt8ImageType>("mode.apply.mask"); + unsigned int nbBands = inputPtr->GetNumberOfComponentsPerPixel(); + itk::MetaDataDictionary &dict = inputPtr->GetMetaDataDictionary(); + std::vector<bool> flags; + std::vector<double> values; + bool ret = otb::ReadNoDataFlags(dict,flags,values); + if (!ret) + { + flags.resize(nbBands,true); + values.resize(nbBands,0.0); + } + + m_V2L = VectorToListFilterType::New(); + m_V2L->SetInput(inputPtr); + ImageListType::Pointer inputList = m_V2L->GetOutput(); + inputList->UpdateOutputInformation(); + ImageListType::Pointer outputList = ImageListType::New(); + for (unsigned int i=0 ; i<nbBands ; ++i) + { + if (flags[i]) + { + MaskFilterType::Pointer masker = MaskFilterType::New(); + masker->SetInput(inputList->GetNthElement(i)); + masker->SetMaskImage(maskPtr); + masker->SetMaskingValue(0); + masker->SetOutsideValue(values[i]); + outputList->PushBack(masker->GetOutput()); + m_MaskFilters.push_back(masker); + } + else + { + outputList->PushBack(inputList->GetNthElement(i)); + } + } + m_L2V = ListToVectorFilterType::New(); + m_L2V->SetInput(outputList); + if (!ret) + { + m_MetaDataChanger = ChangeInfoFilterType::New(); + m_MetaDataChanger->SetInput(m_L2V->GetOutput()); + m_MetaDataChanger->SetOutputMetaData<std::vector<bool> >(otb::MetaDataKey::NoDataValueAvailable,&flags); + m_MetaDataChanger->SetOutputMetaData<std::vector<double> >(otb::MetaDataKey::NoDataValue,&values); + SetParameterOutputImage("out",m_MetaDataChanger->GetOutput()); + } + else + { + SetParameterOutputImage("out",m_L2V->GetOutput()); + } + } } FilterType::Pointer m_Filter; ChangeNoDataFilterType::Pointer m_ChangeNoDataFilter; + std::vector<MaskFilterType::Pointer> m_MaskFilters; + VectorToListFilterType::Pointer m_V2L; + ListToVectorFilterType::Pointer m_L2V; + ChangeInfoFilterType::Pointer m_MetaDataChanger; }; } diff --git a/Modules/Core/Transform/include/otbStreamingWarpImageFilter.h b/Modules/Core/Transform/include/otbStreamingWarpImageFilter.h index 4ebdfce5c43e1299bb7195712b8ad2df55b1e3c9..3b44ec0bedd6295fc0491fec6942d03ba10b9d87 100644 --- a/Modules/Core/Transform/include/otbStreamingWarpImageFilter.h +++ b/Modules/Core/Transform/include/otbStreamingWarpImageFilter.h @@ -93,6 +93,8 @@ protected: */ virtual void GenerateInputRequestedRegion(); + virtual void GenerateOutputInformation(); + /** * Re-implement the method ThreadedGenerateData to mask area outside the deformation grid */ diff --git a/Modules/Core/Transform/include/otbStreamingWarpImageFilter.txx b/Modules/Core/Transform/include/otbStreamingWarpImageFilter.txx index a3e9972a3b5117584e0b984f6c3d0cdf0ec9f693..19ba9ff358c2f35ac314090048b0605b6a08e66f 100644 --- a/Modules/Core/Transform/include/otbStreamingWarpImageFilter.txx +++ b/Modules/Core/Transform/include/otbStreamingWarpImageFilter.txx @@ -23,6 +23,9 @@ #include "otbStreamingWarpImageFilter.h" #include "itkImageRegionIteratorWithIndex.h" +#include "itkDefaultConvertPixelTraits.h" +#include "itkMetaDataObject.h" +#include "otbMetaDataKey.h" namespace otb { @@ -202,6 +205,40 @@ StreamingWarpImageFilter<TInputImage, TOutputImage, TDisplacementField> } +template<class TInputImage, class TOutputImage, class TDisplacementField> +void +StreamingWarpImageFilter<TInputImage, TOutputImage, TDisplacementField> +::GenerateOutputInformation() +{ + Superclass::GenerateOutputInformation(); + + // Set the NoData flag to the edge padding value + itk::MetaDataDictionary& dict = this->GetOutput()->GetMetaDataDictionary(); + std::vector<bool> noDataValueAvailable; + bool ret = itk::ExposeMetaData<std::vector<bool> >(dict,MetaDataKey::NoDataValueAvailable,noDataValueAvailable); + if (!ret) + { + noDataValueAvailable.resize(this->GetOutput()->GetNumberOfComponentsPerPixel(),false); + } + std::vector<double> noDataValue; + ret = itk::ExposeMetaData<std::vector<double> >(dict,MetaDataKey::NoDataValue,noDataValue); + if (!ret) + { + noDataValue.resize(this->GetOutput()->GetNumberOfComponentsPerPixel(),0.0); + } + PixelType edgePadding = this->GetEdgePaddingValue(); + for (unsigned int i=0; i<noDataValueAvailable.size() ; ++i) + { + if (!noDataValueAvailable[i]) + { + noDataValueAvailable[i] = true; + noDataValue[i] = itk::DefaultConvertPixelTraits<PixelType>::GetNthComponent(i,edgePadding); + } + } + itk::EncapsulateMetaData<std::vector<bool> >(dict,MetaDataKey::NoDataValueAvailable,noDataValueAvailable); + itk::EncapsulateMetaData<std::vector<double> >(dict,MetaDataKey::NoDataValue,noDataValue); +} + template<class TInputImage, class TOutputImage, class TDisplacementField> void StreamingWarpImageFilter<TInputImage, TOutputImage, TDisplacementField> diff --git a/Modules/Filtering/ImageManipulation/include/otbChangeInformationImageFilter.h b/Modules/Filtering/ImageManipulation/include/otbChangeInformationImageFilter.h new file mode 100644 index 0000000000000000000000000000000000000000..f92b2c20656c832253b695b6f5845a93465635b1 --- /dev/null +++ b/Modules/Filtering/ImageManipulation/include/otbChangeInformationImageFilter.h @@ -0,0 +1,94 @@ +/*========================================================================= + + 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. + +=========================================================================*/ +#ifndef __otbChangeInformationImageFilter_h +#define __otbChangeInformationImageFilter_h + +#include "itkChangeInformationImageFilter.h" +#include "otbMetaDataKey.h" + +namespace otb +{ + +/** + * \class ChangeInformationImageFilter + * \brief Filter to modify image metadata + * + * The base class is itk::ChangeInformationImageFilter that allows to + * modifiy origin, spacing, direction and buffered region. This deriving + * filter adds the support of MetaDataDictionary. + * + * \ingroup OTBImageManipulation + */ +template< typename TInputImage > +class ChangeInformationImageFilter: + public itk::ChangeInformationImageFilter< TInputImage > +{ +public: + /** Standard class typedefs. */ + typedef ChangeInformationImageFilter Self; + typedef itk::ChangeInformationImageFilter<TInputImage> Superclass; + typedef itk::SmartPointer<Self> Pointer; + typedef itk::SmartPointer<const Self> ConstPointer; + + /** Method for creation through the object factory. */ + itkNewMacro(Self); + + /** Creation through object factory macro */ + itkTypeMacro(ChangeInformationImageFilter, itk::ChangeInformationImageFilter); + + /** Set key names to change */ + void SetChangeMetaData(const char *keyname, bool flag); + + /** Ask if a metadata will be changed */ + bool GetChangeMetaData(const char *keyname); + + /** Set output values for metadata, passing a NULL value will remove the + * metadata from output. If not set for a key name in the change list, + * the metadata will also be set. + */ + template<typename T> + void SetOutputMetaData(const char *keyname, const T * value); + +protected: + ChangeInformationImageFilter() {} + virtual ~ChangeInformationImageFilter() {} + + /** Apply changes to the output image metadata. */ + virtual void GenerateOutputInformation(); + +private: + ChangeInformationImageFilter(const Self &); //purposely not implemented + void operator =(const Self&); //purposely not implemented + + /** Removes a field from a metadata dictionary + * After ITK 4.6, an Erase() method has been added to + * itk::MetaDataDictionary, so this function could be tagged as deprecated */ + bool RemoveKeyFromDictionary(itk::MetaDataDictionary & dict, const std::string & key); + + /** List of metadata keys to change */ + std::set<std::string> m_ChangedKeys; + +}; + +} // End of namespace OTB + +#ifndef OTB_MANUAL_INSTANTIATION +#include "otbChangeInformationImageFilter.txx" +#endif + +#endif diff --git a/Modules/Filtering/ImageManipulation/include/otbChangeInformationImageFilter.txx b/Modules/Filtering/ImageManipulation/include/otbChangeInformationImageFilter.txx new file mode 100644 index 0000000000000000000000000000000000000000..319684064c4caf4a83c8be8b7fd460cae13d920d --- /dev/null +++ b/Modules/Filtering/ImageManipulation/include/otbChangeInformationImageFilter.txx @@ -0,0 +1,150 @@ +/*========================================================================= + + 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. + +=========================================================================*/ +#ifndef __otbChangeInformationImageFilter_txx +#define __otbChangeInformationImageFilter_txx + +#include "otbChangeInformationImageFilter.h" +#include "itkMetaDataObject.h" + +namespace otb +{ + +template< typename TInputImage > +void +ChangeInformationImageFilter<TInputImage> +::SetChangeMetaData(const char *keyname, bool flag) +{ + std::string key(keyname); + if (! key.empty()) + { + if (flag) + { + m_ChangedKeys.insert(key); + } + else + { + std::set<std::string>::iterator pos = m_ChangedKeys.find(key); + if (pos != m_ChangedKeys.end()) + { + m_ChangedKeys.erase(pos); + } + } + } +} + +template< typename TInputImage > +bool +ChangeInformationImageFilter<TInputImage> +::GetChangeMetaData(const char *keyname) +{ + std::string key(keyname); + if (! key.empty()) + { + if (m_ChangedKeys.find(key) != m_ChangedKeys.end()) + { + return true; + } + } + return false; +} + +template< typename TInputImage > +template<typename T> +void +ChangeInformationImageFilter<TInputImage> +::SetOutputMetaData(const char *keyname, const T * value) +{ + std::string key(keyname); + if (! key.empty()) + { + // enable this key for metadata change + m_ChangedKeys.insert(key); + itk::MetaDataDictionary &dict = this->GetMetaDataDictionary(); + if (value == NULL) + { + // Remove meta-data from dictionary + this->RemoveKeyFromDictionary(dict,key); + } + else + { + // Set metadata in dictionary + const T &valueRef = (*value); + itk::EncapsulateMetaData<T>(dict,key,valueRef); + } + } +} + +template< typename TInputImage > +void +ChangeInformationImageFilter<TInputImage> +::GenerateOutputInformation() +{ + Superclass::GenerateOutputInformation(); + + // Process the metadatas to be changed + itk::MetaDataDictionary &dict = this->GetMetaDataDictionary(); + itk::MetaDataDictionary &outputDict = this->GetOutput()->GetMetaDataDictionary(); + std::set<std::string>::iterator it = m_ChangedKeys.begin(); + for ( ; it != m_ChangedKeys.end() ; ++it) + { + if (dict.HasKey(*it)) + { + // Replace metadata in output dictionary + outputDict[*it] = dict[*it]; + } + else + { + // Remove metadata from output dictionary + this->RemoveKeyFromDictionary(outputDict,*it); + } + } +} + +template< typename TInputImage > +bool +ChangeInformationImageFilter<TInputImage> +::RemoveKeyFromDictionary(itk::MetaDataDictionary & dict, const std::string & key) +{ + std::vector<std::string> keyList = dict.GetKeys(); + std::vector<std::string>::iterator pos = keyList.begin(); + while (pos != keyList.end()) + { + if (key.compare(*pos) == 0) + { + break; + } + ++pos; + } + if (pos != keyList.end()) + { + itk::MetaDataDictionary copyDict; + keyList.erase(pos); + pos = keyList.begin(); + for ( ; pos != keyList.end();++pos) + { + copyDict.Set(*pos, const_cast<itk::MetaDataObjectBase*>(dict.Get(*pos))); + } + dict = copyDict; + return true; + } + return false; +} + +} // End of namespace OTB + +#endif diff --git a/Modules/Filtering/ImageManipulation/test/CMakeLists.txt b/Modules/Filtering/ImageManipulation/test/CMakeLists.txt index 86e9cd72c67dca156fc4fd293c9b220ff186fc21..3019412f1434a6242298ef6d9fc9eff55aa520d2 100644 --- a/Modules/Filtering/ImageManipulation/test/CMakeLists.txt +++ b/Modules/Filtering/ImageManipulation/test/CMakeLists.txt @@ -75,6 +75,7 @@ otbOneRIBandImageToOneComplexBandImage.cxx otbTwoNRIBandsImageToNComplexBandsImage.cxx otbChangeNoDataValueFilter.cxx otbImageToNoDataMaskFilter.cxx +otbChangeInformationImageFilter.cxx ) add_executable(otbImageManipulationTestDriver ${OTBImageManipulationTests}) @@ -710,3 +711,8 @@ otb_add_test(NAME filteringImageManipulationChangeNoDataValueFilter COMMAND otbI otb_add_test(NAME filteringImageManipulationImageToNoDataMaskFilter COMMAND otbImageManipulationTestDriver otbImageToNoDataMaskFilter) + +otb_add_test(NAME bfTvChangeInformationImageFilter COMMAND otbImageManipulationTestDriver + otbChangeInformationImageFilter + ${INPUTDATA}/WV2_PAN_ROI_1000_100.tif + ) diff --git a/Modules/Filtering/ImageManipulation/test/otbChangeInformationImageFilter.cxx b/Modules/Filtering/ImageManipulation/test/otbChangeInformationImageFilter.cxx new file mode 100644 index 0000000000000000000000000000000000000000..2a6a7e2a904cee67cfa8d15e7bf7d3be65126ece --- /dev/null +++ b/Modules/Filtering/ImageManipulation/test/otbChangeInformationImageFilter.cxx @@ -0,0 +1,66 @@ +/*========================================================================= + + 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 "otbChangeInformationImageFilter.h" +#include "otbImageFileReader.h" +#include "otbImage.h" + +int otbChangeInformationImageFilter(int itkNotUsed(argc), char * argv[]) +{ + const char *inputFilename(argv[1]); + + typedef otb::Image<float,2> ImageType; + typedef otb::ChangeInformationImageFilter<ImageType> FilterType; + typedef otb::ImageFileReader<ImageType> ReaderType; + + ReaderType::Pointer reader = ReaderType::New(); + reader->SetFileName(inputFilename); + + FilterType::Pointer filter = FilterType::New(); + filter->SetInput(reader->GetOutput()); + // try to set a different ProjRef + std::string newProj("Fake ProjRef"); + filter->SetOutputMetaData<std::string>(otb::MetaDataKey::ProjectionRefKey,&newProj); + // erase that choice + filter->SetOutputMetaData<std::string>(otb::MetaDataKey::ProjectionRefKey,NULL); + // add a no data to the image + std::vector<bool> flags; + flags.push_back(true); + std::vector<double> nodata; + nodata.push_back(0.0); + filter->SetOutputMetaData<std::vector<bool> >(otb::MetaDataKey::NoDataValueAvailable,&flags); + filter->SetOutputMetaData<std::vector<double> >(otb::MetaDataKey::NoDataValue,&nodata); + filter->UpdateOutputInformation(); + + ImageType::Pointer outImage = filter->GetOutput(); + if (! outImage->GetProjectionRef().empty()) + { + std::cout << "Projection is supposed to be removed but is still present !" << std::endl; + return EXIT_FAILURE; + } + + itk::MetaDataDictionary &dict = outImage->GetMetaDataDictionary(); + if (!dict.HasKey(otb::MetaDataKey::NoDataValueAvailable) || + !dict.HasKey(otb::MetaDataKey::NoDataValue)) + { + std::cout << "Missing no data metadata !" << std::endl; + return EXIT_FAILURE; + } + + return EXIT_SUCCESS; +} + diff --git a/Modules/Filtering/ImageManipulation/test/otbImageManipulationTestDriver.cxx b/Modules/Filtering/ImageManipulation/test/otbImageManipulationTestDriver.cxx index f732d0d2a493a927ccfd34f1f5633d85b3508cf3..299f6744511b2d781a1f5a0d973b4c122c44674b 100644 --- a/Modules/Filtering/ImageManipulation/test/otbImageManipulationTestDriver.cxx +++ b/Modules/Filtering/ImageManipulation/test/otbImageManipulationTestDriver.cxx @@ -81,4 +81,5 @@ void RegisterTests() REGISTER_TEST(otbTwoNRIBandsImageToNComplexBandsImage); REGISTER_TEST(otbChangeNoDataValueFilter); REGISTER_TEST(otbImageToNoDataMaskFilter); + REGISTER_TEST(otbChangeInformationImageFilter); } diff --git a/Modules/Fusion/MajorityVoting/include/otbNeighborhoodMajorityVotingImageFilter.h b/Modules/Fusion/MajorityVoting/include/otbNeighborhoodMajorityVotingImageFilter.h index 39d04f689ad6bb90b695073cb6a4a32c9b8e6685..ce25b90ecedb1db3c54530bac7ffd8b0d9f3bfe7 100644 --- a/Modules/Fusion/MajorityVoting/include/otbNeighborhoodMajorityVotingImageFilter.h +++ b/Modules/Fusion/MajorityVoting/include/otbNeighborhoodMajorityVotingImageFilter.h @@ -164,6 +164,7 @@ protected: const KernelIteratorType kernelBegin, const KernelIteratorType kernelEnd); + virtual void GenerateOutputInformation(); private: NeighborhoodMajorityVotingImageFilter(const Self&); //purposely not implemented diff --git a/Modules/Fusion/MajorityVoting/include/otbNeighborhoodMajorityVotingImageFilter.txx b/Modules/Fusion/MajorityVoting/include/otbNeighborhoodMajorityVotingImageFilter.txx index 2889cf1d861de2ec69193924e94da97db67d565c..93c05d6b2034c637528cfaecec84e7e69a9fc89b 100644 --- a/Modules/Fusion/MajorityVoting/include/otbNeighborhoodMajorityVotingImageFilter.txx +++ b/Modules/Fusion/MajorityVoting/include/otbNeighborhoodMajorityVotingImageFilter.txx @@ -23,6 +23,9 @@ // gets integrated into the main directories. #include "otbNeighborhoodMajorityVotingImageFilter.h" +#include "itkDefaultConvertPixelTraits.h" +#include "itkMetaDataObject.h" +#include "otbMetaDataKey.h" namespace otb { @@ -118,6 +121,30 @@ const KernelIteratorType kernelEnd) return majorityLabel; } +template<class TInputImage, class TOutputImage, class TKernel> +void +NeighborhoodMajorityVotingImageFilter<TInputImage, TOutputImage, TKernel> +::GenerateOutputInformation() +{ + Superclass::GenerateOutputInformation(); + + TOutputImage* outputPtr = this->GetOutput(); + + // Set the NoData value using the background + const unsigned int & nbBands = outputPtr->GetNumberOfComponentsPerPixel(); + std::vector<bool> noDataValueAvailable; + noDataValueAvailable.resize(nbBands,true); + std::vector<double> noDataValue; + noDataValue.resize(nbBands,0.0); + for (unsigned int i=0 ; i<nbBands ; ++i) + { + noDataValue[i] = itk::DefaultConvertPixelTraits<PixelType>::GetNthComponent(i,m_LabelForNoDataPixels); + } + itk::MetaDataDictionary& dict = outputPtr->GetMetaDataDictionary(); + itk::EncapsulateMetaData<std::vector<bool> >(dict,MetaDataKey::NoDataValueAvailable,noDataValueAvailable); + itk::EncapsulateMetaData<std::vector<double> >(dict,MetaDataKey::NoDataValue,noDataValue); +} + } // end namespace otb #endif diff --git a/Modules/Fusion/MajorityVoting/otb-module.cmake b/Modules/Fusion/MajorityVoting/otb-module.cmake index bc585bf62a7088aa2ca551d384bcc6f9d011b36b..8643c503476f640fd87ad82754cfb97720c56a8b 100644 --- a/Modules/Fusion/MajorityVoting/otb-module.cmake +++ b/Modules/Fusion/MajorityVoting/otb-module.cmake @@ -5,6 +5,7 @@ this label value (see also DempsterShafer module).") otb_module(OTBMajorityVoting DEPENDS OTBITK + OTBOSSIMAdapters TEST_DEPENDS OTBTestKernel diff --git a/Modules/Learning/DempsterShafer/include/otbDSFusionOfClassifiersImageFilter.h b/Modules/Learning/DempsterShafer/include/otbDSFusionOfClassifiersImageFilter.h index 2c3810858082feca40b6b6296f7df821aa1fa964..84b093f8c167c6985890be5a9e9c888b4dd2c8d6 100644 --- a/Modules/Learning/DempsterShafer/include/otbDSFusionOfClassifiersImageFilter.h +++ b/Modules/Learning/DempsterShafer/include/otbDSFusionOfClassifiersImageFilter.h @@ -139,6 +139,8 @@ protected: /** Destructor */ virtual ~DSFusionOfClassifiersImageFilter() {} + /** Generate output information */ + virtual void GenerateOutputInformation(); /** Threaded generate data */ virtual void ThreadedGenerateData(const OutputImageRegionType& outputRegionForThread, itk::ThreadIdType threadId); /** Before threaded generate data */ diff --git a/Modules/Learning/DempsterShafer/include/otbDSFusionOfClassifiersImageFilter.txx b/Modules/Learning/DempsterShafer/include/otbDSFusionOfClassifiersImageFilter.txx index 65c577151dec44cbe7000adf8facf2b398c1891c..5305fa3d368444bf63e6e70cfbc630c11d51436d 100644 --- a/Modules/Learning/DempsterShafer/include/otbDSFusionOfClassifiersImageFilter.txx +++ b/Modules/Learning/DempsterShafer/include/otbDSFusionOfClassifiersImageFilter.txx @@ -22,6 +22,9 @@ #include "itkImageRegionIterator.h" #include "itkProgressReporter.h" +#include "itkMetaDataObject.h" +#include "otbMetaDataKey.h" + namespace otb { /** @@ -84,6 +87,23 @@ DSFusionOfClassifiersImageFilter<TInputImage, TOutputImage, TMaskImage> } /* ************************************************************************************************************** */ +template <class TInputImage, class TOutputImage, class TMaskImage> +void +DSFusionOfClassifiersImageFilter<TInputImage, TOutputImage, TMaskImage> +::GenerateOutputInformation() +{ + Superclass::GenerateOutputInformation(); + + // Set the NoData value + std::vector<bool> noDataValueAvailable; + noDataValueAvailable.push_back(true); + std::vector<double> noDataValue; + noDataValue.push_back(m_LabelForNoDataPixels); + itk::MetaDataDictionary& dict = this->GetOutput()->GetMetaDataDictionary(); + itk::EncapsulateMetaData<std::vector<bool> >(dict,MetaDataKey::NoDataValueAvailable,noDataValueAvailable); + itk::EncapsulateMetaData<std::vector<double> >(dict,MetaDataKey::NoDataValue,noDataValue); +} +/* ************************************************************************************************************** */ template <class TInputImage, class TOutputImage, class TMaskImage> void diff --git a/Modules/Registration/DisparityMap/include/otbDisparityTranslateFilter.txx b/Modules/Registration/DisparityMap/include/otbDisparityTranslateFilter.txx index 2a0932c883e1c023d439b12bc7cb2b641943ae19..afd59f1caf21033f43f0f4cc8f4449f69a63b389 100644 --- a/Modules/Registration/DisparityMap/include/otbDisparityTranslateFilter.txx +++ b/Modules/Registration/DisparityMap/include/otbDisparityTranslateFilter.txx @@ -205,6 +205,18 @@ DisparityTranslateFilter<TDisparityImage,TGridImage,TSensorImage,TMaskImage> horizOut->CopyInformation(leftIn); vertiOut->CopyInformation(leftIn); + + // Set the NoData value + std::vector<bool> noDataValueAvailable; + noDataValueAvailable.push_back(true); + std::vector<double> noDataValue; + noDataValue.push_back(m_NoDataValue); + itk::MetaDataDictionary& dict = horizOut->GetMetaDataDictionary(); + itk::EncapsulateMetaData<std::vector<bool> >(dict,MetaDataKey::NoDataValueAvailable,noDataValueAvailable); + itk::EncapsulateMetaData<std::vector<double> >(dict,MetaDataKey::NoDataValue,noDataValue); + dict = vertiOut->GetMetaDataDictionary(); + itk::EncapsulateMetaData<std::vector<bool> >(dict,MetaDataKey::NoDataValueAvailable,noDataValueAvailable); + itk::EncapsulateMetaData<std::vector<double> >(dict,MetaDataKey::NoDataValue,noDataValue); } template <class TDisparityImage, class TGridImage, class TSensorImage, class TMaskImage> diff --git a/Modules/Registration/Stereo/include/otbMulti3DMapToDEMFilter.txx b/Modules/Registration/Stereo/include/otbMulti3DMapToDEMFilter.txx index 2c7a851f0446e45ca7ad3dbe0b47e8357d4a6af7..515161f4bb580acd054c6996fc7da7b9e1c24fdf 100644 --- a/Modules/Registration/Stereo/include/otbMulti3DMapToDEMFilter.txx +++ b/Modules/Registration/Stereo/include/otbMulti3DMapToDEMFilter.txx @@ -337,7 +337,14 @@ void Multi3DMapToDEMFilter<T3DImage, TMaskImage, TOutputDEMImage>::GenerateOutpu m_IsGeographic = oSRS.IsGeographic(); // TODO check if this test is valid for all projection systems } - + // Set the NoData value + std::vector<bool> noDataValueAvailable; + noDataValueAvailable.push_back(true); + std::vector<double> noDataValue; + noDataValue.push_back(m_NoDataValue); + itk::MetaDataDictionary& dict = outputPtr->GetMetaDataDictionary(); + itk::EncapsulateMetaData<std::vector<bool> >(dict,MetaDataKey::NoDataValueAvailable,noDataValueAvailable); + itk::EncapsulateMetaData<std::vector<double> >(dict,MetaDataKey::NoDataValue,noDataValue); } template<class T3DImage, class TMaskImage, class TOutputDEMImage> diff --git a/Modules/Segmentation/Conversion/include/otbOGRDataSourceToLabelImageFilter.txx b/Modules/Segmentation/Conversion/include/otbOGRDataSourceToLabelImageFilter.txx index 997c4cb1382dc0c4b9b4f19545a7530f2407d79d..69b8e325f45c80d0dc20259fe885037e2f396c1c 100644 --- a/Modules/Segmentation/Conversion/include/otbOGRDataSourceToLabelImageFilter.txx +++ b/Modules/Segmentation/Conversion/include/otbOGRDataSourceToLabelImageFilter.txx @@ -20,6 +20,8 @@ #include "otbOGRIOHelper.h" #include "otbGdalDataTypeBridge.h" #include "otbImageMetadataInterfaceFactory.h" +#include "itkMetaDataObject.h" +#include "otbMetaDataKey.h" #include "gdal_alg.h" #include "stdint.h" //needed for uintptr_t @@ -164,6 +166,15 @@ OGRDataSourceToLabelImageFilter<TOutputImage> m_SrcDataSetLayers.push_back( &(ogrDS->GetLayer(layer).ogr()) ); } } + + // Set the NoData value using the background + const unsigned int & nbBands = outputPtr->GetNumberOfComponentsPerPixel(); + std::vector<bool> noDataValueAvailable; + noDataValueAvailable.resize(nbBands,true); + std::vector<double> noDataValue; + noDataValue.resize(nbBands,static_cast<double>(m_BackgroundValue)); + itk::EncapsulateMetaData<std::vector<bool> >(dict,MetaDataKey::NoDataValueAvailable,noDataValueAvailable); + itk::EncapsulateMetaData<std::vector<double> >(dict,MetaDataKey::NoDataValue,noDataValue); } template< class TOutputImage>