2 * This program is free software: you can redistribute it and/or modify
3 * it under the terms of the GNU Lesser General Public License as
4 * published by the Free Software Foundation, either version 3 of the
5 * License, or (at your option) any later version.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 * @author Pierre Gueth (\c pierre.gueth@gmail.com )
20 * Laboratoire d'InfoRmatique en Image et Systèmes d'information - LIRIS (CNRS, UMR 5205), CNRS, France
24 * Header file for module ITKWriter.cpp
26 * This file is part of the DGtal library.
29#include "DGtal/images/ConstImageAdapter.h"
30#include "DGtal/images/ImageContainerByITKImage.h"
32#pragma GCC diagnostic push
33#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
34#pragma GCC diagnostic ignored "-Wpedantic"
37#pragma clang diagnostic push
38#pragma clang diagnostic ignored "-Wdocumentation"
40#include <itkImageFileWriter.h>
42#pragma clang diagnostic pop
45#pragma GCC diagnostic pop
48///////////////////////////////////////////////////////////////////////////////
49// IMPLEMENTATION of inline methods.
50///////////////////////////////////////////////////////////////////////////////
54 template<typename I,typename F>
56 ITKWriter<I,F>::exportITK(const std::string& filename, const I& aImage, const Functor& aFunctor)
58 return ITKWriter<I,F>::exportITK(filename, aImage, SpacingType::diagonal(1), aFunctor);
61 template<typename I,typename F>
63 ITKWriter<I,F>::exportITK(const std::string& filename, const I& aImage, const SpacingType &anImgSpacing,
64 const Functor& aFunctor)
66 typedef typename Image::Domain Domain;
67 const Domain& domain = aImage.domain();
69 typedef ConstImageAdapter<Image, Domain, functors::Identity, ValueOut, Functor> AdaptedImage;
70 const functors::Identity identityFunctor{};
71 const AdaptedImage adapted(aImage, domain, identityFunctor, aFunctor);
73 typedef ImageContainerByITKImage<Domain, ValueOut> DGtalITKImage;
74 DGtalITKImage itk_image(aImage.domain());
76 std::copy(adapted.constRange().begin(), adapted.constRange().end(), itk_image.range().outputIterator());
78 typedef itk::ImageFileWriter<typename DGtalITKImage::ITKImage> ITKImageWriter;
79 typename ITKImageWriter::Pointer writer = ITKImageWriter::New();
82 itk_image.setImageSpacing(anImgSpacing);
83 writer->SetFileName(filename);
84 writer->SetInput(itk_image.getITKImagePointer());
87 catch (itk::ExceptionObject &e)
96 template <typename TDomain, typename TValue, typename TFunctor>
98 ITKWriter< ImageContainerByITKImage<TDomain, TValue>, TFunctor >::exportITK(const std::string& filename,
99 const ImageContainerByITKImage<TDomain, TValue>& aImage,[[maybe_unused]] const TFunctor& aFunctor)
102 typedef typename Image::Domain Domain;
104 typedef ImageContainerByITKImage<Domain, ValueOut> DGtalITKImage;
105 typedef itk::ImageFileWriter<typename DGtalITKImage::ITKImage> ITKImageWriter;
106 typename ITKImageWriter::Pointer writer = ITKImageWriter::New();
109 writer->SetFileName(filename);
110 writer->SetInput(aImage.getITKImagePointer());
113 catch (itk::ExceptionObject &e)