ITK  5.4.0
Insight Toolkit
SphinxExamples/src/Filtering/FFT/ComputeInverseFFTOfImage/Code.py
1 #!/usr/bin/env python
2 
3 # Copyright NumFOCUS
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 # https://www.apache.org/licenses/LICENSE-2.0.txt
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16 
17 import itk
18 import argparse
19 
20 parser = argparse.ArgumentParser(description="Compute Inverse FFT Of Image.")
21 parser.add_argument("input_image", nargs="?")
22 args = parser.parse_args()
23 
24 dimension = 2
25 float_image_type = itk.Image[itk.F, dimension]
26 
27 if not args.input_image:
28  corner = itk.Index[dimension]()
29  corner.Fill(0)
30 
31  size = itk.Size[dimension]()
32  size.Fill(200)
33 
34  region = itk.ImageRegion[dimension]()
35  region.SetIndex(corner)
36  region.SetSize(size)
37 
38  image = float_image_type.New(Regions=region)
39  image.Allocate()
40  image.FillBuffer(0)
41 
42  # Make a square
43  image[40:100, 40:100] = 100
44 
45 else:
46  image = itk.imread(args.input_image, pixel_type=itk.F)
47 
48 # Define some types
49 unsigned_char_image_type = itk.Image[itk.UC, dimension]
50 
51 # Compute the FFT
52 image = itk.forward_fft_image_filter(image)
53 
54 # Compute the IFFT
55 image = itk.inverse_fft_image_filter(image)
56 
57 image = itk.cast_image_filter(image, ttype=(float_image_type, unsigned_char_image_type))
58 
59 itk.imwrite(image, "ComputeInverseFFTOfImagePython.png")
itk::Index
Represent a n-dimensional index in a n-dimensional image.
Definition: itkIndex.h:70
itk::Size
Represent a n-dimensional size (bounds) of a n-dimensional image.
Definition: itkSize.h:71
itk::ImageRegion
An image region represents a structured region of data.
Definition: itkImageRegion.h:80
itk::Image
Templated n-dimensional image class.
Definition: itkImage.h:88