diff --git a/Data/Baseline/OTB/Files/bfBoundingRegionCalculatorOutput.txt b/Data/Baseline/OTB/Files/bfBoundingRegionCalculatorOutput.txt deleted file mode 100644 index 607b28d732cbd88ed00155282488e63c212b0ace..0000000000000000000000000000000000000000 --- a/Data/Baseline/OTB/Files/bfBoundingRegionCalculatorOutput.txt +++ /dev/null @@ -1,12 +0,0 @@ -Test results from otbBinaryImageBoundingRegionCalculator test. -[8, 48] [81, 39] -[7, 7] [83, 41] -[7, 9] [45, 36] -[25, 11] [47, 30] - -Testing the pad option - -[7, 47] [83, 41] -[6, 6] [85, 43] -[6, 8] [47, 38] -[24, 10] [49, 32] diff --git a/Modules/Filtering/ImageManipulation/include/otbBinaryImageMinimalBoundingRegionCalculator.h b/Modules/Filtering/ImageManipulation/include/otbBinaryImageMinimalBoundingRegionCalculator.h deleted file mode 100644 index 6d8d3fb4e696f8ff9d426f83133276001766e4b6..0000000000000000000000000000000000000000 --- a/Modules/Filtering/ImageManipulation/include/otbBinaryImageMinimalBoundingRegionCalculator.h +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Copyright (C) 2005-2019 Centre National d'Etudes Spatiales (CNES) - * - * This file is part of Orfeo Toolbox - * - * https://www.orfeo-toolbox.org/ - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef otbBinaryImageMinimalBoundingRegionCalculator_h -#define otbBinaryImageMinimalBoundingRegionCalculator_h - -#include "itkImageToImageFilter.h" -#include "itkObjectFactory.h" - -namespace otb -{ -/** - * \class BinaryImageMinimalBoundingRegionCalculator - * \brief This class compute the smallest region of the image - * containing every pixel with the foreground value. - * - * This class is used for instance in the RCC8 calculator filter, - * where the input region used for computation has to be the smallest possible - * for costs reasons. The Pad arg allows the user to get a region of pad pixel larger - * at each bound in case a security margin has to be kept. - * - * \sa ImageToImageRCC8Calculator - * - * \ingroup OTBImageManipulation - */ -template <class TInputImage> -class ITK_EXPORT BinaryImageMinimalBoundingRegionCalculator - : public itk::ImageToImageFilter<TInputImage, TInputImage> -{ -public: - /** Standard typedefs */ - typedef BinaryImageMinimalBoundingRegionCalculator Self; - typedef itk::ImageToImageFilter<TInputImage, TInputImage> Superclass; - typedef itk::SmartPointer<Self> Pointer; - typedef itk::SmartPointer<const Self> ConstPointer; - /** Creation through object factory macro */ - itkNewMacro(Self); - /** Type macro */ - itkTypeMacro(BinaryImageMinimalBoundingRegionCalculator, ImageToImageFilter); - - typedef TInputImage InputImageType; - typedef typename InputImageType::PixelType PixelType; - typedef typename InputImageType::RegionType RegionType; - typedef typename InputImageType::Pointer InputImagePointerType; - /** Toogle the pad option */ - itkGetMacro(Region, RegionType); - itkSetMacro(InsideValue, PixelType); - itkGetMacro(InsideValue, PixelType); - itkSetMacro(Pad, unsigned int); - itkGetMacro(Pad, unsigned int); - -protected: - /** Constructor */ - BinaryImageMinimalBoundingRegionCalculator(); - /** Destructor */ - ~BinaryImageMinimalBoundingRegionCalculator() override {} - /** Main computation method */ - void GenerateData(void) override; - /** PrintSelf method */ - void PrintSelf(std::ostream& os, itk::Indent indent) const override; -private: - BinaryImageMinimalBoundingRegionCalculator(const Self &) = delete; - void operator =(const Self&) = delete; - /** The computed region */ - RegionType m_Region; - /** Toogle if pad wanted */ - unsigned int m_Pad; - /** Inside value */ - PixelType m_InsideValue; -}; -} // End namespace otb - -#ifndef OTB_MANUAL_INSTANTIATION -#include "otbBinaryImageMinimalBoundingRegionCalculator.hxx" -#endif - -#endif diff --git a/Modules/Filtering/ImageManipulation/include/otbBinaryImageMinimalBoundingRegionCalculator.hxx b/Modules/Filtering/ImageManipulation/include/otbBinaryImageMinimalBoundingRegionCalculator.hxx deleted file mode 100644 index cfe5d95b6b9d8099421302cab87764d99d84e8a3..0000000000000000000000000000000000000000 --- a/Modules/Filtering/ImageManipulation/include/otbBinaryImageMinimalBoundingRegionCalculator.hxx +++ /dev/null @@ -1,159 +0,0 @@ -/* - * Copyright (C) 2005-2019 Centre National d'Etudes Spatiales (CNES) - * - * This file is part of Orfeo Toolbox - * - * https://www.orfeo-toolbox.org/ - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef otbBinaryImageMinimalBoundingRegionCalculator_hxx -#define otbBinaryImageMinimalBoundingRegionCalculator_hxx - -#include "otbBinaryImageMinimalBoundingRegionCalculator.h" -#include "itkImageSliceConstIteratorWithIndex.h" -#include "otbMacro.h" - -namespace otb -{ -/* - * Constructor - */ -template <class TInputImage> -BinaryImageMinimalBoundingRegionCalculator<TInputImage> -::BinaryImageMinimalBoundingRegionCalculator() -{ - // The pad option is desactivated by default - m_Pad = 0; - // Set the default region - typename InputImageType::SizeType size; - typename InputImageType::IndexType index; - size[0] = 0; - size[1] = 0; - index[0] = 0; - index[1] = 0; - m_Region.SetSize(size); - m_Region.SetIndex(index); - m_InsideValue = static_cast<PixelType>(255); -} -/** - * Main computation method - */ -template <class TInputImage> -void -BinaryImageMinimalBoundingRegionCalculator<TInputImage> -::GenerateData(void) -{ - // Input images pointers - const InputImageType* image = this->GetInput(); - // Iterator definition - typedef itk::ImageSliceConstIteratorWithIndex<InputImageType> SliceIteratorType; - // Indexes containing upper-left and lower-right corner - typename InputImageType::IndexType min; - typename InputImageType::IndexType max; - min[0] = 0; - min[1] = 0; - max[1] = 0; - max[1] = 0; - for (unsigned int axis = 0; axis < InputImageType::ImageDimension; ++axis) - { // Create the forward iterator to find lower bound - SliceIteratorType fit(image, image->GetLargestPossibleRegion()); - - fit.SetFirstDirection(!axis); - fit.SetSecondDirection(axis); - fit.GoToBegin(); - - // Walk through the two images line by line - while (!fit.IsAtEnd()) - { - while (!fit.IsAtEndOfSlice()) - { - while (!fit.IsAtEndOfLine()) - { - // If a common intersection is found - if (fit.Get() == m_InsideValue) - { - // then the lower bound is found - min[axis] = fit.GetIndex()[axis]; - fit.GoToReverseBegin(); // skip to the end - break; - } - ++fit; - } - fit.NextLine(); - } - fit.NextSlice(); - } - // Create the reverse iterator to find upper bound - SliceIteratorType rit(image, image->GetLargestPossibleRegion()); - rit.SetFirstDirection(!axis); - rit.SetSecondDirection(axis); - rit.GoToReverseBegin(); - // Walk through the two images line by line - while (!rit.IsAtReverseEnd()) - { - while (!rit.IsAtReverseEndOfSlice()) - { - while (!rit.IsAtReverseEndOfLine()) - { - // If a common intersection is found - if (rit.Get() == m_InsideValue) - { - max[axis] = rit.GetIndex()[axis]; - rit.GoToBegin(); //Skip to reverse end - break; - } - --rit; - - } - rit.PreviousLine(); - - } - rit.PreviousSlice(); - } - } - - typename InputImageType::SizeType size; - typename InputImageType::IndexType index; - - for (unsigned int i = 0; i < InputImageType::ImageDimension; ++i) - { - size[i] = max[i] - min[i] + 1; - index[i] = min[i]; - } - - m_Region.SetIndex(index); - m_Region.SetSize(size); - - if (m_Pad) - { - m_Region.PadByRadius(m_Pad); - } - - m_Region.Crop(image->GetLargestPossibleRegion()); -} -/** - * PrintSelf method - */ -template <class TInputImage> -void -BinaryImageMinimalBoundingRegionCalculator<TInputImage> -::PrintSelf(std::ostream& os, itk::Indent indent) const -{ - Superclass::PrintSelf(os, indent); -} - -} // End namespace otb - -#endif diff --git a/Modules/Filtering/ImageManipulation/test/otbBinaryImageMinimalBoundingRegionCalculator.cxx b/Modules/Filtering/ImageManipulation/test/otbBinaryImageMinimalBoundingRegionCalculator.cxx deleted file mode 100644 index 90d3167cbb890262026198319a4b781b9af99b73..0000000000000000000000000000000000000000 --- a/Modules/Filtering/ImageManipulation/test/otbBinaryImageMinimalBoundingRegionCalculator.cxx +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright (C) 2005-2019 Centre National d'Etudes Spatiales (CNES) - * - * This file is part of Orfeo Toolbox - * - * https://www.orfeo-toolbox.org/ - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "itkMacro.h" -#include "otbImage.h" -#include "otbBinaryImageMinimalBoundingRegionCalculator.h" -#include "otbImageFileReader.h" -#include "otbImageList.h" - -int otbBinaryImageMinimalBoundingRegionCalculator(int itkNotUsed(argc), char* argv[]) -{ - const unsigned int Dimension = 2; - - int nbImages = atoi(argv[1]); - char * outfile = argv[2]; - - typedef unsigned char PixelType; - typedef otb::Image<PixelType, Dimension> ImageType; - typedef otb::ImageFileReader<ImageType> ReaderType; - typedef otb::BinaryImageMinimalBoundingRegionCalculator<ImageType> - BoundingRegionCalculatorType; - typedef BoundingRegionCalculatorType::RegionType RegionType; - typedef otb::ImageList<ImageType> ImageListType; - typedef ImageListType::Iterator IteratorType; - // reference image list - ImageListType::Pointer images = ImageListType::New(); - - // Reading input images - std::ofstream out; - out.open(outfile, std::ios::out); - out << "Test results from otbBinaryImageBoundingRegionCalculator test." << std::endl; - for (int i = 1; i <= nbImages; ++i) - { - ReaderType::Pointer reader = ReaderType::New(); - reader->SetFileName(argv[2 + i]); - reader->Update(); - images->PushBack(reader->GetOutput()); - } - - // Declaration - BoundingRegionCalculatorType::Pointer brct; - // Computing bounding region for each image - for (IteratorType it = images->Begin(); it != images->End(); ++it) - { - brct = BoundingRegionCalculatorType::New(); - brct->SetInput(it.Get()); - brct->Update(); - RegionType region = brct->GetRegion(); - out << region.GetIndex() << "\t" << region.GetSize() << std::endl; - } - out << std::endl << "Testing the pad option" << std::endl << std::endl; - for (IteratorType it = images->Begin(); it != images->End(); ++it) - { - brct = BoundingRegionCalculatorType::New(); - brct->SetPad(1); - brct->SetInput(it.Get()); - brct->Update(); - RegionType region = brct->GetRegion(); - out << region.GetIndex() << "\t" << region.GetSize() << std::endl; - } - - out.close(); - - return EXIT_SUCCESS; -}