-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathneurite_vector.m
40 lines (33 loc) · 911 Bytes
/
neurite_vector.m
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
function [U, V, theta] = neurite_vector(image, sigma)
%%
% INPUT:
% sigma: size of gaussian kernel
% image: image to process
% 0 - 1 double
image = double(image);
image = image ./ max(image(:));
gaussian_img = imgaussfilt(image, sigma, 'padding', 'replicate');
% second-order derivatives
[gx, gy] = gradient(gaussian_img);
[gxx, gxy] = gradient(gx);
[gyx, gyy] = gradient(gy);
[m, n] = size(image);
E = zeros(m, n);
U = E;
V = E;
for i = 1:m
for j = 1:n
Hessian = [gxx(i,j) gxy(i,j); gyx(i,j) gyy(i,j)];
[eigen_vector, eigen_value] = eig(Hessian, 'vector');
[~, index] = max(abs(eigen_value));
lambda_x = eigen_value(index);
E(i, j) = (lambda_x < 0) * lambda_x;
% eigenvector
U(i, j) = eigen_vector(1, 3 - index);
V(i, j) = eigen_vector(2, 3 - index);
end
end
% eigenvector .* eigenvalue
U = U .* E;
V = V .* E;
theta = atan2d(V, U);