Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
{
"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
}