Loading [MathJax]/extensions/tex2jax.js
SimpleITK  2.2.0
HelloWorld/HelloWorld.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 import os
21 import SimpleITK as sitk
22 
23 # Create an image
24 pixelType = sitk.sitkUInt8
25 imageSize = [128, 128]
26 image = sitk.Image(imageSize, pixelType)
27 
28 # Create a face image
29 faceSize = [64, 64]
30 faceCenter = [64, 64]
31 face = sitk.GaussianSource(pixelType, imageSize, faceSize, faceCenter)
32 
33 # Create eye images
34 eyeSize = [5, 5]
35 eye1Center = [48, 48]
36 eye2Center = [80, 48]
37 eye1 = sitk.GaussianSource(pixelType, imageSize, eyeSize, eye1Center, 150)
38 eye2 = sitk.GaussianSource(pixelType, imageSize, eyeSize, eye2Center, 150)
39 
40 # Apply the eyes to the face
41 face = face - eye1 - eye2
42 face = sitk.BinaryThreshold(face, 200, 255, 255)
43 
44 # Create the mouth
45 mouthRadii = [30, 20]
46 mouthCenter = [64, 76]
47 mouth = 255 - sitk.BinaryThreshold(
48  sitk.GaussianSource(pixelType, imageSize, mouthRadii, mouthCenter),
49  200,
50  255,
51  255,
52 )
53 # Paste the mouth into the face
54 mouthSize = [64, 18]
55 mouthLoc = [32, 76]
56 face = sitk.Paste(face, mouth, mouthSize, mouthLoc, mouthLoc)
57 
58 # Apply the face to the original image
59 image = image + face
60 
61 # Display the results
62 if "SITK_NOSHOW" not in os.environ:
63  sitk.Show(image, title="Hello World: Python", debugOn=True)
itk::simple::Image
The Image class for SimpleITK.
Definition: sitkImage.h:76
itk::simple::BinaryThreshold
Image BinaryThreshold(const Image &image1, double lowerThreshold=0.0, double upperThreshold=255.0, uint8_t insideValue=1u, uint8_t outsideValue=0u)
Binarize an input image by thresholding.
itk::simple::Paste
Image Paste(const Image &destinationImage, const Image &sourceImage, std::vector< unsigned int > sourceSize=std::vector< unsigned int >(SITK_MAX_DIMENSION, 1), std::vector< int > sourceIndex=std::vector< int >(SITK_MAX_DIMENSION, 0), std::vector< int > destinationIndex=std::vector< int >(SITK_MAX_DIMENSION, 0), std::vector< bool > DestinationSkipAxes=std::vector< bool >())
Paste an image into another image.
itk::simple::GaussianSource
Image GaussianSource(PixelIDValueEnum outputPixelType=itk::simple::sitkFloat32, std::vector< unsigned int > size=std::vector< unsigned int >(3, 64), std::vector< double > sigma=std::vector< double >(3, 16.0), std::vector< double > mean=std::vector< double >(3, 32.0), double scale=255, std::vector< double > origin=std::vector< double >(3, 0.0), std::vector< double > spacing=std::vector< double >(3, 1.0), std::vector< double > direction=std::vector< double >(), bool normalized=false)
Generate an n-dimensional image of a Gaussian.
itk::simple::Show
void SITKIO_EXPORT Show(const Image &image, const std::string &title="", const bool debugOn=ProcessObject::GetGlobalDefaultDebug())