{ "cells": [ { "cell_type": "markdown", "id": "a9e360da", "metadata": {}, "source": [ "# Working with a sequence of images\n", "In this notebook, we will look at how to work with a sequence of images, and possibly change some parameters on the fly. As in all examples, we will start with setting the Keras backend." ] }, { "cell_type": "markdown", "id": "b303c558", "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/zea_sequence_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/zea_sequence_example.ipynb)\n", " \n", "[![Hugging Face dataset](https://img.shields.io/badge/Hugging%20Face-Dataset-yellow?logo=huggingface)](https://huggingface.co/datasets/zeahub/zea-carotid-2023)" ] }, { "cell_type": "markdown", "id": "b6eebf11", "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": "6d6dd155", "metadata": {}, "outputs": [], "source": [ "%%capture\n", "%pip install zea" ] }, { "cell_type": "code", "execution_count": 2, "id": "b41342fd", "metadata": {}, "outputs": [], "source": [ "import os\n", "\n", "os.environ[\"KERAS_BACKEND\"] = \"jax\"" ] }, { "cell_type": "code", "execution_count": 3, "id": "7e4af10b", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\u001b[1m\u001b[38;5;36mzea\u001b[0m\u001b[0m: Using backend 'jax'\n" ] } ], "source": [ "import keras\n", "\n", "import zea\n", "from zea.visualize import set_mpl_style\n", "from zea.internal.notebooks import animate_images" ] }, { "cell_type": "code", "execution_count": 4, "id": "2047ca56", "metadata": { "tags": [ "parameters" ] }, "outputs": [], "source": [ "n_frames = 15\n", "n_tx = 11\n", "n_tx_total = 127" ] }, { "cell_type": "markdown", "id": "6de3d4f2", "metadata": {}, "source": [ "We will work with the GPU if available, and initialize using `init_device` to pick the best available device. Also, (optionally), we will set the matplotlib style for plotting." ] }, { "cell_type": "code", "execution_count": 5, "id": "e55d6107", "metadata": {}, "outputs": [], "source": [ "zea.init_device(verbose=False)\n", "set_mpl_style()" ] }, { "cell_type": "markdown", "id": "449d254c", "metadata": {}, "source": [ "Let's initialize a default B-mode ultrasound image formation pipeline." ] }, { "cell_type": "code", "execution_count": 6, "id": "39a27a22", "metadata": {}, "outputs": [], "source": [ "pipeline = zea.Pipeline.from_default(enable_pfield=False, with_batch_dim=False)" ] }, { "cell_type": "markdown", "id": "c369482f", "metadata": {}, "source": [ "We will load a sequence of acquired RF data frames (carotid scan) and reconstruct a B-mode image from each frame. We will then animate the sequence of images. But first let's load the data and parameters." ] }, { "cell_type": "code", "execution_count": 7, "id": "f79441a3", "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "bc3f1eb2c4e64e5fbe98738a9ebd33d9", "version_major": 2, "version_minor": 0 }, "text/plain": [ "2_cross_bifur_right_0000_small.hdf5: 0%| | 0.00/2.49G [00:00