MCPcopy Create free account
hub / github.com/SimpleITK/SimpleITK / HelloWorld

Class HelloWorld

Examples/HelloWorld/HelloWorld.java:21–78  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

19import org.itk.simple.*;
20
21class HelloWorld {
22
23 public static void main(String argv[]) {
24
25 // Create an image
26 PixelIDValueEnum pixelType = PixelIDValueEnum.sitkUInt8;
27 long[] isize = {128, 128};
28 VectorUInt32 imageSize = new VectorUInt32( isize );
29 Image image = new Image( imageSize, pixelType );
30
31 // Create a face image
32 double[] fsize = {64., 64.};
33 VectorDouble faceSize = new VectorDouble( fsize );
34 double[] fcenter = {64., 64.};
35 VectorDouble faceCenter = new VectorDouble( fcenter );
36 Image face = SimpleITK.gaussianSource( pixelType, imageSize, faceSize, faceCenter );
37
38 // Create eye images
39 double[] esize = {5., 5.};
40 VectorDouble eyeSize = new VectorDouble( esize );
41 double[] e1center = {48., 48.};
42 VectorDouble eye1Center = new VectorDouble( e1center );
43 double[] e2center = {80., 48.};
44 VectorDouble eye2Center = new VectorDouble( e2center );
45 Image eye1 = SimpleITK.gaussianSource( pixelType, imageSize, eyeSize, eye1Center, 150 );
46 Image eye2 = SimpleITK.gaussianSource( pixelType, imageSize, eyeSize, eye2Center, 150 );
47
48 // Apply the eyes to the face
49 face = SimpleITK.subtract( face, eye1 );
50 face = SimpleITK.subtract( face, eye2 );
51 face = SimpleITK.binaryThreshold( face, 200., 255., (short) 255 );
52
53 // Create the mouth
54 double[] mradius = {30., 20.};
55 VectorDouble mouthRadius = new VectorDouble( mradius );
56 double[] mcenter = {64., 76.};
57 VectorDouble mouthCenter = new VectorDouble( mcenter );
58 Image mouth = SimpleITK.gaussianSource( pixelType, imageSize, mouthRadius, mouthCenter );
59 mouth = SimpleITK.binaryThreshold( mouth, 200, 255, (short) 255 );
60 mouth = SimpleITK.subtract( 255, mouth );
61
62 // Paste the mouth onto the face
63 long[] msize = {64, 18};
64 VectorUInt32 mouthSize = new VectorUInt32( msize );
65 int[] mloc = {32, 76};
66 VectorInt32 mouthLoc = new VectorInt32( mloc );
67 face = SimpleITK.paste( face, mouth, mouthSize, mouthLoc, mouthLoc );
68
69 // Apply the face to the original image
70 image = SimpleITK.add( image, face );
71
72 // Display the results
73 if(System.getenv("SITK_NOSHOW") == null) {
74 SimpleITK.show( image, "Hello World: Java", true );
75 }
76 }
77
78}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected