ITK  4.5.0
Insight Segmentation and Registration Toolkit
Filtering/ResampleImageFilter1.py
1 #==========================================================================
2 #
3 # Copyright Insight Software Consortium
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 #==========================================================================*/
18 
19 
20 from InsightToolkit import *
21 
22 from sys import argv
23 
24 
25 scale = itkScaleTransform2_New()
26 
27 reader = itkImageFileReaderUS2_New()
28 writer = itkImageFileWriterUS2_New()
29 
30 reader.SetFileName( argv[1] )
31 writer.SetFileName( argv[2] )
32 
33 parameters = scale.GetParameters()
34 
35 parameters.SetElement( 0, eval( argv[3] ) )
36 parameters.SetElement( 1, eval( argv[3] ) )
37 
38 reader.Update()
39 
40 inputImage = reader.GetOutput()
41 
42 size = inputImage.GetLargestPossibleRegion().GetSize()
43 
44 centralPixel = itkIndex3()
45 
46 centralPixel.SetElement( 0, size.GetElement(0) / 2 )
47 centralPixel.SetElement( 1, size.GetElement(1) / 2 )
48 
49 centralPoint = itkPointD2()
50 
51 spacing = inputImage.GetSpacing()
52 
53 interpolator = itkLinearInterpolateImageFunctionUS2D_New()
54 
55 centralPoint.SetElement(0, centralPixel.GetElement(0) )
56 centralPoint.SetElement(1, centralPixel.GetElement(1) )
57 
58 scale.SetCenter( centralPoint )
59 scale.SetParameters( parameters )
60 
61 resampler = itkResampleImageFilterUS2US2_New()
62 
63 resampler.SetInput( reader.GetOutput() )
64 
65 resampler.SetTransform( scale.GetPointer() )
66 resampler.SetInterpolator( interpolator.GetPointer() )
67 resampler.SetSize( size )
68 resampler.SetOutputSpacing( spacing )
69 
70 resampler.Update()
71 
72 
73 writer.SetInput( resampler.GetOutput() )
74 
75 writer.Update()
76 
77 
78 
79