]> Creatis software - bbtk.git/blob - packages/demo/bbs/appli/demoFiltering1.bbs
Unify demo codes
[bbtk.git] / packages / demo / bbs / appli / demoFiltering1.bbs
1
2 description "Basic segmentation and filtering of an image"
3 author "jpr@creatis.insa-lyon.fr"
4 category "demo"
5
6 // 3 Slices, 2 volumes
7
8 include std
9 include vtk
10 include wx
11 include itk
12 include itkvtk
13 include wxvtk
14
15 //
16 // Get the image and determine Slice number, slider size, ...
17 // ----------------------------------------------------------
18
19 # Here loads hola.mhd
20 # -------------------
21 include vtk/boxes/bbLoadHola
22 new LoadHola reader
23
24 # uncomment next lines to have a file selector
25 # --------------------------------------------
26 /*
27 new FileSelector openFileDialog
28 new ImageReader reader
29   connect openFileDialog.Out reader.In
30 */
31
32 # uncomment next lines to use Gimmick
33 # -----------------------------------
34 /*
35 load creaImageIO
36 new Gimmick reader
37 */
38
39 # uncomment next lines to Read a MHD file (and nothing else !)
40 # ------------------------------------------------------------
41 /*
42 new FileSelector openFileDialog
43 new MetaImageReader reader
44    connect openFileDialog.Out reader.In
45 */
46
47 # uncomment the following lines to read a 3D images stack
48 # (only if file name order is meaningfull)
49 # -------------------------------------------------------
50 /*
51 // To choose the directory
52 new DirectorySelector ds
53 // To get the image names into a vector
54 new FilesFromDirectory fd
55 // To read all the files, as a bbitk::ImagePointer
56 new ImageSeriesReader reader
57 // user choosen directory as input
58 connect ds.Out fd.In
59 set fd.Recursive false
60 // list of files as input
61 #print "Files found in $ds.Out$\n
62 connect fd.Out reader.FileNames
63 */
64
65 # uncomment the following lines to read a 3D images stack
66 # (if the directory contains a 'XCoherent" Serie)
67 # -------------------------------------------------------
68 /*
69 // To choose the directory
70 new DirectorySelector ds
71 // To get the image names into a vector
72 new FilesFromDirectory fd
73 // user choosen directory as input
74 connect ds.Out fd.In 
75 // order the files, computes an accurate ZSpacing
76 new GetXCoherentInfoGdcmReader reader
77 connect fd.Out reader.In
78 */
79
80 # uncomment the following lines to read a 3D images stack
81 # (with DICOMDirReader)
82 # -------------------------------------------------------
83 /*
84 include itk/boxes/bbDICOMDirReader
85 // To choose the directory
86 new DirectorySelector ds
87 new DICOMDirReader reader
88    connect ds.Out reader.In
89 */
90
91 // We need that to set Sliders sizes
92
93 #Get image dimensions, ...
94 new ImageProperties mc
95    connect reader.Out mc.In
96
97 #Get number of planes  (Z)
98 new GetVectorIntElement gveZ
99    connect mc.Size gveZ.In
100    set gveZ.I 2
101    
102 #Compute the number of the 'middle' slice on Z axis
103 new Div div2
104   connect   gveZ.Out div2.In1
105   set div2.In2 2
106
107 //
108 // Graphical organization
109 // ----------------------
110
111 new LayoutSplit mainSplit
112   set mainSplit.Proportion 60
113   set mainSplit.WinHeight  1000
114   set mainSplit.WinWidth   1400
115   set mainSplit.WinTitle "Processing / Viewing example (demoFiltering1.bbs) "
116
117    new LayoutSplit splitUp
118      set splitUp.Proportion 38
119      connect splitUp.Widget  mainSplit.Widget1
120
121       new LayoutLine toolLayout
122         set toolLayout.Orientation H
123         connect toolLayout.Widget splitUp.Widget1
124
125            new LayoutLine sliderLayout
126               set sliderLayout.Orientation V
127               connect sliderLayout.Widget toolLayout.Widget1
128
129                  new Slider sliceSlider
130                     set sliceSlider.Title "Slice"
131                     set sliceSlider.ReactiveOnTrack true
132                     connect sliceSlider.Widget sliderLayout.Widget1
133
134                  new Slider lowerThresholdSlider
135                     set lowerThresholdSlider.Title "LowerThreshold"
136                     set lowerThresholdSlider.Max        200
137                     set lowerThresholdSlider.In         10
138                     set lowerThresholdSlider.ChangeResolution 1
139                     connect lowerThresholdSlider.Widget sliderLayout.Widget2
140
141                  new Slider upperThresholdSlider
142                     set upperThresholdSlider.Title "UpperThreshold"
143                     set upperThresholdSlider.Max        500
144                     set upperThresholdSlider.In         150
145                     set upperThresholdSlider.ChangeResolution 1
146                     connect upperThresholdSlider.Widget sliderLayout.Widget3
147
148                  new Slider smoothSlider
149                     set smoothSlider.Title "Smooth"
150                     set smoothSlider.Max        10
151                     set smoothSlider.In         3
152                     set smoothSlider.ChangeResolution 1
153                     connect  smoothSlider.Widget sliderLayout.Widget4
154
155            new LayoutLine buttonLayout
156               set buttonLayout.Orientation H
157               connect buttonLayout.Widget toolLayout.Widget2
158
159               new ColourSelectorButton colourThreshold
160                  set colourThreshold.In "1 0 0"
161                  connect colourThreshold.Widget buttonLayout.Widget1
162
163               new ColourSelectorButton colourSmooth
164                  set colourSmooth.In "1 1 0"
165                  connect colourSmooth.Widget buttonLayout.Widget2
166
167
168 /*
169               new CommandButton refresh
170                  set refresh.Label "Refresh (to be used once at start time)"
171                  connect refresh.Widget buttonLayout.Widget3
172 */
173       new LayoutLine layout2D
174          set layout2D.Orientation H
175          connect layout2D.Widget splitUp.Widget2
176
177          new Viewer2D viewer2DImageOriginal
178             connect viewer2DImageOriginal.Widget layout2D.Widget1
179
180          new Viewer2D viewer2DImageSegmented
181             connect viewer2DImageSegmented.Widget layout2D.Widget2
182
183          new Viewer2D viewer2DImageSmooth
184             connect viewer2DImageSmooth.Widget layout2D.Widget3
185
186    new LayoutSplit layout3D
187      set layout3D.Orientation H
188      set layout3D.Proportion 90
189      connect layout3D.Widget  mainSplit.Widget2
190
191         new LayoutSplit layoutSurfaces
192            set layoutSurfaces.Orientation H
193            set layoutSurfaces.Proportion 50
194            connect layoutSurfaces.Widget layout3D.Widget1
195
196            new Viewer3D  viewer3DSurfaceThreshold
197            connect viewer3DSurfaceThreshold.Widget layoutSurfaces.Widget1
198
199            new Viewer3D  viewer3DSurfaceSmooth
200            connect viewer3DSurfaceSmooth.Widget layoutSurfaces.Widget2
201
202         new LayoutLine vSliderLayout
203            connect vSliderLayout.Widget layout3D.Widget2
204
205            new Slider lowerOpacitySlider
206               set lowerOpacitySlider.Title "Opacity"
207               set lowerOpacitySlider.Min        1
208               set lowerOpacitySlider.Max        100
209               set lowerOpacitySlider.In         50
210               set lowerOpacitySlider.Orientation V
211               connect lowerOpacitySlider.Widget vSliderLayout.Widget1
212
213 /*
214            new Slider upperOpacitySlider
215               set upperOpacitySlider.Title "UpperOpacity"
216               set upperOpacitySlider.Max        100
217               set upperOpacitySlider.In         100
218               set upperOpacitySlider.Orientation V
219               connect upperOpacitySlider.Widget vSliderLayout.Widget2
220 */
221
222 //
223 // End of Graphical organization
224 // -----------------------------
225
226 //
227 // Processing pipeline
228 // -------------------
229
230   connect reader.Out                    viewer2DImageOriginal.In
231   connect sliceSlider.Out               viewer2DImageOriginal.Slice
232
233   #Slider size is the number of planes
234   connect gveZ.Out     sliceSlider.Max
235   #initial slice is the middle one
236   connect div2.Out sliceSlider.In
237   set sliceSlider.ChangeResolution 1
238   
239 // Images 2D
240
241  new BinaryThresholdImageFilter threshold
242   set threshold.InsideValue 255
243   set threshold.OutsideValue 0
244
245   connect upperThresholdSlider.Out threshold.UpperThreshold
246   connect lowerThresholdSlider.Out threshold.LowerThreshold
247   connect reader.Out threshold.In
248
249   connect threshold.Out                 viewer2DImageSegmented.In
250   connect sliceSlider.Out               viewer2DImageSegmented.Slice
251
252 new ImageGaussianSmooth smooth
253   connect threshold.Out smooth.In
254   connect smoothSlider.Out smooth.StdDevX
255   connect smoothSlider.Out smooth.StdDevY
256   connect smoothSlider.Out smooth.StdDevZ
257
258   connect smooth.Out            viewer2DImageSmooth.In
259   connect sliceSlider.Out       viewer2DImageSmooth.Slice
260
261
262 // Planes
263 new ImagePlanes planes
264   connect reader.Out planes.In
265   connect planes.PlaneX viewer3DSurfaceSmooth.Obs1
266   connect planes.PlaneY viewer3DSurfaceSmooth.Obs2
267   connect planes.PlaneZ viewer3DSurfaceSmooth.Obs3
268
269 // Surfaces 3D 
270
271 new IsoSurfaceExtractor  isoextractorThreshold
272   connect threshold.Out isoextractorThreshold.In
273   set isoextractorThreshold.Opacity 1  
274   set isoextractorThreshold.Isovalue 100
275   connect colourThreshold.Out isoextractorThreshold.Colour
276   connect isoextractorThreshold.Out  viewer3DSurfaceThreshold.In1
277
278 new Div div3
279    connect lowerOpacitySlider.Out div3.In1
280    set div3.In2 100
281
282 new IsoSurfaceExtractor  isoextractorSmooth
283   connect smooth.Out isoextractorSmooth.In
284   connect div3.Out isoextractorSmooth.Opacity
285   set isoextractorSmooth.Isovalue 200
286   connect colourSmooth.Out isoextractorSmooth.Colour
287   connect isoextractorSmooth.Out  viewer3DSurfaceSmooth.In2
288
289 // Refresh issues
290
291 new MultipleInputs multInForImageOriginal
292   connect sliceSlider.BoxChange multInForImageOriginal.In1
293 #  connect refresh.BoxChange     multInForImageOriginal.In2
294
295
296  new MultipleInputs multInForImageSegmented
297   connect lowerThresholdSlider.BoxChange multInForImageSegmented.In1
298   connect upperThresholdSlider.BoxChange multInForImageSegmented.In2
299 #  connect refresh.BoxChange              multInForImageSegmented.In3
300   connect sliceSlider.BoxChange  multInForImageSegmented.In4    
301     
302  new MultipleInputs multInForImageSmooth
303   connect lowerThresholdSlider.BoxChange multInForImageSmooth.In1
304   connect upperThresholdSlider.BoxChange multInForImageSmooth.In2 
305   connect smoothSlider.BoxChange         multInForImageSmooth.In3
306 #  connect refresh.BoxChange              multInForImageSmooth.In4
307   connect sliceSlider.BoxChange multInForImageSmooth.In5
308
309  new MultipleInputs multInForSurfaceThreshold
310 #  connect refresh.BoxChange multInForSurfaceThreshold.In1
311   connect colourThreshold.BoxChange multInForSurfaceThreshold.In2
312   connect lowerThresholdSlider.BoxChange multInForSurfaceThreshold.In3
313   connect upperThresholdSlider.BoxChange multInForSurfaceThreshold.In4 
314
315  new MultipleInputs multInForSurfaceSmooth
316 #  connect refresh.BoxChange multInForSurfaceSmooth.In1
317   connect lowerOpacitySlider.BoxChange multInForSurfaceSmooth.In1
318   connect colourSmooth.BoxChange multInForSurfaceSmooth.In2
319   connect lowerThresholdSlider.BoxChange multInForSurfaceSmooth.In3
320   connect upperThresholdSlider.BoxChange multInForSurfaceSmooth.In4
321   connect smoothSlider.BoxChange         multInForSurfaceSmooth.In5
322
323   connect multInForImageOriginal.BoxChange     viewer2DImageOriginal.BoxExecute
324   connect multInForImageSegmented.BoxChange    viewer2DImageSegmented.BoxExecute
325   connect multInForImageSmooth.BoxChange       viewer2DImageSmooth.BoxExecute
326
327   connect multInForSurfaceThreshold.BoxChange  viewer3DSurfaceThreshold.BoxExecute
328   connect multInForSurfaceSmooth.BoxChange     viewer3DSurfaceSmooth.BoxExecute
329
330  
331
332   exec mainSplit