SimpleITK  
SimpleGaussian/SimpleGaussian.py
1 #!/usr/bin/env python
2 # =========================================================================
3 #
4 # Copyright NumFOCUS
5 #
6 # Licensed under the Apache License, Version 2.0 (the "License");
7 # you may not use this file except in compliance with the License.
8 # You may obtain a copy of the License at
9 #
10 # http://www.apache.org/licenses/LICENSE-2.0.txt
11 #
12 # Unless required by applicable law or agreed to in writing, software
13 # distributed under the License is distributed on an "AS IS" BASIS,
14 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 # See the License for the specific language governing permissions and
16 # limitations under the License.
17 #
18 # =========================================================================
19 
20 
21 import os
22 import sys
23 import SimpleITK as sitk
24 
25 
26 def main(args):
27  if len(args) < 4:
28  print("Usage: SimpleGaussian <input> <sigma> <output>")
29  sys.exit(1)
30 
31  reader = sitk.ImageFileReader()
32  reader.SetFileName(args[1])
33  input_image = reader.Execute()
34 
35  pixelID = input_image.GetPixelID()
36 
38  gaussian.SetSigma(float(args[2]))
39  blur_image = gaussian.Execute(input_image)
40 
41  caster = sitk.CastImageFilter()
42  caster.SetOutputPixelType(pixelID)
43  blur_image = caster.Execute(blur_image)
44 
45  writer = sitk.ImageFileWriter()
46  writer.SetFileName(args[3])
47  writer.Execute(blur_image)
48 
49  return_dict = {"input_image": input_image,
50  "blur_image": blur_image}
51  return return_dict
52 
53 
54 # Display the results
55 if __name__ == "__main__":
56  in_image, out_image = main(sys.argv)
57  if "SITK_NOSHOW" not in os.environ:
58  sitk.Show(out_image, "Simple Gaussian")
itk::simple::SmoothingRecursiveGaussianImageFilter
Computes the smoothing of an image by convolution with the Gaussian kernels implemented as IIR filter...
Definition: sitkSmoothingRecursiveGaussianImageFilter.h:43
itk::simple::Show
void SITKIO_EXPORT Show(const Image &image, const std::string &title="", const bool debugOn=ProcessObject::GetGlobalDefaultDebug())
itk::simple::ImageFileReader
Read an image file and return a SimpleITK Image.
Definition: sitkImageFileReader.h:60
itk::simple::CastImageFilter
A hybrid cast image filter to convert images to other types of images.
Definition: sitkCastImageFilter.h:39
itk::simple::ImageFileWriter
Write out a SimpleITK image to the specified file location.
Definition: sitkImageFileWriter.h:48