{ "cells": [ { "cell_type": "markdown", "id": "30a5e819", "metadata": {}, "source": [ "# REFoCUS: Synthetic Aperture Recovery for Ultrasound Imaging\n", "In this notebook, we demonstrate how to use the [Refocus](../../_autosummary/zea.ops.pipeline.rst) operation to decode plane-wave transmit data into synthetic aperture (SA) data, and how it affects the resulting B-mode image quality.\n", "\n", "REFoCUS works by inverting the transmit encoding model in the frequency domain, effectively recovering a full-matrix capture (multistatic) dataset from a conventional plane-wave or focused transmit sequence. This can improve lateral resolution and contrast compared to standard delay-and-sum beamforming.\n", "\n", "> **References**\n", ">\n", "> Bottenus, N. (2018). *Recovery of the complete data set from focused transmit beams.* IEEE Transactions on Ultrasonics, Ferroelectrics, and Frequency Control, 65(1), 30–38. https://doi.org/10.1109/TUFFC.2017.2773495\n", ">\n", "> Ali, R., Dahl, J., & Bottenus, N. (2019). *Extending Retrospective Encoding for Robust Recovery of the Multistatic Dataset.* IEEE TUFFC, 67(5), 943–956.\n", ">\n", "> Reference implementation: https://github.com/nbottenus/REFoCUS" ] }, { "cell_type": "markdown", "id": "a0525856", "metadata": {}, "source": [ "[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/tue-bmd/zea/blob/main/docs/source/notebooks/pipeline/refocus_pipeline_example.ipynb)\n", " \n", "[![View on GitHub](https://img.shields.io/badge/GitHub-View%20Source-blue?logo=github)](https://github.com/tue-bmd/zea/blob/main/docs/source/notebooks/pipeline/refocus_pipeline_example.ipynb)\n", " \n", "[![Hugging Face dataset](https://img.shields.io/badge/Hugging%20Face-Dataset-yellow?logo=huggingface)](https://huggingface.co/datasets/zeahub/picmus)" ] }, { "cell_type": "markdown", "id": "36097b2e", "metadata": {}, "source": [ "‼️ **Important:** This notebook is optimized for **GPU/TPU**. Code execution on a **CPU** may be very slow.\n", "\n", "If you are running in Colab, please enable a hardware accelerator via:\n", "\n", "**Runtime → Change runtime type → Hardware accelerator → GPU/TPU** 🚀." ] }, { "cell_type": "code", "execution_count": 1, "id": "2892316a", "metadata": {}, "outputs": [], "source": [ "%%capture\n", "%pip install zea" ] }, { "cell_type": "code", "execution_count": 2, "id": "a3e312fd", "metadata": {}, "outputs": [], "source": [ "import os\n", "\n", "os.environ[\"KERAS_BACKEND\"] = \"jax\"\n", "os.environ[\"ZEA_DISABLE_CACHE\"] = \"1\"\n", "os.environ[\"ZEA_LOG_LEVEL\"] = \"INFO\"" ] }, { "cell_type": "markdown", "id": "8ca0649c", "metadata": {}, "source": [ "We'll import all necessary libraries and modules, including the `Refocus` and `Pipeline` classes." ] }, { "cell_type": "code", "execution_count": 3, "id": "311c11ff", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\u001b[1m\u001b[38;5;36mzea\u001b[0m\u001b[0m: Using backend 'jax'\n" ] } ], "source": [ "import matplotlib.pyplot as plt\n", "\n", "import zea\n", "from zea.display import to_8bit\n", "from zea.ops import (\n", " Pipeline,\n", " Cast,\n", " Refocus,\n", " ApplyWindow,\n", " Demodulate,\n", " Beamform,\n", " EnvelopeDetect,\n", " Normalize,\n", " LogCompress,\n", ")\n", "from zea.visualize import set_mpl_style" ] }, { "cell_type": "markdown", "id": "a5d72a4c", "metadata": {}, "source": [ "We will work with the GPU if available, and initialize using `init_device` to pick the best available device. We also set the matplotlib style for consistent plot styling." ] }, { "cell_type": "code", "execution_count": 4, "id": "45f293f1", "metadata": {}, "outputs": [], "source": [ "zea.init_device(verbose=False)\n", "set_mpl_style()" ] }, { "cell_type": "markdown", "id": "c189f821", "metadata": {}, "source": [ "## Loading data\n", "\n", "We'll load a real RF dataset from the [PICMUS](https://www.creatis.insa-lyon.fr/Challenge/IEEE_IUS_2016/home) challenge. This is a contrast-speckle phantom acquired with a plane-wave sequence using 75 transmit angles." ] }, { "cell_type": "code", "execution_count": 5, "id": "params-cell-refocus", "metadata": { "tags": [ "parameters" ] }, "outputs": [], "source": [ "num_transmits = 75\n", "grid_size_x = None\n", "grid_size_z = None" ] }, { "cell_type": "code", "execution_count": 6, "id": "bd1aa79b", "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "6657bd5b4924425f94d420ae08785b6b", "version_major": 2, "version_minor": 0 }, "text/plain": [ "database/experiments/contrast_speckle/co(…): 0%| | 0.00/127M [00:00