From 5325f18922ae1df5cc4140613faac009084409ef Mon Sep 17 00:00:00 2001 From: Julien Michel <julien.michel@orfeo-toolbox.org> Date: Thu, 18 Apr 2019 09:36:26 +0000 Subject: [PATCH] REFAC: Remove SeamCarving module --- .../SeamCarvingExampleOutput.png | 3 - .../SeamCarvingOtherExampleOutput.png | 3 - Examples/FeatureExtraction/CMakeLists.txt | 6 - .../FeatureExtraction/SeamCarvingExample.cxx | 176 ----------- .../SeamCarvingOtherExample.cxx | 172 ----------- .../FeatureExtraction/test/CMakeLists.txt | 21 -- Modules/Feature/SeamCarving/CMakeLists.txt | 22 -- .../include/otbAddCarvingPathFilter.h | 141 --------- .../include/otbAddCarvingPathFilter.hxx | 278 ------------------ .../include/otbImageToCarvingPathFilter.h | 116 -------- .../include/otbImageToCarvingPathFilter.hxx | 262 ----------------- .../include/otbRemoveCarvingPathFilter.h | 141 --------- .../include/otbRemoveCarvingPathFilter.hxx | 224 -------------- Modules/Feature/SeamCarving/otb-module.cmake | 38 --- .../Feature/SeamCarving/test/CMakeLists.txt | 32 -- .../test/otbSeamCarvingTestDriver.cxx | 25 -- 16 files changed, 1660 deletions(-) delete mode 100644 Data/Baseline/Examples/FeatureExtraction/SeamCarvingExampleOutput.png delete mode 100644 Data/Baseline/Examples/FeatureExtraction/SeamCarvingOtherExampleOutput.png delete mode 100644 Examples/FeatureExtraction/SeamCarvingExample.cxx delete mode 100644 Examples/FeatureExtraction/SeamCarvingOtherExample.cxx delete mode 100644 Modules/Feature/SeamCarving/CMakeLists.txt delete mode 100644 Modules/Feature/SeamCarving/include/otbAddCarvingPathFilter.h delete mode 100644 Modules/Feature/SeamCarving/include/otbAddCarvingPathFilter.hxx delete mode 100644 Modules/Feature/SeamCarving/include/otbImageToCarvingPathFilter.h delete mode 100644 Modules/Feature/SeamCarving/include/otbImageToCarvingPathFilter.hxx delete mode 100644 Modules/Feature/SeamCarving/include/otbRemoveCarvingPathFilter.h delete mode 100644 Modules/Feature/SeamCarving/include/otbRemoveCarvingPathFilter.hxx delete mode 100644 Modules/Feature/SeamCarving/otb-module.cmake delete mode 100644 Modules/Feature/SeamCarving/test/CMakeLists.txt delete mode 100644 Modules/Feature/SeamCarving/test/otbSeamCarvingTestDriver.cxx diff --git a/Data/Baseline/Examples/FeatureExtraction/SeamCarvingExampleOutput.png b/Data/Baseline/Examples/FeatureExtraction/SeamCarvingExampleOutput.png deleted file mode 100644 index 426eb10b3d..0000000000 --- a/Data/Baseline/Examples/FeatureExtraction/SeamCarvingExampleOutput.png +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:4015aa8e7dcf8993def02252301d5f91eb73b970fecd277f799194551bc99ce0 -size 35299 diff --git a/Data/Baseline/Examples/FeatureExtraction/SeamCarvingOtherExampleOutput.png b/Data/Baseline/Examples/FeatureExtraction/SeamCarvingOtherExampleOutput.png deleted file mode 100644 index eed540571c..0000000000 --- a/Data/Baseline/Examples/FeatureExtraction/SeamCarvingOtherExampleOutput.png +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:da8f331a2806a0c06405abcd7806ebdb668e13a74457151313f13a5ed7c57a32 -size 45234 diff --git a/Examples/FeatureExtraction/CMakeLists.txt b/Examples/FeatureExtraction/CMakeLists.txt index c1e0fbdb00..5d48aead0d 100644 --- a/Examples/FeatureExtraction/CMakeLists.txt +++ b/Examples/FeatureExtraction/CMakeLists.txt @@ -59,12 +59,6 @@ target_link_libraries(PanTexExample ${OTB_LIBRARIES}) add_executable(RatioLineDetectorExample RatioLineDetectorExample.cxx) target_link_libraries(RatioLineDetectorExample ${OTB_LIBRARIES}) -add_executable(SeamCarvingExample SeamCarvingExample.cxx) -target_link_libraries(SeamCarvingExample ${OTB_LIBRARIES}) - -add_executable(SeamCarvingOtherExample SeamCarvingOtherExample.cxx) -target_link_libraries(SeamCarvingOtherExample ${OTB_LIBRARIES}) - add_executable(SFSExample SFSExample.cxx) target_link_libraries(SFSExample ${OTB_LIBRARIES}) diff --git a/Examples/FeatureExtraction/SeamCarvingExample.cxx b/Examples/FeatureExtraction/SeamCarvingExample.cxx deleted file mode 100644 index 854872a1b5..0000000000 --- a/Examples/FeatureExtraction/SeamCarvingExample.cxx +++ /dev/null @@ -1,176 +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. - */ - - -// This example illustrates the details of the seam carving operation. -// References to this method can be found in \cite{Avidan07}. This example -// details the use of \doxygen{otb}{ImageToCarvingPathFilter} and -// \doxygen{otb}{RemoveCarvingPathFilter}. -// -// In this example, a loop is defined to remove a vertical or horizontal seam -// at each step of the algorithm. The seam with the minimum energy is chosen. - -/* Example usage: -./SeamCarvingExample Input/QB_Suburb.png Output/SeamCarvingExampleOutput.png 50 -*/ - - -#include "otbImage.h" -#include "itkPolyLineParametricPath.h" -#include "otbImageFileReader.h" -#include "otbImageFileWriter.h" -#include "itkUnaryFunctorImageFilter.h" -#include "itkGradientMagnitudeImageFilter.h" -#include "itkRescaleIntensityImageFilter.h" - -#include "otbDrawPathFilter.h" -#include "otbImageToCarvingPathFilter.h" -#include "otbRemoveCarvingPathFilter.h" - -#include "itkImageDuplicator.h" - -int main(int itkNotUsed(argc), char* argv[]) -{ - - typedef float InputPixelType; - typedef unsigned char OutputPixelType; - const unsigned int Dimension = 2; - - typedef otb::Image<InputPixelType, Dimension> ImageType; - typedef otb::Image<OutputPixelType, Dimension> OutputImageType; - typedef itk::PolyLineParametricPath<Dimension> PathType; - - typedef otb::ImageFileReader<ImageType> ReaderType; - typedef otb::ImageFileWriter<OutputImageType> WriterType; - typedef itk::RescaleIntensityImageFilter<ImageType, OutputImageType> RescalerType; - - ReaderType::Pointer reader = ReaderType::New(); - WriterType::Pointer writer = WriterType::New(); - RescalerType::Pointer rescaler = RescalerType::New(); - - const char* filenamereader = argv[1]; - reader->SetFileName(filenamereader); - - const char* filenamewriter = argv[2]; - writer->SetFileName(filenamewriter); - - int iteration = atoi(argv[3]); - - // Energy is computed according to the gradient of the image, thus an - // \doxygen{itk}{GradientMagnitudeImageFilter} is instantiated - - typedef itk::GradientMagnitudeImageFilter<ImageType, ImageType> GradientType; - GradientType::Pointer gradient = GradientType::New(); - - // The \doxygen{otb}{ImageToCarvingPathFilter} compute the seam of minimum - // energy according to lines or columns of the image. Later, as we will - // choose the best option between the two, we need two of these filters. - - typedef otb::ImageToCarvingPathFilter<ImageType, PathType> CarvingFilterType; - CarvingFilterType::Pointer carvingFilterVert = CarvingFilterType::New(); - CarvingFilterType::Pointer carvingFilterHor = CarvingFilterType::New(); - - // The \doxygen{otb}{RemoveCarvingPathFilter} will really resize the image - // deleting the path. - - typedef otb::RemoveCarvingPathFilter<ImageType, PathType, ImageType> RemoveCarvingPathFilterType; - RemoveCarvingPathFilterType::Pointer removeCarvingPath = RemoveCarvingPathFilterType::New(); - - // As we are going to iterate through the filters, we need to disconnect the - // pipeline at one point and store the image somewhere. For that purpose, we - // use an \doxygen{itk}{ImageDuplicator} - - typedef itk::ImageDuplicator<ImageType> duplicatorType; - duplicatorType::Pointer duplicator = duplicatorType::New(); - - // Now that all elements have been instantiated, we start to plug the pipeline - // and to define the loop. - - reader->Update(); - duplicator->SetInputImage(reader->GetOutput()); - duplicator->Update(); - - double energyVert, energyHor; - - for (int i = 0; i < iteration; ++i) - { - - gradient->SetInput(duplicator->GetOutput()); - - // Two carving filters processed the gradient image to find the minimum - // vertical seam and the minimum horizontal seam. Note that the - // \code{UpdateLargestPossibleRegion()} need to be used as the size of the - // input image will be different in each loop. - - carvingFilterVert->SetInput(gradient->GetOutput()); - carvingFilterVert->SetDirection(0); - carvingFilterVert->UpdateLargestPossibleRegion(); - energyVert = carvingFilterVert->GetEnergyPerPix(); - - carvingFilterHor->SetInput(gradient->GetOutput()); - carvingFilterHor->SetDirection(1); - carvingFilterHor->UpdateLargestPossibleRegion(); - energyHor = carvingFilterHor->GetEnergyPerPix(); - - // The vertical or the horizontal seam with the minimal energy is chosen. - - if (energyVert < energyHor) - { - removeCarvingPath->SetInput(duplicator->GetOutput()); - removeCarvingPath->SetInputPath(carvingFilterVert->GetOutput()); - removeCarvingPath->SetDirection(0); - removeCarvingPath->UpdateLargestPossibleRegion(); - } - else - { - removeCarvingPath->SetInput(duplicator->GetOutput()); - removeCarvingPath->SetInputPath(carvingFilterHor->GetOutput()); - removeCarvingPath->SetDirection(1); - removeCarvingPath->UpdateLargestPossibleRegion(); - } - - // The duplicator filter keep the results for the next loop - - duplicator->SetInputImage(removeCarvingPath->GetOutput()); - duplicator->Update(); - } - - // Finally, the resulting image is saved on an image file as usual - - rescaler->SetInput(duplicator->GetOutput()); - writer->SetInput(rescaler->GetOutput()); - writer->Update(); - - // Figure~\ref{fig:SEAMCARVING_FILTER} shows the result of applying - // the seam carving filter to a satellite image. - // \begin{figure} - // \center - // \includegraphics[width=0.44\textwidth]{QB_Suburb.eps} - // \includegraphics[width=0.38\textwidth]{SeamCarvingExampleOutput.eps} - // \itkcaption[Seam carving filter application]{Result of applying - // the \doxygen{otb}{ImageToCarvingPathFilter} followed by the - // \doxygen{otb}{RemoveCarvingPathFilter} to Quickbird - // image. From left to right : original image, reduced image removing the 50 - // seams with the lowest energy.} - // \label{fig:SEAMCARVING_FILTER} - // \end{figure} - - return EXIT_SUCCESS; -} diff --git a/Examples/FeatureExtraction/SeamCarvingOtherExample.cxx b/Examples/FeatureExtraction/SeamCarvingOtherExample.cxx deleted file mode 100644 index f8ac6e4e1b..0000000000 --- a/Examples/FeatureExtraction/SeamCarvingOtherExample.cxx +++ /dev/null @@ -1,172 +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. - */ - - -// This example illustrates the use of the \doxygen{otb}{AddCarvingPathFilter}, -// the opposite of the \doxygen{otb}{RemoveCarvingPathFilter}. -// -// Here, we use this filter combined with the \doxygen{otb}{DrawPathFilter} to -// output the image with the removed seam in white. -// -// Most of the code is similar to the previous example. - -/* Example usage: -./SeamCarvingOtherExample Input/QB_Suburb.png Output/SeamCarvingOtherExampleOutput.png 50 -*/ - - -#include "otbImage.h" -#include "itkPolyLineParametricPath.h" -#include "otbImageFileReader.h" -#include "otbImageFileWriter.h" -#include "itkUnaryFunctorImageFilter.h" -#include "itkRescaleIntensityImageFilter.h" -#include "itkGradientMagnitudeImageFilter.h" - -#include "otbDrawPathFilter.h" -#include "otbImageToCarvingPathFilter.h" -#include "otbRemoveCarvingPathFilter.h" -#include "otbAddCarvingPathFilter.h" - -#include "itkImageDuplicator.h" -#include "otbObjectList.h" - -int main(int itkNotUsed(argc), char* argv[]) -{ - - typedef float InputPixelType; - typedef unsigned char OutputPixelType; - const unsigned int Dimension = 2; - - typedef otb::Image<InputPixelType, Dimension> ImageType; - typedef otb::Image<OutputPixelType, Dimension> OutputImageType; - typedef itk::PolyLineParametricPath<Dimension> PathType; - - // We need to define a list to keep the path in memory until the end of - // the seam carving process. This is done using an \doxygen{otb}{ObjectList} - - typedef otb::ObjectList<PathType> PathListType; - PathListType::Pointer pathList = PathListType::New(); - - typedef otb::ImageFileReader<ImageType> ReaderType; - typedef otb::ImageFileWriter<OutputImageType> WriterType; - typedef itk::RescaleIntensityImageFilter<ImageType, OutputImageType> RescalerType; - - ReaderType::Pointer reader = ReaderType::New(); - WriterType::Pointer writer = WriterType::New(); - RescalerType::Pointer rescaler = RescalerType::New(); - - const char* filenamereader = argv[1]; - reader->SetFileName(filenamereader); - - const char* filenamewriter = argv[2]; - writer->SetFileName(filenamewriter); - - int iteration = atoi(argv[3]); - - // We instantiate the different filters of the pipeline as before. - - typedef itk::GradientMagnitudeImageFilter<ImageType, ImageType> GradientType; - GradientType::Pointer gradient = GradientType::New(); - - typedef otb::ImageToCarvingPathFilter<ImageType, PathType> CarvingFilterType; - CarvingFilterType::Pointer carvingFilter = CarvingFilterType::New(); - - typedef otb::DrawPathFilter<ImageType, PathType, ImageType> DrawPathFilterType; - DrawPathFilterType::Pointer drawPathFilter = DrawPathFilterType::New(); - - typedef otb::RemoveCarvingPathFilter<ImageType, PathType, ImageType> RemoveCarvingPathFilterType; - RemoveCarvingPathFilterType::Pointer removeCarvingPath = RemoveCarvingPathFilterType::New(); - - typedef otb::AddCarvingPathFilter<ImageType, PathType, ImageType> AddCarvingPathFilterType; - AddCarvingPathFilterType::Pointer addCarvingPath = AddCarvingPathFilterType::New(); - - typedef itk::ImageDuplicator<ImageType> duplicatorType; - duplicatorType::Pointer duplicator = duplicatorType::New(); - reader->Update(); - duplicator->SetInputImage(reader->GetOutput()); - duplicator->Update(); - - // The loop to shorten the image is similar to the previous one. Here we - // decide to remove alternatively one vertical and one horizontal seam. At - // each iteration, we save the seam on the list using the \code{PushBack()} - // method. - - for (int i = 0; i < iteration; ++i) - { - - gradient->SetInput(duplicator->GetOutput()); - - carvingFilter->SetInput(gradient->GetOutput()); - carvingFilter->SetDirection(i % 2); - - removeCarvingPath->SetInput(duplicator->GetOutput()); - removeCarvingPath->SetInputPath(carvingFilter->GetOutput()); - removeCarvingPath->SetDirection(i % 2); - removeCarvingPath->UpdateLargestPossibleRegion(); - - pathList->PushBack(carvingFilter->GetOutput()); - carvingFilter->GetOutput()->DisconnectPipeline(); - - duplicator->SetInputImage(removeCarvingPath->GetOutput()); - duplicator->Update(); - } - - // The next loop will put back the seam using the - // \doxygen{otb}{AddCarvingPathFilter} and drawing it with the - // \doxygen{otb}{DrawPathFilter}. - - for (int i = iteration - 1; i >= 0; i--) - { - - addCarvingPath->SetInput(duplicator->GetOutput()); - addCarvingPath->SetInputPath(pathList->GetNthElement(i)); - addCarvingPath->SetDirection(i % 2); - addCarvingPath->UpdateLargestPossibleRegion(); - - drawPathFilter->SetInput(addCarvingPath->GetOutput()); - drawPathFilter->SetInputPath(pathList->GetNthElement(i)); - drawPathFilter->UpdateLargestPossibleRegion(); - - duplicator->SetInputImage(drawPathFilter->GetOutput()); - duplicator->Update(); - } - - // Finally, the resulting image is saved on an image file as usual - - rescaler->SetInput(duplicator->GetOutput()); - writer->SetInput(rescaler->GetOutput()); - writer->Update(); - - // Figure~\ref{fig:SEAMCARVING2_FILTER} shows the result of applying - // the seam carving filter to a satellite image. - // \begin{figure} - // \center - // \includegraphics[width=0.44\textwidth]{QB_Suburb.eps} - // \includegraphics[width=0.44\textwidth]{SeamCarvingOtherExampleOutput.eps} - // \itkcaption[Seam carving filter application]{Illustration of the minimum - // seams alternatively vertical and horizontal on a Quickbird - // image. From left to right : original image, image with the 25 vertical - // seams and the 25 horizontal seams.} - // \label{fig:SEAMCARVING2_FILTER} - // \end{figure} - - return EXIT_SUCCESS; -} diff --git a/Examples/FeatureExtraction/test/CMakeLists.txt b/Examples/FeatureExtraction/test/CMakeLists.txt index 50b5174bbe..bea835448e 100644 --- a/Examples/FeatureExtraction/test/CMakeLists.txt +++ b/Examples/FeatureExtraction/test/CMakeLists.txt @@ -90,27 +90,6 @@ otb_add_test(NAME feTeRatioLineDetectorExampleTest COMMAND ${OTB_TEST_DRIVER} 5 1 ) -# ------- SeamCarvingExamplesTest---------- - -otb_add_test(NAME feTeSeamCarvingExampleTest COMMAND ${OTB_TEST_DRIVER} - --compare-image ${NOTOL} - ${BASELINE}/SeamCarvingExampleOutput.png - ${TEMP}/SeamCarvingExampleOutput.png - Execute $<TARGET_FILE:SeamCarvingExample> - ${INPUTDATA}/QB_Suburb.png - ${TEMP}/SeamCarvingExampleOutput.png - 50 -) - -otb_add_test(NAME feTeSeamCarvingOtherExampleTest COMMAND ${OTB_TEST_DRIVER} - --compare-image ${NOTOL} - ${BASELINE}/SeamCarvingOtherExampleOutput.png - ${TEMP}/SeamCarvingOtherExampleOutput.png - Execute $<TARGET_FILE:SeamCarvingOtherExample> - ${INPUTDATA}/QB_Suburb.png - ${TEMP}/SeamCarvingOtherExampleOutput.png - 50 -) #otb_add_test(NAME feTeImageToSIFTKeyPointSetFilterTest COMMAND ${OTB_TEST_DRIVER} # --compare-image ${NOTOL} diff --git a/Modules/Feature/SeamCarving/CMakeLists.txt b/Modules/Feature/SeamCarving/CMakeLists.txt deleted file mode 100644 index 48e2f8a8d7..0000000000 --- a/Modules/Feature/SeamCarving/CMakeLists.txt +++ /dev/null @@ -1,22 +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. -# - -project(OTBSeamCarving) -otb_module_impl() diff --git a/Modules/Feature/SeamCarving/include/otbAddCarvingPathFilter.h b/Modules/Feature/SeamCarving/include/otbAddCarvingPathFilter.h deleted file mode 100644 index 7066a891f5..0000000000 --- a/Modules/Feature/SeamCarving/include/otbAddCarvingPathFilter.h +++ /dev/null @@ -1,141 +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 otbAddCarvingPathFilter_h -#define otbAddCarvingPathFilter_h - -#include "itkImageAndPathToImageFilter.h" -#include "itkImageSliceIteratorWithIndex.h" - -namespace otb -{ -/** \class AddCarvingPathFilter - * \brief This class add pixels given in one path - * - * This filter add pixels found by the otb::ImageToCarvingPathFilter - * thus increasing the image size. - * the image (if Direction is set to 0) or from left to right - * (if direction is set to 1). Pixel value is computed as the average - * between the neighborhood pixels. - * - * This is one component necessary to apply the seam carving algorithm - * published by Shai Avidan, Ariel Shamir, - * Seam Carving for Content-Aware Image Resizing, - * ACM Transactions on Graphics, Volume 26, Number 3, - * SIGGRAPH 2007 - * - * \par INPUTS - * The first input is an image, usually, the same one provided to the - * otb::ImageToCarvingPathFilter - * The second input is a path, typically the output of otb::ImageToCarvingPathFilter. - * - * \par OUTPUTS - * The output is an image with a bigger size than the input image. There is one more - * column if direction is 0 and one more line if direction is 1. - * - * \sa ImageToCarvingPathFilter - * - * - * \ingroup PathFilters - * \ingroup ImageFilters - * - * \ingroup OTBSeamCarving - */ - -template <class TInputImage, class TInputPath, class TOutputImage> -class ITK_EXPORT AddCarvingPathFilter : public itk::ImageAndPathToImageFilter<TInputImage, TInputPath, TOutputImage> -{ -public: - /** Standard class typedefs. */ - typedef AddCarvingPathFilter Self; - typedef itk::ImageAndPathToImageFilter<TInputImage, TInputPath, TOutputImage> Superclass; - typedef itk::SmartPointer<Self> Pointer; - typedef itk::SmartPointer<const Self> ConstPointer; - - /** Method for creation through the object factory. */ - itkNewMacro(Self); - - /** Run-time type information (and related methods). */ - itkTypeMacro(AddCarvingPathFilter, itk::ImageAndPathToImageFilter); - - /** Some convenient typedefs. */ - typedef TInputImage InputImageType; - typedef typename InputImageType::Pointer InputImagePointer; - typedef typename InputImageType::ConstPointer InputImageConstPointer; - typedef typename InputImageType::RegionType InputImageRegionType; - typedef typename InputImageType::PixelType InputImagePixelType; - typedef TInputPath InputPathType; - typedef typename InputPathType::Pointer InputPathPointer; - typedef typename InputPathType::ConstPointer InputPathConstPointer; - typedef typename InputPathType::InputType InputPathInputType; - typedef typename InputPathType::OutputType InputPathOutputType; - typedef typename InputPathType::IndexType InputPathIndexType; - typedef typename InputPathType::OffsetType InputPathOffsetType; - typedef TOutputImage OutputImageType; - typedef typename OutputImageType::Pointer OutputImagePointer; - typedef typename OutputImageType::ConstPointer OutputImageConstPointer; - - typedef typename OutputImageType::RegionType OutputImageRegionType; - typedef typename OutputImageType::PixelType OutputImagePixelType; - typedef typename OutputImageType::ValueType OutputImageValueType; - -// typedef typename itk::ImageRegionConstIterator<InputImageType> InputIteratorType; -// typedef typename itk::ImageRegionIterator<OutputImageType> OutputIteratorType; - typedef typename itk::ImageSliceConstIteratorWithIndex<InputImageType> InputIteratorType; - typedef typename itk::ImageSliceIteratorWithIndex<OutputImageType> OutputIteratorType; - - /** Set/Get the path input of this process object. - Note: these methods are adding to get the proper name */ - void SetInputPath(const TInputPath * path); - - const TInputPath * GetInputPath(void); - - itkSetMacro(Value, OutputImagePixelType); - itkGetConstReferenceMacro(Value, OutputImagePixelType); - - /** Set and Get direction value */ - itkSetMacro(Direction, unsigned int); - itkGetConstMacro(Direction, unsigned int); - - void GenerateOutputInformation() override; - void GenerateInputRequestedRegion() override; - -protected: - AddCarvingPathFilter(); - ~AddCarvingPathFilter() override {} - - void PrintSelf(std::ostream& os, itk::Indent indent) const override; - void GenerateData() override; - -private: - AddCarvingPathFilter(const Self &) = delete; - void operator =(const Self&) = delete; - - OutputImagePixelType m_Value; - unsigned int m_Direction; -}; - -} // end namespace otb - -#ifndef OTB_MANUAL_INSTANTIATION -#include "otbAddCarvingPathFilter.hxx" -#endif - -#endif diff --git a/Modules/Feature/SeamCarving/include/otbAddCarvingPathFilter.hxx b/Modules/Feature/SeamCarving/include/otbAddCarvingPathFilter.hxx deleted file mode 100644 index 5864bc0917..0000000000 --- a/Modules/Feature/SeamCarving/include/otbAddCarvingPathFilter.hxx +++ /dev/null @@ -1,278 +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 otbAddCarvingPathFilter_hxx -#define otbAddCarvingPathFilter_hxx - -#include "otbAddCarvingPathFilter.h" -#include "itkMacro.h" - -namespace otb -{ -/** - * Constructor - */ -template <class TInputImage, class TInputPath, class TOutputImage> -AddCarvingPathFilter<TInputImage, TInputPath, TOutputImage> -::AddCarvingPathFilter() -{ - m_Value = static_cast<OutputImagePixelType>(255.0); - m_Direction = 0; -} -/** - * Main computation method. - */ -template <class TInputImage, class TInputPath, class TOutputImage> -inline void -AddCarvingPathFilter<TInputImage, TInputPath, TOutputImage> -::SetInputPath(const TInputPath * path) -{ - this->SetPathInput(path); -} -template <class TInputImage, class TInputPath, class TOutputImage> -const TInputPath * -AddCarvingPathFilter<TInputImage, TInputPath, TOutputImage> -::GetInputPath(void) -{ - return this->GetPathInput(); -} - -template <class TInputImage, class TInputPath, class TOutputImage> -void -AddCarvingPathFilter<TInputImage, TInputPath, TOutputImage> -::GenerateData(void) -{ - - const InputImageType * inputImage = this->GetImageInput(); - const InputPathType * inputPath = this->GetPathInput(); - OutputImageType * outputImage = this->GetOutput(); - - outputImage->SetBufferedRegion(outputImage->GetRequestedRegion()); - outputImage->Allocate(); - - InputIteratorType inputIterator(inputImage, - inputImage->GetLargestPossibleRegion()); - OutputIteratorType outputIterator(outputImage, - outputImage->GetLargestPossibleRegion()); - - unsigned int dir0; - unsigned int dir1; - - if (m_Direction == 0) - { - dir0 = 0; - dir1 = 1; - } - else - { - dir0 = 1; - dir1 = 0; - } - - inputIterator.SetFirstDirection(dir0); - inputIterator.SetSecondDirection(dir1); - inputIterator.GoToBegin(); - outputIterator.SetFirstDirection(dir0); - outputIterator.SetSecondDirection(dir1); - outputIterator.GoToBegin(); - - int line = -1; - typename InputImageType::IndexType index; - typename InputPathType::VertexListType::ConstPointer vertexList = inputPath->GetVertexList(); - typename InputPathType::VertexListType::ConstIterator pathIterator; - typename InputImageType::IndexType indexToAdd; - typedef typename InputImageType::IndexType::IndexValueType IndexValueType; - - typename InputImageType::SizeType inputSize; - inputSize = inputImage->GetLargestPossibleRegion().GetSize(); - - //go to the end of the path - pathIterator = vertexList->Begin(); - while (pathIterator != vertexList->End()) - { - ++pathIterator; - } - --pathIterator; - - while (!outputIterator.IsAtEnd()) - { - while (!outputIterator.IsAtEndOfSlice()) - { - bool flag = false; - while (!outputIterator.IsAtEndOfLine()) - { - index = outputIterator.GetIndex(); - - if (index[dir1] != line) - { - line = index[dir1]; - typename InputImageType::PointType tmpIndex; - inputImage->TransformContinuousIndexToPhysicalPoint(pathIterator.Value(), tmpIndex); - inputImage->TransformPhysicalPointToIndex(tmpIndex, indexToAdd); - if (pathIterator != vertexList->Begin()) - { - --pathIterator; - } - if (index[dir1] != indexToAdd[dir1]) - { - itkExceptionMacro(<< "Error : " << index[dir1] << " , " << indexToAdd[dir1]); - } - } - - if ((flag == true) - || ((index[dir0] != indexToAdd[dir0]) - && (index[dir0] < static_cast<IndexValueType>(inputSize[dir0])))) - { - outputIterator.Set(inputIterator.Get()); - ++inputIterator; - } - else - { - flag = true; - OutputImagePixelType newValue = itk::NumericTraits<OutputImagePixelType>::Zero; - int n = 0; - InputIteratorType tmpIterator = inputIterator; - --tmpIterator; - if (!tmpIterator.IsAtReverseEndOfLine()) - { - newValue = tmpIterator.Get(); - ++n; - } - tmpIterator = inputIterator; - ++tmpIterator; - if (!tmpIterator.IsAtEndOfLine()) - { - newValue += tmpIterator.Get(); - ++n; - } - assert(n != 0); - newValue /= n; - outputIterator.Set(newValue); - } - ++outputIterator; - - } - - if ((outputIterator.GetIndex())[dir0] != (inputIterator.GetIndex())[dir0] + 1) - { - itkExceptionMacro(<< "Error 2: " << (outputIterator.GetIndex())[dir0] << " , " - << (inputIterator.GetIndex())[dir0]); - } - inputIterator.NextLine(); - outputIterator.NextLine(); - } - inputIterator.NextSlice(); - outputIterator.NextSlice(); - } - -} - -/** - * Printself Method - */ -template <class TInputImage, class TInputPath, class TOutputImage> -void -AddCarvingPathFilter<TInputImage, TInputPath, TOutputImage> -::PrintSelf(std::ostream& os, itk::Indent indent) const -{ - Superclass::PrintSelf(os, indent); - os << indent << "Path Value: " << m_Value << std::endl; -} - -template <class TInputImage, class TInputPath, class TOutputImage> -void -AddCarvingPathFilter<TInputImage, TInputPath, TOutputImage> -::GenerateOutputInformation() -{ - // call the superclass' implementation of this method - Superclass::GenerateOutputInformation(); - - // get pointers to the input and output - typename Superclass::InputImageConstPointer inputPtr = this->GetInput(); - typename Superclass::OutputImagePointer outputPtr = this->GetOutput(); - - unsigned int dir0; - //unsigned int dir1; - - if (m_Direction == 0) - { - dir0 = 0; - //dir1 = 1; - } - else - { - dir0 = 1; - //dir1 = 0; - } - - // we need to compute the output spacing, the output image size, and the - // output image start index - const typename TInputImage::SpacingType& - inputSpacing = inputPtr->GetSignedSpacing(); - const typename TInputImage::SizeType& inputSize - = inputPtr->GetLargestPossibleRegion().GetSize(); - const typename TInputImage::IndexType& inputStartIndex - = inputPtr->GetLargestPossibleRegion().GetIndex(); - - typename TOutputImage::SpacingType outputSpacing; - typename TOutputImage::SizeType outputSize; - typename TOutputImage::IndexType outputStartIndex; - - for (unsigned int i = 0; i < TOutputImage::ImageDimension; ++i) - { - outputSpacing[i] = inputSpacing[i]; - outputSize[i] = (unsigned int) (inputSize[i]); - outputStartIndex[i] = inputStartIndex[i]; - } - // we remove one column of the image - outputSize[dir0] = inputSize[dir0] + 1; - - outputPtr->SetSignedSpacing(outputSpacing); - - typename TOutputImage::RegionType outputLargestPossibleRegion; - outputLargestPossibleRegion.SetSize(outputSize); - outputLargestPossibleRegion.SetIndex(outputStartIndex); - - outputPtr->SetLargestPossibleRegion(outputLargestPossibleRegion); -} - -template <class TInputImage, class TInputPath, class TOutputImage> -void -AddCarvingPathFilter<TInputImage, TInputPath, TOutputImage> -::GenerateInputRequestedRegion() -{ - // call the superclass' implementation of this method - Superclass::GenerateInputRequestedRegion(); - // get pointers to the input and output - InputImagePointer inputPtr = - const_cast<InputImageType *>(this->GetInput()); - if (!inputPtr) - { - itkExceptionMacro(<< "Input has not been set."); - } - - inputPtr->SetRequestedRegion(inputPtr->GetLargestPossibleRegion()); - -} - -} // end namespace otb - -#endif diff --git a/Modules/Feature/SeamCarving/include/otbImageToCarvingPathFilter.h b/Modules/Feature/SeamCarving/include/otbImageToCarvingPathFilter.h deleted file mode 100644 index ad9142b722..0000000000 --- a/Modules/Feature/SeamCarving/include/otbImageToCarvingPathFilter.h +++ /dev/null @@ -1,116 +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 otbImageToCarvingPathFilter_h -#define otbImageToCarvingPathFilter_h - -#include "otbImageToPathFilter.h" -#include "itkImageSliceConstIteratorWithIndex.h" - -namespace otb -{ -/** - * \class ImageToCarvingPathFilter - * \brief This filter find the minimum energy path of an image. - * - * This filter find the minimum energy path from top to bottom of - * the image (if Direction is set to 0) or from left to right - * (if direction is set to 1). - * - * This is one component necessary to apply the seam carving algorithm - * published by Shai Avidan, Ariel Shamir, - * Seam Carving for Content-Aware Image Resizing, - * ACM Transactions on Graphics, Volume 26, Number 3, - * SIGGRAPH 2007 - * - * \par INPUTS - * The input is an image, typically the output of a gradient filter. - * - * \par OUTPUTS - * The output is - * a polyline parametric path comprising one and only one pixel per line - * (resp. column) if direction is 0 (resp. 1). - * - * \sa RemoveCarvingPathFilter - * - * \ingroup PathFilters - * \ingroup ImageFilters - * - * \ingroup OTBSeamCarving - */ - -template <class TInputImage, class TOutputPath> -class ITK_EXPORT ImageToCarvingPathFilter - : public ImageToPathFilter<TInputImage, TOutputPath> -{ -public: - /** standards typedefs */ - typedef ImageToCarvingPathFilter Self; - typedef ImageToPathFilter<TInputImage, TOutputPath> Superclass; - typedef itk::SmartPointer<Self> Pointer; - typedef itk::SmartPointer<const Self> ConstPointer; - - /// Creation through the object factory - itkNewMacro(Self); - /// Runtime information - itkTypeMacro(ImageToCarvingPathFilter, ImageToPathFilter); - - /// Template parameters typedef - typedef typename Superclass::InputImageType InputImageType; - typedef typename Superclass::InputImagePointerType InputImagePointerType; - typedef typename Superclass::OutputPathType OutputPathType; - typedef typename Superclass::OutputPathPointerType OutputPathPointerType; - - typedef typename InputImageType::PixelType PixelType; - - /** Set and Get foreground value */ - itkSetMacro(ForegroundValue, PixelType); - itkGetConstMacro(ForegroundValue, PixelType); - - /** Set and Get direction value */ - itkSetMacro(Direction, unsigned int); - itkGetConstMacro(Direction, unsigned int); - - /** Get EnergyPerPix value */ - itkGetConstMacro(EnergyPerPix, double); - -protected: - ImageToCarvingPathFilter(); - ~ImageToCarvingPathFilter() override {} - void PrintSelf(std::ostream& os, itk::Indent indent) const override; - void GenerateOutputInformation() override {} //does nothing - void GenerateData() override; - -private: - ImageToCarvingPathFilter(const Self &) = delete; - void operator =(const Self&) = delete; - - PixelType m_ForegroundValue; - unsigned int m_Direction; - double m_EnergyPerPix; -}; - -} // end namespace otb - -#ifndef OTB_MANUAL_INSTANTIATION -#include "otbImageToCarvingPathFilter.hxx" -#endif - -#endif diff --git a/Modules/Feature/SeamCarving/include/otbImageToCarvingPathFilter.hxx b/Modules/Feature/SeamCarving/include/otbImageToCarvingPathFilter.hxx deleted file mode 100644 index 1112363027..0000000000 --- a/Modules/Feature/SeamCarving/include/otbImageToCarvingPathFilter.hxx +++ /dev/null @@ -1,262 +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 otbImageToCarvingPathFilter_hxx -#define otbImageToCarvingPathFilter_hxx - -#include "otbImageToCarvingPathFilter.h" -#include "otbMacro.h" -#include "itkConstantPadImageFilter.h" -#include "itkConstShapedNeighborhoodIterator.h" -#include "itkImageRegionConstIterator.h" -#include "itkNumericTraits.h" -#include "itkImageLinearConstIteratorWithIndex.h" - -namespace otb -{ -/* - * Constructor. - */ -template <class TInputImage, class TOutputPath> -ImageToCarvingPathFilter<TInputImage, TOutputPath> -::ImageToCarvingPathFilter() -{ - m_ForegroundValue = PixelType(255); - m_Direction = 0; - m_EnergyPerPix = 0.0; -} - -/** - * Main computation method. - */ -template <class TInputImage, class TOutputPath> -void -ImageToCarvingPathFilter<TInputImage, TOutputPath> -::GenerateData(void) -{ - - const InputImageType * inputImage = this->GetInput(); - OutputPathType * outputPath = this->GetOutput(); - - typedef itk::ImageSliceConstIteratorWithIndex - <InputImageType> IteratorType; - typedef itk::NeighborhoodIterator<InputImageType> - NeighborhoodIteratorType; - - IteratorType it(inputImage, - inputImage->GetLargestPossibleRegion()); - it.GoToBegin(); - - PixelType maxValue = itk::NumericTraits<PixelType>::max(); - - typename InputImageType::Pointer energyImage = InputImageType::New(); - energyImage->SetRegions(inputImage->GetLargestPossibleRegion()); - energyImage->Allocate(); - - typename NeighborhoodIteratorType::RadiusType radius; - radius.Fill(1); - NeighborhoodIteratorType neighIt(radius, energyImage, - energyImage->GetLargestPossibleRegion()); - neighIt.GoToBegin(); - - unsigned int dir0; - unsigned int dir1; - - typename IteratorType::OffsetType UP0; - typename IteratorType::OffsetType UP1; - typename IteratorType::OffsetType UP2; - typename IteratorType::OffsetType NEXT; - - const typename IteratorType::OffsetType LEFT = {{-1, 0}}; - const typename IteratorType::OffsetType RIGHT = {{1, 0}}; - const typename IteratorType::OffsetType UP = {{0, -1}}; - const typename IteratorType::OffsetType DOWN = {{0, 1}}; - const typename IteratorType::OffsetType LEFTUP = {{-1, -1}}; -// const typename IteratorType::OffsetType RIGHTDOWN ={{1, 1}}; - const typename IteratorType::OffsetType RIGHTUP = {{1, -1}}; - const typename IteratorType::OffsetType LEFTDOWN = {{-1, 1}}; -// const typename IteratorType::OffsetType CENTER ={{0, 0}}; - - if (m_Direction == 0) - { - dir0 = 0; - dir1 = 1; - UP0 = LEFTUP; - UP1 = UP; - UP2 = RIGHTUP; - NEXT = DOWN; - } - else - { - dir0 = 1; - dir1 = 0; - UP0 = LEFTUP; - UP1 = LEFT; - UP2 = LEFTDOWN; - NEXT = RIGHT; - } - - /** Compute the energy image top-down or left-right - * with cumulative energy (dynamic programming first step) */ - it.SetFirstDirection(dir0); - it.SetSecondDirection(dir1); - it.GoToBegin(); - neighIt.GoToBegin(); - while (!it.IsAtEnd()) - { - while (!it.IsAtEndOfSlice()) - { - while (!it.IsAtEndOfLine()) - { - neighIt.SetLocation(it.GetIndex()); //TODO bad for performances... find a better option - // this is really about 20% of total processing time !!! - - PixelType min = maxValue; - bool isInside = false; - bool flag = false; - if (neighIt.GetPixel(UP0, isInside) < min) - { - if (isInside) - { - min = neighIt.GetPixel(UP0); - flag = true; - } - } - if (neighIt.GetPixel(UP1, isInside) < min) - { - if (isInside) - { - min = neighIt.GetPixel(UP1); - flag = true; - } - } - if (neighIt.GetPixel(UP2, isInside) < min) - { - if (isInside) - { - min = neighIt.GetPixel(UP2); - flag = true; - } - } - - if (!flag) //no previous value - { - min = 0; - } - - PixelType newValue = it.Get() + min; - neighIt.SetCenterPixel(newValue); - - ++it; - - } - it.NextLine(); - } - it.NextSlice(); - } - - /** Follow the minima bottom-up or right-left - * (dynamic programming second step) */ - - //find the starting point to follow on the last line - typedef itk::ImageLinearConstIteratorWithIndex<InputImageType> - LinearIteratorType; - - LinearIteratorType LinIt(energyImage, - energyImage->GetLargestPossibleRegion()); - LinIt.SetDirection(dir0); - LinIt.GoToReverseBegin(); - typedef typename InputImageType::IndexType IndexType; - - PixelType min = maxValue; - IndexType indexToAdd; - while (!LinIt.IsAtReverseEndOfLine()) - { - if (LinIt.Get() < min) - { - min = LinIt.Get(); - indexToAdd = LinIt.GetIndex(); - } - --LinIt; - } - outputPath->AddVertex(indexToAdd); - m_EnergyPerPix = ((double) min) / (inputImage->GetLargestPossibleRegion().GetSize())[dir1]; - - //follow the min - neighIt.SetLocation(indexToAdd); - bool flag = true; - while (flag) - { - flag = false; - PixelType minValue = maxValue; - IndexType indexToAdd2; - bool isInside = false; - - if (neighIt.GetPixel(UP0, isInside) < min) - { - if (isInside) - { - minValue = neighIt.GetPixel(UP0); - indexToAdd2 = neighIt.GetIndex(UP0); - flag = true; - } - } - - if (neighIt.GetPixel(UP1, isInside) < minValue) - { - if (isInside) - { - minValue = neighIt.GetPixel(UP1); - indexToAdd2 = neighIt.GetIndex(UP1); - flag = true; - } - } - - if (neighIt.GetPixel(UP2, isInside) < minValue) - { - if (isInside) - { - minValue = neighIt.GetPixel(UP2); - indexToAdd2 = neighIt.GetIndex(UP2); - flag = true; - } - } - - if (flag) - { - outputPath->AddVertex(indexToAdd2); - neighIt.SetLocation(indexToAdd2); - } - - } - -} - -template <class TInputImage, class TOutputPath> -void -ImageToCarvingPathFilter<TInputImage, TOutputPath> -::PrintSelf(std::ostream& os, itk::Indent indent) const -{ - Superclass::PrintSelf(os, indent); - os << "Foreground value : " << m_ForegroundValue << std::endl; -} -} // end namespace otb - -#endif diff --git a/Modules/Feature/SeamCarving/include/otbRemoveCarvingPathFilter.h b/Modules/Feature/SeamCarving/include/otbRemoveCarvingPathFilter.h deleted file mode 100644 index c503944f71..0000000000 --- a/Modules/Feature/SeamCarving/include/otbRemoveCarvingPathFilter.h +++ /dev/null @@ -1,141 +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 otbRemoveCarvingPathFilter_h -#define otbRemoveCarvingPathFilter_h - -#include "itkImageAndPathToImageFilter.h" -#include "itkImageSliceIteratorWithIndex.h" - -namespace otb -{ -/** \class RemoveCarvingPathFilter - * \brief This class remove pixels given in one path - * - * - * - * This filter remove pixels found by the otb::ImageToCarvingPathFilter - * thus decreasing the image size. - * the image (if Direction is set to 0) or from left to right - * (if direction is set to 1). - * - * This is one component necessary to apply the seam carving algorithm - * published by Shai Avidan, Ariel Shamir, - * Seam Carving for Content-Aware Image Resizing, - * ACM Transactions on Graphics, Volume 26, Number 3, - * SIGGRAPH 2007 - * - * \par INPUTS - * The first input is an image, usually, the same one provided to the - * otb::ImageToCarvingPathFilter - * The second input is a path, typically the output of otb::ImageToCarvingPathFilter. - * - * \par OUTPUTS - * The output is an image with a smaller size than the input image. There is one less - * column if direction is 0 and one less line if direction is 1. - * - * \sa ImageToCarvingPathFilter - * - * - * \ingroup PathFilters - * \ingroup ImageFilters - * - * \ingroup OTBSeamCarving - */ - -template <class TInputImage, class TInputPath, class TOutputImage> -class ITK_EXPORT RemoveCarvingPathFilter : public itk::ImageAndPathToImageFilter<TInputImage, TInputPath, TOutputImage> -{ -public: - /** Standard class typedefs. */ - typedef RemoveCarvingPathFilter Self; - typedef itk::ImageAndPathToImageFilter<TInputImage, TInputPath, TOutputImage> Superclass; - typedef itk::SmartPointer<Self> Pointer; - typedef itk::SmartPointer<const Self> ConstPointer; - - /** Method for creation through the object factory. */ - itkNewMacro(Self); - - /** Run-time type information (and related methods). */ - itkTypeMacro(RemoveCarvingPathFilter, itk::ImageAndPathToImageFilter); - - /** Some convenient typedefs. */ - typedef TInputImage InputImageType; - typedef typename InputImageType::Pointer InputImagePointer; - typedef typename InputImageType::ConstPointer InputImageConstPointer; - typedef typename InputImageType::RegionType InputImageRegionType; - typedef typename InputImageType::PixelType InputImagePixelType; - typedef TInputPath InputPathType; - typedef typename InputPathType::Pointer InputPathPointer; - typedef typename InputPathType::ConstPointer InputPathConstPointer; - typedef typename InputPathType::InputType InputPathInputType; - typedef typename InputPathType::OutputType InputPathOutputType; - typedef typename InputPathType::IndexType InputPathIndexType; - typedef typename InputPathType::OffsetType InputPathOffsetType; - typedef TOutputImage OutputImageType; - typedef typename OutputImageType::Pointer OutputImagePointer; - typedef typename OutputImageType::ConstPointer OutputImageConstPointer; - - typedef typename OutputImageType::RegionType OutputImageRegionType; - typedef typename OutputImageType::PixelType OutputImagePixelType; - typedef typename OutputImageType::ValueType OutputImageValueType; - -// typedef typename itk::ImageRegionConstIterator<InputImageType> InputIteratorType; -// typedef typename itk::ImageRegionIterator<OutputImageType> OutputIteratorType; - typedef typename itk::ImageSliceConstIteratorWithIndex<InputImageType> InputIteratorType; - typedef typename itk::ImageSliceIteratorWithIndex<OutputImageType> OutputIteratorType; - - /** Set/Get the path input of this process object. - Note: these methods are adding to get the proper name */ - void SetInputPath(const TInputPath * path); - - const TInputPath * GetInputPath(void); - - itkSetMacro(Value, OutputImagePixelType); - itkGetConstReferenceMacro(Value, OutputImagePixelType); - - /** Set and Get direction value */ - itkSetMacro(Direction, unsigned int); - itkGetConstMacro(Direction, unsigned int); - - void GenerateOutputInformation() override; - -protected: - RemoveCarvingPathFilter(); - ~RemoveCarvingPathFilter() override {} - - void PrintSelf(std::ostream& os, itk::Indent indent) const override; - void GenerateData() override; - -private: - RemoveCarvingPathFilter(const Self &) = delete; - void operator =(const Self&) = delete; - - OutputImagePixelType m_Value; - unsigned int m_Direction; -}; - -} // end namespace otb - -#ifndef OTB_MANUAL_INSTANTIATION -#include "otbRemoveCarvingPathFilter.hxx" -#endif - -#endif diff --git a/Modules/Feature/SeamCarving/include/otbRemoveCarvingPathFilter.hxx b/Modules/Feature/SeamCarving/include/otbRemoveCarvingPathFilter.hxx deleted file mode 100644 index 46640119ef..0000000000 --- a/Modules/Feature/SeamCarving/include/otbRemoveCarvingPathFilter.hxx +++ /dev/null @@ -1,224 +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 otbRemoveCarvingPathFilter_hxx -#define otbRemoveCarvingPathFilter_hxx - -#include "otbRemoveCarvingPathFilter.h" -#include "itkMacro.h" - -namespace otb -{ -/** - * Constructor - */ -template <class TInputImage, class TInputPath, class TOutputImage> -RemoveCarvingPathFilter<TInputImage, TInputPath, TOutputImage> -::RemoveCarvingPathFilter() -{ - m_Value = static_cast<OutputImagePixelType>(255.0); - m_Direction = 0; -} - -template <class TInputImage, class TInputPath, class TOutputImage> -inline void -RemoveCarvingPathFilter<TInputImage, TInputPath, TOutputImage> -::SetInputPath(const TInputPath * path) -{ - this->SetPathInput(path); -} - -template <class TInputImage, class TInputPath, class TOutputImage> -const TInputPath * -RemoveCarvingPathFilter<TInputImage, TInputPath, TOutputImage> -::GetInputPath(void) -{ - return this->GetPathInput(); -} - -/** - * Main computation method. - */ -template <class TInputImage, class TInputPath, class TOutputImage> -void -RemoveCarvingPathFilter<TInputImage, TInputPath, TOutputImage> -::GenerateData(void) -{ - - const InputImageType * inputImage = this->GetImageInput(); - const InputPathType * inputPath = this->GetPathInput(); - OutputImageType * outputImage = this->GetOutput(); - - outputImage->SetBufferedRegion(outputImage->GetRequestedRegion()); - outputImage->Allocate(); - - InputIteratorType inputIterator(inputImage, - inputImage->GetLargestPossibleRegion()); - OutputIteratorType outputIterator(outputImage, - outputImage->GetLargestPossibleRegion()); - - unsigned int dir0; - unsigned int dir1; - - if (m_Direction == 0) - { - dir0 = 0; - dir1 = 1; - } - else - { - dir0 = 1; - dir1 = 0; - } - - inputIterator.SetFirstDirection(dir0); - inputIterator.SetSecondDirection(dir1); - inputIterator.GoToBegin(); - outputIterator.SetFirstDirection(dir0); - outputIterator.SetSecondDirection(dir1); - outputIterator.GoToBegin(); - - int line = -1; - typename InputImageType::IndexType index; - typename InputPathType::VertexListType::ConstPointer vertexList = inputPath->GetVertexList(); - typename InputPathType::VertexListType::ConstIterator pathIterator; - typename InputImageType::IndexType indexToRemove; - - //go to the end of the path - pathIterator = vertexList->Begin(); - while (pathIterator != vertexList->End()) - { - ++pathIterator; - } - --pathIterator; - - while (!inputIterator.IsAtEnd()) - { - while (!inputIterator.IsAtEndOfSlice()) - { - while (!inputIterator.IsAtEndOfLine()) - { - index = inputIterator.GetIndex(); - - if (index[dir1] != line) - { - line = index[dir1]; - typename InputImageType::PointType tmpIndex; - inputImage->TransformContinuousIndexToPhysicalPoint(pathIterator.Value(), tmpIndex); - inputImage->TransformPhysicalPointToIndex(tmpIndex, indexToRemove); - - if (pathIterator != vertexList->Begin()) - { - --pathIterator; - } - if (index[dir1] != indexToRemove[dir1]) - { - itkExceptionMacro(<< "Error!!!"); - } - } - if (index[dir0] != indexToRemove[dir0]) - { - outputIterator.Set(inputIterator.Get()); - ++outputIterator; - } - ++inputIterator; - } - inputIterator.NextLine(); - outputIterator.NextLine(); - } - inputIterator.NextSlice(); - outputIterator.NextSlice(); - } - -} - -/** - * Printself Method - */ -template <class TInputImage, class TInputPath, class TOutputImage> -void -RemoveCarvingPathFilter<TInputImage, TInputPath, TOutputImage> -::PrintSelf(std::ostream& os, itk::Indent indent) const -{ - Superclass::PrintSelf(os, indent); - os << indent << "Path Value: " << m_Value << std::endl; -} - -template <class TInputImage, class TInputPath, class TOutputImage> -void -RemoveCarvingPathFilter<TInputImage, TInputPath, TOutputImage> -::GenerateOutputInformation() -{ - // call the superclass' implementation of this method - Superclass::GenerateOutputInformation(); - - // get pointers to the input and output - typename Superclass::InputImageConstPointer inputPtr = this->GetInput(); - typename Superclass::OutputImagePointer outputPtr = this->GetOutput(); - - unsigned int dir0; - //unsigned int dir1; - - if (m_Direction == 0) - { - dir0 = 0; - //dir1 = 1; - } - else - { - dir0 = 1; - //dir1 = 0; - } - - // we need to compute the output spacing, the output image size, and the - // output image start index - const typename TInputImage::SpacingType& - inputSpacing = inputPtr->GetSignedSpacing(); - const typename TInputImage::SizeType& inputSize - = inputPtr->GetLargestPossibleRegion().GetSize(); - const typename TInputImage::IndexType& inputStartIndex - = inputPtr->GetLargestPossibleRegion().GetIndex(); - - typename TOutputImage::SpacingType outputSpacing; - typename TOutputImage::SizeType outputSize; - typename TOutputImage::IndexType outputStartIndex; - - for (unsigned int i = 0; i < TOutputImage::ImageDimension; ++i) - { - outputSpacing[i] = inputSpacing[i]; - outputSize[i] = (unsigned int) (inputSize[i]); - outputStartIndex[i] = inputStartIndex[i]; - } - // we remove one column of the image - outputSize[dir0] = inputSize[dir0] - 1; - - outputPtr->SetSignedSpacing(outputSpacing); - - typename TOutputImage::RegionType outputLargestPossibleRegion; - outputLargestPossibleRegion.SetSize(outputSize); - outputLargestPossibleRegion.SetIndex(outputStartIndex); - - outputPtr->SetLargestPossibleRegion(outputLargestPossibleRegion); -} - -} // end namespace otb - -#endif diff --git a/Modules/Feature/SeamCarving/otb-module.cmake b/Modules/Feature/SeamCarving/otb-module.cmake deleted file mode 100644 index d0f0c8465d..0000000000 --- a/Modules/Feature/SeamCarving/otb-module.cmake +++ /dev/null @@ -1,38 +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. -# - -set(DOCUMENTATION "This module contains necessary components to apply the seam -carving algorithm published by Shai Avidan, Ariel Shamir, Seam Carving for -Content-Aware Resizing, ACM Transactions on Graphics, Volume 26, Number 3, SIGGRAPH -2007.") - -otb_module(OTBSeamCarving - DEPENDS - OTBPath - OTBCommon - OTBITK - - TEST_DEPENDS - OTBTestKernel - OTBImageBase - - DESCRIPTION - "${DOCUMENTATION}" -) diff --git a/Modules/Feature/SeamCarving/test/CMakeLists.txt b/Modules/Feature/SeamCarving/test/CMakeLists.txt deleted file mode 100644 index f8775d775c..0000000000 --- a/Modules/Feature/SeamCarving/test/CMakeLists.txt +++ /dev/null @@ -1,32 +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. -# - -otb_module_test() - -set(OTBSeamCarvingTests -otbSeamCarvingTestDriver.cxx -) - -add_executable(otbSeamCarvingTestDriver ${OTBSeamCarvingTests}) -target_link_libraries(otbSeamCarvingTestDriver ${OTBSeamCarving-Test_LIBRARIES}) -otb_module_target_label(otbSeamCarvingTestDriver) - -# Tests Declaration - diff --git a/Modules/Feature/SeamCarving/test/otbSeamCarvingTestDriver.cxx b/Modules/Feature/SeamCarving/test/otbSeamCarvingTestDriver.cxx deleted file mode 100644 index fb60f68257..0000000000 --- a/Modules/Feature/SeamCarving/test/otbSeamCarvingTestDriver.cxx +++ /dev/null @@ -1,25 +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 "otbTestMain.h" - -void RegisterTests() -{ -} -- GitLab