diff --git a/README.md b/README.md new file mode 100644 index 0000000000000000000000000000000000000000..687e6c04afd53cd4e6556ef342ddd51d6d4e0565 --- /dev/null +++ b/README.md @@ -0,0 +1,97 @@ +# Structure Tensor + +Simple MATLAB package for computing structure tensors for 3D images. +Uses GPU block processing for high performance. + + + +## Installation + +Simply copy the `structuretensor` directory to you project. + +Then call `addpath structuretensor` in MATLAB. + + + +## Examples +**Simple example**: just get the eigenvalues and eigenvectors. +```matlab +addpath structuretensor + +% Make simple volume with one rod aligned with the Y-axis. +vol = zeros(128, 128, 128); +vol(60:70, :, 60:70) = 1; + +% Set structure tensor parameters. +sigma = 2; +rho = 4; + +% Compute structure tensor eigenvalues and eigenvectors. +% By default, the function uses the GPU if one is available. +% See also help StructureTensorEig3 for more info. +[E, X, Y, Z] = StructureTensorEig3(vol, sigma, rho,... + 'BlockSize', 64,... % Use 64x64x64 blocks. Can also give block as [W,H,D]. + 'Verbose', true); % Print a loadbar to show progress. + +% Show smallest eigenvector in the middle of the volume. +% Notice it is aligned with the Y-axis. +disp([X{1}(65,65,65), Y{1}(65,65,65), Z{1}(65,65,65)]); +``` + +**Only compute the smallest eigenvector.** This saves a lot of time and memory. Since the smallest eigenvector gives the local orientation it is usually the only one we care about. + +```matlab +addpath structuretensor + +% Make simple volume with one rod aligned with the Y-axis. +vol = zeros(128, 128, 128); +vol(60:70, :, 60:70) = 1; + +% Set structure tensor parameters. +sigma = 2; +rho = 4; + +% Compute structure tensor eigenvalues and eigenvectors. +% By default, the function uses the GPU if one is available. +% See also help StructureTensorEig3 for more info. +[E, X, Y, Z] = StructureTensorEig3(vol, sigma, rho,... + 'BlockSize', 64,... % Use 64x64x64 blocks. Can also give block as [W,H,D]. + 'Verbose', true,... % Print a loadbar to show progress. + 'NumEigVecs', 1); % Only return 1 eigenvector (the smallest). + +% Show smallest eigenvector in the middle of the volume. +% Notice it is aligned with the Y-axis. +disp([X{1}(65,65,65), Y{1}(65,65,65), Z{1}(65,65,65)]); +``` + +**Compute both the structure tensor components and eigenvectors/values**. +```matlab +addpath structuretensor + +% Make simple volume with one rod aligned with the Y-axis. +vol = zeros(128, 128, 128); +vol(60:70, :, 60:70) = 1; + +% Set structure tensor parameters. +sigma = 2; +rho = 4; + +% Compute structure tensor components. +% By default, the function uses the GPU if one is available. +% See also help StructureTensor3 for more info. +[T11, T22, T33, T12, T13, T23] = StructureTensor3(vol, sigma, rho,... + 'BlockSize', 64,... % Use 64x64x64 blocks. Can also give block as [W,H,D]. + 'Verbose', true); % Print a loadbar to show progress. + +% Compute structure tensor eigenvalues and eigenvectors. +% By default, the function uses the GPU if one is available. +% See also help EigRealSymm3 for more info. +[E, X, Y, Z] = EigRealSymm3(T11, T22, T33, T12, T13, T23,... + 'BlockSize', 64,... % Use 64x64x64 blocks. Can also give block as [W,H,D]. + 'Verbose', true); % Print a loadbar to show progress. + +% Show smallest eigenvector in the middle of the volume. +% Notice it is aligned with the Y-axis. +disp([X{1}(65,65,65), Y{1}(65,65,65), Z{1}(65,65,65)]); +``` +