Skip to content

Commit fb8292e

Browse files
committed
Improved python intro tutorial
1 parent bf0d3a2 commit fb8292e

File tree

1 file changed

+66
-7
lines changed

1 file changed

+66
-7
lines changed

doc/pages/Python-tutorial-intro.dox

Lines changed: 66 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,14 @@ Our entire example should now look like this:
5555

5656
@code{.py}
5757
import fast
58-
importer = fast.ImageFileImporter.create(fast.Config.getTestDataPath() + 'US/Heart/ApicalFourChamber/US-2D_0.mhd')
58+
importer = fast.ImageFileImporter\
59+
.create(fast.Config.getTestDataPath() + 'US/Heart/ApicalFourChamber/US-2D_0.mhd')
5960

6061
# Set up a renderer and connect it to the importer
6162
renderer = fast.ImageRenderer.create().connect(importer)
6263

6364
# Create a window, add the renderer and start the computation/rendering loop.
64-
window = fast.SimpleWindow2D.create().connect(renderer)
65-
window.run()
65+
fast.SimpleWindow2D.create().connect(renderer).run()
6666
@endcode
6767

6868
You should now see this image:
@@ -88,7 +88,8 @@ de-noising ultrasound images.
8888

8989
@code{.py}
9090
import fast
91-
importer = fast.ImageFileImporter.create(fast.Config.getTestDataPath() + 'US/Heart/ApicalFourChamber/US-2D_0.mhd')
91+
importer = fast.ImageFileImporter\
92+
.create(fast.Config.getTestDataPath() + 'US/Heart/ApicalFourChamber/US-2D_0.mhd')
9293

9394
# Set up the NonLocalMeans processing step and connect it to the importer
9495
nlm = fast.NonLocalMeans.create().connect(importer)
@@ -142,8 +143,12 @@ cameras and even from ultrasound scanners.
142143
First, we are going to try streaming from disk. To do this, simply
143144
replace the ImageFileImporter with an ImageFileStreamer in the previous code example:
144145

145-
@code{.cpp}
146-
importer = fast.ImageFileStreamer.create(fast.Config.getTestDataPath() + '/US/Heart/ApicalFourChamber/US-2D_#.mhd', True)
146+
@code{.py}
147+
importer = fast.ImageFileStreamer.create(
148+
fast.Config.getTestDataPath() + '/US/Heart/ApicalFourChamber/US-2D_#.mhd',
149+
loop=True,
150+
framerate=10,
151+
)
147152
@endcode
148153

149154
Compile and run the application, and you should now see an entire ultrasound recording being played back to you on screen.
@@ -166,6 +171,53 @@ for image in fast.DataStream(nlm):
166171
frameNr += 1
167172
@endcode
168173

174+
Image segmentation
175+
-----------------------------------------
176+
177+
Segmentation is the process of classifying each pixel in a image.
178+
In FAST, a segmentation is represented as an Image object with 8-bit unsigned integer data type and a single channel.
179+
Typically, segmentations are displayed as transparent color overlays on the original image.
180+
In the example below, a simple binary thresholding is applied to a stream of ultrasound images.
181+
A SegmentationRenderer is used to render a transparent overlay on the input image which is, as before, rendered
182+
using an ImageRenderer:
183+
184+
@code{.py}
185+
import fast
186+
187+
streamer = fast.ImageFileStreamer.create(
188+
fast.Config.getTestDataPath() + '/US/Heart/ApicalFourChamber/US-2D_#.mhd',
189+
loop=True,
190+
framerate=10
191+
)
192+
segmentation = fast.BinaryThresholding.create(100).connect(streamer)
193+
194+
# Create an image renderer and a segmentation renderer
195+
imageRenderer = fast.ImageRenderer.create().connect(streamer)
196+
segmentationRenderer = fast.SegmentationRenderer.create().connect(segmentation)
197+
198+
# Connect renderers to window and run the whole pipeline
199+
fast.SimpleWindow2D.create(bgcolor=fast.Color.Black())\
200+
.connect([imageRenderer, segmentationRenderer])\
201+
.run()
202+
@endcode
203+
204+
To reduce boilerplate code you can use the [display2D and display3D](@ref shortcuts) functions for displaying data and results.
205+
The example below is equivalent to the one above, but with only 1 line of code for the data display part.
206+
207+
@code{.py}
208+
import fast
209+
210+
streamer = fast.ImageFileStreamer.create(
211+
fast.Config.getTestDataPath() + '/US/Heart/ApicalFourChamber/US-2D_#.mhd',
212+
loop=True,
213+
framerate=10
214+
)
215+
segmentation = fast.BinaryThresholding.create(100).connect(streamer)
216+
217+
# Reduce boilerplate code with setting up renderers and window by using the display2D function:
218+
fast.display2D(streamer, segmentation, bgcolor=fast.Color.Black())
219+
@endcode
220+
169221
Integration with other Python libraries
170222
-----------------------------------------
171223
Images in FAST implements the [Python array interface](https://numpy.org/doc/stable/reference/arrays.interface.html), and may thus be passed onto other Python libraries which
@@ -293,7 +345,14 @@ Here is a complete example on how to do this:
293345

294346
Exporting data
295347
---------------------
296-
@todo
348+
To save data in a given file format, you can use any of the [FAST Exporters](@ref exporters).
349+
For instance to save an image as a jpeg file you can use the ImageFileExporter:
350+
351+
@code{.py}
352+
fast.ImageFileExporter.create('filename.jpg').connect(image).run()
353+
@endcode
354+
355+
ImageFileExporter will recognize the filename extension, e.g. '.jpg', and select the correct exporting routine.
297356

298357
Next steps
299358
---------------------

0 commit comments

Comments
 (0)