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