How csheaff/us-beamform-linarray works
1. Repository purpose
- This repo is a side-by-side ultrasound beamforming demo, not a reusable framework.
- It contains two independent implementations of the same idea: a Python educational version and a Rust prototype version.
2. Top-level structure
- example_us_bmode_sensor_data.h5 is the shared input dataset.
- py/linear_array_beamforming.py is the Python pipeline.
- rs/src/main.rs is the Rust pipeline, with build metadata in rs/Cargo.toml.
- The result.png images referenced in the README are generated outputs, showing the final reconstructed B-mode images.
3. Data source boundary
- The only real input is simulated RF sensor data stored in HDF5 format.
- The data was generated externally by the K-Wave MATLAB toolbox using a linear transducer phantom simulation.
- That means the repo does not include simulation code; it consumes precomputed raw sensor data and reconstructs an image from it.
4. Python architecture
- The Python script is the clearer “reference” implementation.
- It loads HDF5 RF data with h5py, processes numeric arrays with numpy and scipy, and visualizes results with matplotlib.
- The README says it demonstrates the conventional ultrasound processing chain and compares simple B-mode imaging, fixed receive-focus beamforming, and dynamic focusing.
5. Python data flow
- Raw sensor data is read from the .h5 file.
- The signal is transformed through a sequence of ultrasound reconstruction steps.
- Intermediate and final images are rendered to visualize the effect of different beamforming strategies.
- This script is oriented toward explaining the algorithmic stages rather than optimizing runtime.
6. Rust architecture
- The Rust side is a minimally functional prototype focused on the same reconstruction problem.
- Core array handling is built around ndarray.
- FFT-related work depends on external native libraries through fftw.
- Image-handling/interop support comes from opencv-rust, while logging and plot generation use simplelog and plotlib.
7. Rust data flow
- The Rust program reads the same kind of RF data and reconstructs a beamformed image, currently using dynamic focusing.
- The README notes that upsampling is slow and signal filtering is not yet implemented.
- This makes the Rust path more of a performance/portability experiment than a complete signal-processing reference.
8. Processing boundaries
- The main architectural boundary is between input RF acquisition data and output reconstructed image.
- Within that boundary, the pipeline is classic ultrasound DSP: load data, manipulate sample arrays, beamform, and display/save the result.
- The repo does not show separate services, network calls, or distributed components.
9. Dependency and runtime implications
- Python depends on the scientific stack: numpy, scipy, matplotlib, h5py.
- Rust relies on native toolchain and system libraries, especially FFTW and OpenCV; the README calls out gfortran and libopenblas-dev as possible prerequisites.
- This is important architecturally because the Rust implementation is not purely self-contained; it bridges into external C/C++ ecosystem libraries.
10. How to draw the diagram
- Show one shared dataset feeding two independent pipelines: Python and Rust.
- Each pipeline should be a single-process batch computation path, not a service.
- Both terminate in an image output/plot, with Python emphasizing comparison of methods and Rust emphasizing dynamic-focused reconstruction and debugging output.
Main entry points: main.rs Beamforming · example_us_bmode_sensor_data.h5 RF dataset · Cargo.toml Cargo manifest
Components 16
Shared data
Common ultrasound input dataset consumed by both pipelines
- RF dataset · Simulated ultrasound sensor data consumed by both pipelines
example_us_bmode_sensor_data.h5
Python pipeline
Reference beamforming implementation
- Beamforming · Educational reconstruction pipeline for conventional ultrasound processing
py/linear_array_beamforming.py - Load data · Reads RF samples and metadata from HDF5
- DSP chain · Array transforms and signal processing stages
- Method compare · Compares basic imaging, fixed focus, and dynamic focusing
- Render plots · Visualizes intermediate and final reconstructed images
- Image output · Saved reconstructed B-mode figure produced by the Python demo
Rust pipeline
Prototype beamforming implementation
- Cargo manifest · Rust dependency and build metadata
rs/Cargo.toml - Beamforming · Prototype dynamic-focused reconstruction program
rs/src/main.rs - Read RF · Loads the same ultrasound sample data into Rust buffers
- Array core · Numerical buffer and intermediate array handling
- Dynamic focus · Reconstructs the image with dynamic receive focusing
- FFT bridge · Native FFT and signal-processing dependency
- Image bridge · Interop for image handling and display support
- Debug output · Logging and lightweight plot generation for inspection
- Image output · Reconstructed beamformed image produced by the Rust demo
Connections 15
- RF dataset → Load data: read · Python ingests the shared HDF5 RF dataset
- Load data → DSP chain: samples · Loaded RF samples enter the reconstruction chain
- DSP chain → Method compare: variants · The pipeline produces multiple beamforming modes for comparison
- Method compare → Render plots: render · Comparison results are visualized as plots and images
- Render plots → Image output: save · Final figures are written as generated image output
- RF dataset → Read RF: read · Rust consumes the same kind of RF input data
- Cargo manifest → Beamforming: build · Cargo metadata defines the binary and external dependencies
- Beamforming → Array core: buffers · Main reconstruction logic operates on ndarray-backed sample buffers
- Beamforming → Dynamic focus: beamform · Dynamic receive focusing reconstructs the image
- Beamforming → FFT bridge: fft · Signal processing depends on native FFTW support
- Beamforming → Image bridge: image · Image interop supports display or export of results
- Beamforming → Debug output: debug · Logging and plotting support runtime inspection
- Dynamic focus → Image output: save · Reconstruction terminates in a generated image artifact
- Read RF → Array core: populate · Loaded RF data becomes numerical arrays for processing
- Dynamic focus → Debug output: trace · Beamforming stages can be inspected through logs and plots