Skip to content

Commit 1c1318b

Browse files
kian-weimerdzenanz
authored andcommitted
ENH: Added ComputeInverseFFTOfImage Python script
1 parent 6918c50 commit 1c1318b

File tree

3 files changed

+66
-0
lines changed

3 files changed

+66
-0
lines changed

src/Filtering/FFT/ComputeInverseFFTOfImage/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,8 @@ install(FILES Code.cxx CMakeLists.txt
2323
enable_testing()
2424
add_test(NAME ComputeInverseFFTOfImageTest
2525
COMMAND ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/ComputeInverseFFTOfImage)
26+
27+
if(ITK_WRAP_PYTHON)
28+
add_test(NAME ComputeInverseFFTOfImageTestPython
29+
COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/Code.py)
30+
endif()
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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+
# http://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 sys
18+
import itk
19+
20+
dimension = 2
21+
float_image_type = itk.Image[itk.F, dimension]
22+
23+
if len(sys.argv) < 2:
24+
corner = itk.Index[dimension]()
25+
corner.Fill(0)
26+
27+
size = itk.Size[dimension]()
28+
size.Fill(200)
29+
30+
region = itk.ImageRegion[dimension]()
31+
region.SetIndex(corner)
32+
region.SetSize(size)
33+
34+
image = float_image_type.New(Regions=region)
35+
image.Allocate()
36+
37+
# Make a square
38+
image[40:100, 40:100] = 100
39+
40+
else:
41+
image = itk.imread(sys.argv[1], pixel_type=itk.F)
42+
43+
# Define some types
44+
unsigned_char_image_type = itk.Image[itk.UC, dimension]
45+
46+
# Compute the FFT
47+
image = itk.forward_fft_image_filter(image)
48+
49+
# Compute the IFFT
50+
image = itk.inverse_fft_image_filter(image)
51+
52+
image = itk.cast_image_filter(image, ttype=(float_image_type, unsigned_char_image_type))
53+
54+
itk.imwrite(image, "ComputeInverseFFTOfImagePython.png")

src/Filtering/FFT/ComputeInverseFFTOfImage/Documentation.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,13 @@ Results
2525
Code
2626
----
2727

28+
Python
29+
......
30+
31+
.. literalinclude:: Code.py
32+
:language: python
33+
:lines: 1, 16-
34+
2835
C++
2936
...
3037

0 commit comments

Comments
 (0)