Skip to content
Snippets Groups Projects
structure_tensor.ipynb 3.44 KiB
Newer Older
  • Learn to ignore specific revisions
  • s193396's avatar
    s193396 committed
    {
     "cells": [
      {
       "cell_type": "code",
       "execution_count": 1,
       "metadata": {},
       "outputs": [
        {
         "name": "stderr",
         "output_type": "stream",
         "text": [
          "WARNING:root:Could not load CuPy: No module named 'cupy'\n"
         ]
        }
       ],
       "source": [
        "import qim3d"
       ]
      },
      {
       "cell_type": "markdown",
       "metadata": {},
       "source": [
        "### Structure tensor notebook"
       ]
      },
      {
       "cell_type": "markdown",
       "metadata": {},
       "source": [
        "This notebook shows how to compute eigenvalues and eigenvectors of the **structure tensor** of a 3D volume using the `qim3d` library. The structure tensor (matrix) represents information about the local gradient directions in the volume, such that the eigenvectors represent the orientation of the structure in the volume, and the corresponding eigenvaleus indicate the magnitude.\n",
        "\n",
        "The function `qim3d.processing.structure_tensor` returns two arrays `val` and `vec` for the eigenvalues and eigenvectors, respectively.\\\n",
        "By having the argument `visulize = True`, the function displays two figures:\n",
        "\n",
        "* Slice of volume with vector field of the eigenvectors\n",
        "* Orientation histogram of the eigenvectors  "
       ]
      },
      {
       "cell_type": "markdown",
       "metadata": {},
       "source": [
        "### **Example 1**: Structure tensor of bone volume"
       ]
      },
      {
       "cell_type": "code",
       "execution_count": 29,
       "metadata": {},
       "outputs": [
        {
         "data": {
          "application/vnd.jupyter.widget-view+json": {
           "model_id": "27aae46cc15f4379a890397802c53fb5",
           "version_major": 2,
           "version_minor": 0
          },
          "text/plain": [
           "VBox(children=(HBox(children=(IntSlider(value=64, description='Slice index', layout=Layout(width='450px'), max…"
          ]
         },
         "metadata": {},
         "output_type": "display_data"
        }
       ],
       "source": [
        "# Import 3D volume of bone\n",
        "bone = qim3d.examples.bone_128x128x128\n",
        "\n",
        "# Compute eigenvalues and eigenvectors of the structure tensor\n",
        "val, vec = qim3d.processing.structure_tensor(bone, visualize = True, axis = 1)"
       ]
      },
      {
       "cell_type": "markdown",
       "metadata": {},
       "source": [
        "### **Example 2:** Structure tensor of brain tissue volume"
       ]
      },
      {
       "cell_type": "code",
       "execution_count": 28,
       "metadata": {},
       "outputs": [
        {
         "data": {
          "application/vnd.jupyter.widget-view+json": {
           "model_id": "9648fa04a18b4f9f8a5c19749ea57d3b",
           "version_major": 2,
           "version_minor": 0
          },
          "text/plain": [
           "VBox(children=(HBox(children=(IntSlider(value=64, description='Slice index', layout=Layout(width='450px'), max…"
          ]
         },
         "metadata": {},
         "output_type": "display_data"
        }
       ],
       "source": [
        "# Import 3D volume of brain tissue\n",
        "NT = qim3d.examples.NT_128x128x128\n",
        "\n",
        "# Compute eigenvalues and eigenvectors of the structure tensor\n",
        "val, vec = qim3d.processing.structure_tensor(NT, visualize = True, axis = 2)"
       ]
      }
     ],
     "metadata": {
      "kernelspec": {
       "display_name": "qim3d",
       "language": "python",
       "name": "python3"
      },
      "language_info": {
       "codemirror_mode": {
        "name": "ipython",
        "version": 3
       },
       "file_extension": ".py",
       "mimetype": "text/x-python",
       "name": "python",
       "nbconvert_exporter": "python",
       "pygments_lexer": "ipython3",
       "version": "3.10.14"
      }
     },
     "nbformat": 4,
     "nbformat_minor": 2
    }