Volume Cartographer 2.27.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages
StructureTensor.hpp
Go to the documentation of this file.
1
7#pragma once
8
9#include <cstdint>
10
11#include <opencv2/core.hpp>
12
15
16namespace volcart
17{
19using EigenValue = double;
20
22using EigenVector = cv::Vec3d;
23
25using EigenPairs = std::array<std::pair<EigenValue, EigenVector>, 3>;
26
28using StructureTensor = cv::Matx33d;
29
31static const auto ZERO_STRUCTURE_TENSOR =
32 StructureTensor(0, 0, 0, 0, 0, 0, 0, 0, 0);
33
52 const Volume::Pointer& volume,
53 int vx,
54 int vy,
55 int vz,
56 int radius = 1,
57 int kernelSize = 3);
58
61 const Volume::Pointer& volume,
62 const cv::Vec3i& index,
63 int radius = 1,
64 int kernelSize = 3);
65
75 const Volume::Pointer& volume,
76 double vx,
77 double vy,
78 double vz,
79 int radius = 1,
80 int kernelSize = 3);
81
84 const Volume::Pointer& volume,
85 const cv::Vec3d& index,
86 int radius = 1,
87 int kernelSize = 3);
88
96 const Volume::Pointer& volume,
97 int x,
98 int y,
99 int z,
100 int radius = 1,
101 int kernelSize = 3);
102
105 const Volume::Pointer& volume,
106 const cv::Vec3i& index,
107 int radius = 1,
108 int kernelSize = 3);
109
120 const Volume::Pointer& volume,
121 double x,
122 double y,
123 double z,
124 int radius = 1,
125 int kernelSize = 3);
126
129 const Volume::Pointer& volume,
130 const cv::Vec3d& index,
131 int radius = 1,
132 int kernelSize = 3);
133
141template <typename DType>
143 const Volume::Pointer& volume,
144 const cv::Vec3i& center,
145 std::int32_t rx,
146 std::int32_t ry,
147 std::int32_t rz)
148{
149 Tensor3D<DType> v(2 * rx + 1, 2 * ry + 1, 2 * rz + 1);
150 for (std::int32_t k = center(2) - rz, c = 0; k <= center(2) + rz;
151 ++k, ++c) {
152 for (std::int32_t j = center(1) - ry, b = 0; j <= center(1) + ry;
153 ++j, ++b) {
154 for (std::int32_t i = center(0) - rx, a = 0; i <= center(0) + rx;
155 ++i, ++a) {
156 v(a, b, c) = DType(volume->intensityAt(i, j, k));
157 }
158 }
159 }
160
161 return v;
162}
163
169template <typename DType>
171 const Volume::Pointer& volume,
172 const cv::Vec3d& center,
173 int rx,
174 int ry,
175 int rz,
176 const cv::Vec3d& xvec = {1, 0, 0},
177 const cv::Vec3d& yvec = {0, 1, 0},
178 const cv::Vec3d& zvec = {0, 0, 1})
179{
180 Tensor3D<DType> v(2 * rx + 1, 2 * ry + 1, 2 * rz + 1);
181 for (int c = 0; c < 2 * rz + 1; ++c) {
182 for (int b = 0; b < 2 * ry + 1; ++b) {
183 for (int a = 0; a < 2 * rx + 1; ++a) {
184 auto xOffset = -rx + a;
185 auto yOffset = -ry + b;
186 auto zOffset = -rz + c;
187 auto p = center + (xvec * xOffset) + (yvec * yOffset) +
188 (zvec * zOffset);
189 v(a, b, c) = DType(volume->interpolateAt(p));
190 }
191 }
192 }
193
194 return v;
195}
196} // namespace volcart
A 3rd-order tensor object.
Definition: Tensor3D.hpp:28
std::shared_ptr< Volume > Pointer
Definition: Volume.hpp:42
Volume Cartographer library
StructureTensor ComputeVoxelStructureTensor(const Volume::Pointer &volume, int vx, int vy, int vz, int radius=1, int kernelSize=3)
Compute the structure tensor for a voxel position.
double EigenValue
StructureTensor ComputeSubvoxelStructureTensor(const Volume::Pointer &volume, double vx, double vy, double vz, int radius=1, int kernelSize=3)
Compute the structure tensor for a subvoxel position.
static const auto ZERO_STRUCTURE_TENSOR
Tensor3D< DType > ComputeVoxelNeighbors(const Volume::Pointer &volume, const cv::Vec3i &center, std::int32_t rx, std::int32_t ry, std::int32_t rz)
Get an axis-aligned cuboid subvolume centered on a voxel.
EigenPairs ComputeVoxelEigenPairs(const Volume::Pointer &volume, int x, int y, int z, int radius=1, int kernelSize=3)
Compute the eigenvalues and eigenvectors from the structure tensor for a voxel position.
std::array< std::pair< EigenValue, EigenVector >, 3 > EigenPairs
cv::Matx33d StructureTensor
Tensor3D< DType > ComputeSubvoxelNeighbors(const Volume::Pointer &volume, const cv::Vec3d &center, int rx, int ry, int rz, const cv::Vec3d &xvec={1, 0, 0}, const cv::Vec3d &yvec={0, 1, 0}, const cv::Vec3d &zvec={0, 0, 1})
Get an axis-aligned cuboid subvolume centered on a subvoxel.
cv::Vec3d EigenVector
EigenPairs ComputeSubvoxelEigenPairs(const Volume::Pointer &volume, double x, double y, double z, int radius=1, int kernelSize=3)
Compute the eigenvalues and eigenvectors from the structure tensor for a subvoxel position.