{ "cells": [ { "cell_type": "markdown", "id": "1692bbb0", "metadata": {}, "source": [ "# Speckle2Self: ultrasound speckle reduction\n", "\n", "[![arXiv](https://img.shields.io/badge/arXiv-Paper-b31b1b.svg)](https://arxiv.org/abs/2507.06828)   [![GitHub](https://img.shields.io/badge/GitHub-Code-black?logo=github)](https://github.com/noseefood/speckle2self)\n", "\n", "This notebook demonstrates how to perform **self-supervised ultrasound speckle reduction** using [Speckle2Self](https://arxiv.org/abs/2507.06828) within the [zea](https://github.com/tue-bmd/zea) framework. We apply the model to an **in-vivo carotid artery** scan from [zeahub/zea-carotid-2023](https://huggingface.co/datasets/zeahub/zea-carotid-2023), matching the domain on which the `speckle2self-invivo` weights were trained.\n", "\n", "For more information on the method, see the [original paper](https://arxiv.org/abs/2507.06828):\n", "- Lin, Huiping, et al. \"Speckle2Self: Learning Self-Supervised Despeckling with Attention Mechanism for SAR Images.\" Remote Sensing 17.23 (2025): 3840." ] }, { "cell_type": "markdown", "id": "95796f53", "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/models/speckle2self_despeckling_example.ipynb)   [![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/models/speckle2self_despeckling_example.ipynb)\n", "[![Hugging Face model](https://img.shields.io/badge/Hugging%20Face-Model-yellow?logo=huggingface)](https://huggingface.co/zeahub/speckle2self-invivo)" ] }, { "cell_type": "markdown", "id": "d9f98e76", "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": "3192d444", "metadata": {}, "outputs": [], "source": [ "%%capture\n", "%pip install zea" ] }, { "cell_type": "code", "execution_count": 2, "id": "f254ad42", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\u001b[1m\u001b[38;5;36mzea\u001b[0m\u001b[0m: Using backend 'tensorflow'\n" ] } ], "source": [ "import os\n", "\n", "os.environ[\"KERAS_BACKEND\"] = \"tensorflow\"\n", "\n", "import numpy as np\n", "import keras\n", "import matplotlib.pyplot as plt\n", "\n", "import zea\n", "from zea.ops import (\n", " Beamform,\n", " EnvelopeDetect,\n", " Pipeline,\n", " Cast,\n", " Demodulate,\n", " Downsample,\n", " Normalize,\n", " LogCompress,\n", ")\n", "from zea.visualize import set_mpl_style" ] }, { "cell_type": "code", "execution_count": 3, "id": "d394b567", "metadata": {}, "outputs": [], "source": [ "zea.init_device(verbose=False)\n", "set_mpl_style()" ] }, { "cell_type": "code", "execution_count": 4, "id": "65f38c13", "metadata": {}, "outputs": [], "source": [ "carotid_path = \"hf://zeahub/picmus/in_vivo/carotid_cross/carotid_cross_expe_dataset_rf/carotid_cross_expe_dataset_rf.hdf5\"\n", "frame_idx = 0\n", "n_tx = 11 # transmits per frame (fewer -> faster; more -> better quality)\n", "dynamic_range = (-40, 0) # dB" ] }, { "cell_type": "markdown", "id": "7c543bf7", "metadata": {}, "source": [ "## Load carotid data\n", "\n", "We load a single frame of an in-vivo carotid scan from [zeahub/zea-carotid-2023](https://huggingface.co/datasets/zeahub/zea-carotid-2023) on Hugging Face. Note that this is raw ultrasound RF channel data. Therefore we will first need to beamform and envelope-detect the data before feeding it to the Speckle2Self model. We will do this using the `zea.Pipeline` framework, which provides efficient implementations of these operations. For more details see the [pipeline example notebook](../pipeline/zea_pipeline_example.ipynb) or the [API reference](https://zea.readthedocs.io/en/latest/pipeline.html)." ] }, { "cell_type": "code", "execution_count": 5, "id": "9204a2ea", "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "5dca0d0a0936453bbf7e8088a23814f2", "version_major": 2, "version_minor": 0 }, "text/plain": [ "in_vivo/carotid_cross/carotid_cross_expe(…): 0%| | 0.00/58.6M [00:00