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 """ Apply SimpleITK's SmoothGaussianImageFilter to an image. """
22 
23 import os
24 import sys
25 import SimpleITK as sitk
26 
27 
28 def main(args):
29  """ Apply SimpleITK's SmoothGaussianImageFilter to an image. """
30  if len(args) < 4:
31  print("Usage: SimpleGaussian <input> <sigma> <output>")
32  sys.exit(1)
33 
34  reader = sitk.ImageFileReader()
35  reader.SetFileName(args[1])
36  input_image = reader.Execute()
37 
38  pixelID = input_image.GetPixelID()
39 
41  gaussian.SetSigma(float(args[2]))
42  blur_image = gaussian.Execute(input_image)
43 
44  caster = sitk.CastImageFilter()
45  caster.SetOutputPixelType(pixelID)
46  blur_image = caster.Execute(blur_image)
47 
48  writer = sitk.ImageFileWriter()
49  writer.SetFileName(args[3])
50  writer.Execute(blur_image)
51 
52  return_dict = {"input_image": input_image, "blur_image": blur_image}
53  return return_dict
54 
55 
56 # Display the results
57 if __name__ == "__main__":
58  in_image, out_image = main(sys.argv)
59  if "SITK_NOSHOW" not in os.environ:
60  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:74
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:51