This is an example of ultrasound beamforming using a linear array in both Python and Rust. The Python script is written with something of an educational emphasis, and the Rust script is in a minimally-functional state to be refined as Rust's signal and image processing libraries mature.
RF Data was simulated using a 3rd party MATLAB toolbox called K-Wave. Specifically, the data was generated using example_us_bmode_linear_transducer.m
, which sets up a linear probe and generates the signals received after pulsing into a 3D scattering phantom. The phantom accounts for nonlinearity, multiple scattering, power law acoustic absorption, and a finite beam width in the elevation direction. One can find the nature of the simulated data as well as a description of the K-wave program here.
The aforementioned m-file not only simulates recorded data but performs image reconstruction as well. However, I have merely acquired the raw RF data stored in the variable sensor_data
and written my own image reconstruction routines. You know, for fun.
The conventional steps in an ultrasound signal processing pipeline are conducted, and a comparison is performed between simple B-mode imaging, beamforming with fixed receive focus, and dynamic focusing:
This program requires numpy
, scipy
, matplotlib
, and h5py
.
The available signal and image processing libraries written in pure Rust are in their infancy at the time of this writing, so this script makes use of C++ libraries such as fftw
and opencv
. The script is centered around ndarray
and incorporates logging (simplelog
) and plot creation/saving (plotlib
) for the checking of intermediate outputs.
Currently a beamformed image is produced with dynamic focusing, albeit with a slow upsampling step and no signal filtering.
You may be required to install fortran/openblas to compile (e.g. sudo apt-get install gfortran libopenblas-dev
on debian). Notes on installing a version of OpenCV compatible with rust bindings are included.
py | rs |
---|---|