Newer
Older
"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 a figure of three subplots:\n",
"\n",
"* Slice of volume with vector field of the eigenvectors\n",
"* Orientation histogram of the eigenvectors\n",
"* Slice of volume with overlaying colors of the orientation\n",
"\n",
"For all three subplots, the colors used to visualize the orientation within the volume are from the HSV colorspace. In these visualizations, the saturation of the color corresponds to the vector component of the slicing direction (i.e. $z$-component when choosing visualization along `axis = 0`). Hence, if an orientation in the volume is orthogonal to the slicing direction, the corresponding color of the visualization will be gray."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### **Example:** Structure tensor of brain tissue volume"
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"version_major": 2,
"version_minor": 0
},
"text/plain": [
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"# Import 3D volume of brain tissue\n",
"NT = qim3d.examples.NT_128x128x128\n",
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"From the visualization of the full volume, it can be seen that the circular structures of the brain tissue are aligned orthogonal to the $z$-axis (`axis = 0`). By choosing to slice the volume in this direction, the structure tensor visualizations will largely be gray, since the $z$-component of the eigenvectors are close to $0$, meaning the saturation of the coloring will be close to $0$ (i.e. gray). This can be seen below. "
]
},
{
"cell_type": "code",
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"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": [
"# Compute eigenvalues and eigenvectors of the structure tensor\n",
"val, vec = qim3d.processing.structure_tensor(NT, visualize = True, axis = 0) # Slicing in z-direction"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"By slicing the volume in the $x$-direction (`axis = 2`) instead, the orientation along the length of the structures in the brain tissue can be seen instead. Then the structure tensor visualizations will be largely blue, corresponding to eigenvectors along the $x$-direction with angles of $\\approx \\frac{\\pi}{2}$ radians ($90$ degrees)."
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"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": [
"# Compute eigenvalues and eigenvectors of the structure tensor\n",
"val, vec = qim3d.processing.structure_tensor(NT, visualize = True, axis = 2) # Slicing in x-direction"
]
}
],
"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
}