ITK  5.4.0
Insight Toolkit
SphinxExamples/src/Filtering/FFT/ComputeInverseFFTOfImage/Code.cxx
/*=========================================================================
*
* Copyright NumFOCUS
*
* 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
*
* https://www.apache.org/licenses/LICENSE-2.0.txt
*
* 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 "itkImage.h"
using FloatImageType = itk::Image<float, 2>;
static void
CreateImage(FloatImageType * const image);
int
main(int argc, char * argv[])
{
// Verify input
if (argc < 2)
{
CreateImage(image);
// std::cerr << "Required: filename" << std::endl;
// return EXIT_FAILURE;
}
else
{
image = itk::ReadImage<FloatImageType>(argv[1]);
}
// Define some types
using UnsignedCharImageType = itk::Image<unsigned char, 2>;
// Compute the FFT
auto fftFilter = FFTType::New();
fftFilter->SetInput(image);
fftFilter->Update();
// Compute the IFFT
// using IFFTType = itk::InverseFFTImageFilter<FFTType::OutputImageType, UnsignedCharImageType>; // This does not work
// - output type seems to need to be float, but it is just an error, not a concept check error...
auto ifftFilter = IFFTType::New();
ifftFilter->SetInput(fftFilter->GetOutput());
ifftFilter->Update();
auto castFilter = CastFilterType::New();
castFilter->SetInput(ifftFilter->GetOutput());
castFilter->Update();
itk::WriteImage(castFilter->GetOutput(), "ifft.png");
return EXIT_SUCCESS;
}
void
CreateImage(FloatImageType * const image)
{
itk::Index<2> corner = { { 0, 0 } };
itk::Size<2> size = { { 200, 200 } };
itk::ImageRegion<2> region(corner, size);
image->SetRegions(region);
image->Allocate();
// Make a square
for (FloatImageType::IndexValueType r = 40; r < 100; ++r)
{
for (FloatImageType::IndexValueType c = 40; c < 100; ++c)
{
FloatImageType::IndexType pixelIndex = { { r, c } };
image->SetPixel(pixelIndex, 100);
}
}
}
Pointer
SmartPointer< Self > Pointer
Definition: itkAddImageFilter.h:93
itk::CastImageFilter
Casts input pixels to output pixel type.
Definition: itkCastImageFilter.h:100
itk::Index
Represent a n-dimensional index in a n-dimensional image.
Definition: itkIndex.h:70
itk::Size< 2 >
itkInverseFFTImageFilter.h
itk::ImageRegion
An image region represents a structured region of data.
Definition: itkImageRegion.h:80
itkImageFileReader.h
itkImage.h
itkCastImageFilter.h
itk::ForwardFFTImageFilter
Base class for forward Fast Fourier Transform.
Definition: itkForwardFFTImageFilter.h:65
itk::IndexValueType
long IndexValueType
Definition: itkIntTypes.h:90
itkForwardFFTImageFilter.h
itk::GTest::TypedefsAndConstructors::Dimension2::IndexType
ImageBaseType::IndexType IndexType
Definition: itkGTestTypedefsAndConstructors.h:50
itk::InverseFFTImageFilter
Base class for inverse Fast Fourier Transform.
Definition: itkInverseFFTImageFilter.h:51
itkRescaleIntensityImageFilter.h
itkImageFileWriter.h
itk::Image
Templated n-dimensional image class.
Definition: itkImage.h:88
New
static Pointer New()
itk::WriteImage
ITK_TEMPLATE_EXPORT void WriteImage(TImagePointer &&image, const std::string &filename, bool compress=false)
Definition: itkImageFileWriter.h:254