SimpleITK  1.2.4
HelloWorld/HelloWorld.py
1 #!/usr/bin/env python
2 #=========================================================================
3 #
4 # Copyright Insight Software Consortium
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 SimpleITK as sitk
21 
22 # Create an image
23 pixelType = sitk.sitkUInt8
24 imageSize = [128, 128]
25 image = sitk.Image( imageSize, pixelType )
26 
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( sitk.GaussianSource(pixelType, imageSize, mouthRadii, mouthCenter),
48  200, 255, 255 )
49 # Paste the mouth into the face
50 mouthSize = [64, 18]
51 mouthLoc = [32, 76]
52 face = sitk.Paste(face, mouth, mouthSize, mouthLoc, mouthLoc)
53 
54 # Apply the face to the original image
55 image = image+face
56 
57 # Display the results
58 sitk.Show( image, title="Hello World: Python", debugOn=True )