Pipeline¶
Operations and Pipelines for ultrasound data processing.
This module contains two important classes, Operation and Pipeline,
which are used to process ultrasound data. A pipeline is a sequence of operations
that are applied to the data in a specific order.
We implement a range of common
operations for ultrasound data processing (zea.ops.ultrasound), but also support
a variety of basic tensor operations (zea.ops.tensor). Lastly, all existing Keras
operations (see Keras Ops API) are available as zea
operations as well (see zea.ops.keras_ops).
Stand-alone manual usage¶
Operations can be run on their own:
Examples
>>> import numpy as np
>>> from zea.ops import EnvelopeDetect
>>> data = np.random.randn(2000, 128, 1)
>>> # static arguments are passed in the constructor
>>> envelope_detect = EnvelopeDetect(axis=-1)
>>> # other parameters can be passed here along with the data
>>> envelope_data = envelope_detect(data=data)
Using a pipeline¶
You can initialize with a default pipeline or create your own custom pipeline.
>>> from zea.ops import Pipeline, EnvelopeDetect, Normalize, LogCompress
>>> pipeline = Pipeline.from_default()
>>> operations = [
... EnvelopeDetect(),
... Normalize(),
... LogCompress(),
... ]
>>> pipeline_custom = Pipeline(operations)
One can also load a pipeline from a config or yaml/json file:
>>> from zea import Pipeline
>>> # From JSON string
>>> json_string = '{"pipeline": {"operations": ["identity"]}}'
>>> pipeline = Pipeline.from_json(json_string)
>>> # from yaml file
>>> import yaml
>>> from zea import Config
>>> # Create a sample pipeline YAML file
>>> pipeline_dict = {
... "pipeline": {
... "operations": [
... {"name": "identity"},
... ],
... }
... }
>>> with open("pipeline.yaml", "w") as f:
... yaml.dump(pipeline_dict, f)
>>> yaml_file = "pipeline.yaml"
>>> pipeline = Pipeline.from_path(yaml_file)
Example of a yaml file:
pipeline:
operations:
- name: demodulate
- name: beamform
params:
type: das
pfield: false
num_patches: 100
- name: envelope_detect
- name: normalize
- name: log_compress