forked from Kitware/VTK
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TestSkeleton2D.py
executable file
·101 lines (100 loc) · 3.23 KB
/
TestSkeleton2D.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#!/usr/bin/env python
import vtk
from vtk.test import Testing
from vtk.util.misc import vtkGetDataRoot
VTK_DATA_ROOT = vtkGetDataRoot()
# A script to test the threshold filter.
# Values above 2000 are set to 255.
# Values below 2000 are set to 0.
# Image pipeline
imageCanvas = vtk.vtkImageCanvasSource2D()
imageCanvas.SetScalarTypeToUnsignedChar()
imageCanvas.SetExtent(0,339,0,339,0,0)
# background black
imageCanvas.SetDrawColor(0)
imageCanvas.FillBox(0,511,0,511)
# thick box
imageCanvas.SetDrawColor(255)
imageCanvas.FillBox(10,110,10,110)
imageCanvas.SetDrawColor(0)
imageCanvas.FillBox(30,90,30,90)
# put a stop sign in the box
imageCanvas.SetDrawColor(255)
imageCanvas.DrawSegment(52,80,68,80)
imageCanvas.DrawSegment(68,80,80,68)
imageCanvas.DrawSegment(80,68,80,52)
imageCanvas.DrawSegment(80,52,68,40)
imageCanvas.DrawSegment(68,40,52,40)
imageCanvas.DrawSegment(52,40,40,52)
imageCanvas.DrawSegment(40,52,40,68)
imageCanvas.DrawSegment(40,68,52,80)
imageCanvas.FillPixel(60,60)
# diamond
imageCanvas.SetDrawColor(255)
imageCanvas.FillTube(145,145,195,195,34)
imageCanvas.SetDrawColor(0)
imageCanvas.FillTube(165,165,175,175,7)
# H
imageCanvas.SetDrawColor(255)
imageCanvas.FillBox(230,250,230,330)
imageCanvas.FillBox(310,330,230,330)
imageCanvas.FillBox(230,330,270,290)
# circle
imageCanvas.SetDrawColor(255)
imageCanvas.DrawCircle(280,170,50.0)
# point as center of circle
imageCanvas.SetDrawColor(255)
imageCanvas.DrawPoint(280,170)
# lines +
imageCanvas.DrawSegment(60,120,60,220)
imageCanvas.DrawSegment(10,170,110,170)
# lines X
imageCanvas.DrawSegment(10,230,110,330)
imageCanvas.DrawSegment(110,230,10,330)
# sloped lines
imageCanvas.DrawSegment(120,230,220,230)
imageCanvas.DrawSegment(120,230,220,250)
imageCanvas.DrawSegment(120,230,220,270)
imageCanvas.DrawSegment(120,230,220,290)
imageCanvas.DrawSegment(120,230,220,310)
imageCanvas.DrawSegment(120,230,220,330)
imageCanvas.DrawSegment(120,230,200,330)
imageCanvas.DrawSegment(120,230,180,330)
imageCanvas.DrawSegment(120,230,160,330)
imageCanvas.DrawSegment(120,230,140,330)
imageCanvas.DrawSegment(120,230,120,330)
# double thickness lines +
imageCanvas.DrawSegment(120,60,220,60)
imageCanvas.DrawSegment(120,61,220,61)
imageCanvas.DrawSegment(170,10,170,110)
imageCanvas.DrawSegment(171,10,171,110)
# lines X
imageCanvas.DrawSegment(230,10,330,110)
imageCanvas.DrawSegment(231,10,331,110)
imageCanvas.DrawSegment(230,110,330,10)
imageCanvas.DrawSegment(231,110,331,10)
skeleton1 = vtk.vtkImageSkeleton2D()
#skeleton1 BypassOn
skeleton1.SetInputConnection(imageCanvas.GetOutputPort())
skeleton1.SetPrune(0)
skeleton1.SetNumberOfIterations(20)
skeleton1.ReleaseDataFlagOff()
clip = vtk.vtkImageClip()
clip.SetInputConnection(skeleton1.GetOutputPort())
clip.SetOutputWholeExtent(0,120,0,120,0,0)
magnify = vtk.vtkImageMagnify()
magnify.SetInputConnection(clip.GetOutputPort())
magnify.SetMagnificationFactors(5,5,1)
magnify.InterpolateOff()
magnify.ReleaseDataFlagOff()
viewer1 = vtk.vtkImageViewer()
viewer1.SetInputConnection(imageCanvas.GetOutputPort())
viewer1.SetColorWindow(5)
viewer1.SetColorLevel(1)
viewer = vtk.vtkImageViewer()
#viewer SetInputConnection [magnify GetOutputPort]
viewer.SetInputConnection(skeleton1.GetOutputPort())
viewer.SetColorWindow(5)
viewer.SetColorLevel(1)
viewer.Render()
# --- end of script --