ITK  5.2.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
*
* http://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[])
{
FloatImageType::Pointer image;
// Verify input
if (argc < 2)
{
image = FloatImageType::New();
CreateImage(image);
// std::cerr << "Required: filename" << std::endl;
// return EXIT_FAILURE;
}
else
{
// Read the image
ReaderType::Pointer reader = ReaderType::New();
reader->SetFileName(argv[1]);
reader->Update();
image = reader->GetOutput();
}
// Define some types
using UnsignedCharImageType = itk::Image<unsigned char, 2>;
// Compute the FFT
FFTType::Pointer 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...
IFFTType::Pointer ifftFilter = IFFTType::New();
ifftFilter->SetInput(fftFilter->GetOutput());
ifftFilter->Update();
CastFilterType::Pointer castFilter = CastFilterType::New();
castFilter->SetInput(ifftFilter->GetOutput());
castFilter->Update();
WriterType::Pointer writer = WriterType::New();
writer->SetFileName("ifft.png");
writer->SetInput(castFilter->GetOutput());
writer->Update();
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);
}
}
}
itk::CastImageFilter
Casts input pixels to output pixel type.
Definition: itkCastImageFilter.h:104
itk::Index
Represent a n-dimensional index in a n-dimensional image.
Definition: itkIndex.h:66
itk::Size< 2 >
itkInverseFFTImageFilter.h
itk::ImageRegion
An image region represents a structured region of data.
Definition: itkImageRegion.h:69
itkImageFileReader.h
itkImage.h
itkCastImageFilter.h
itk::ForwardFFTImageFilter
Base class for forward Fast Fourier Transform.
Definition: itkForwardFFTImageFilter.h:62
itk::ImageFileReader
Data source that reads image data from a single file.
Definition: itkImageFileReader.h:75
itkForwardFFTImageFilter.h
itk::GTest::TypedefsAndConstructors::Dimension2::IndexType
ImageBaseType::IndexType IndexType
Definition: itkGTestTypedefsAndConstructors.h:50
itk::ImageFileWriter
Writes image data to a single file.
Definition: itkImageFileWriter.h:87
itk::InverseFFTImageFilter
Base class for inverse Fast Fourier Transform.
Definition: itkInverseFFTImageFilter.h:50
itkRescaleIntensityImageFilter.h
itkImageFileWriter.h
itk::IndexValueType
signed long IndexValueType
Definition: itkIntTypes.h:90
itk::Image
Templated n-dimensional image class.
Definition: itkImage.h:86