Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
IAH public
DeProj
Commits
5d9ae4db
Commit
5d9ae4db
authored
Jul 16, 2020
by
Jean-Yves TINEVEZ
Browse files
Externalize curvature calculation and put the right units.
parent
d0cd038e
Changes
4
Hide whitespace changes
Inline
Side-by-side
src/@deproj/compute_curvatures.m
0 → 100644
View file @
5d9ae4db
function
[
curvMean
,
curvGauss
,
curvK1
,
curvK2
]
=
compute_curvatures
(
H
,
object_scale
,
pixel_size
,
voxel_depth
,
invert_z
)
%COMPUTE_CURVATURES Compute local curvature from the smoothed height-map.
% Ref: http://users.vcnet.com/simonp/curvature.pdf
if
nargin
<
5
invert_z
=
false
;
end
if
nargin
<
4
voxel_depth
=
1
;
end
if
nargin
<
3
pixel_size
=
1
;
end
if
nargin
>=
2
&&
~
isnan
(
object_scale
)
&&
~
isempty
(
object_scale
)
% We need to smooth the height-map over the scale of several cells.
Hs
=
imgaussfilt
(
H
,
3
*
object_scale
);
else
Hs
=
H
;
end
% Physical units.
Hs
=
Hs
*
voxel_depth
;
if
invert_z
Hs
=
-
Hs
;
end
[
Hx
,
Hy
]
=
gradient
(
Hs
,
pixel_size
);
[
Hxx
,
Hxy
]
=
gradient
(
Hx
,
pixel_size
);
[
~
,
Hyy
]
=
gradient
(
Hy
,
pixel_size
);
% Gaussian curvature.
Nk
=
(
1.
+
Hx
.^
2
+
Hy
.^
2
);
curvGauss
=
(
Hxx
.*
Hyy
-
Hxy
.^
2
)
.
/
(
Nk
.^
2
);
% Mean curvature.
Dk1
=
(
1.
+
Hx
.^
2
)
.*
Hyy
;
Dk2
=
(
1.
+
Hy
.^
2
)
.*
Hxx
;
Dk3
=
-
2.
*
Hx
.*
Hy
.*
Hxy
;
curvMean
=
(
Dk1
+
Dk2
+
Dk3
)
.
/
(
2
*
Nk
.^
1.5
);
% Principle curvatures.
curvK1
=
curvMean
+
sqrt
(
curvMean
.*
curvMean
-
curvGauss
);
curvK2
=
curvMean
-
sqrt
(
curvMean
.*
curvMean
-
curvGauss
);
end
src/@deproj/deproj.m
View file @
5d9ae4db
...
...
@@ -87,6 +87,10 @@ classdef deproj
% Returns the seismic colormap.
cmap
=
cmap_seismic
();
% Compute local curvature from the smoothed height-map.
[
curvMean
,
curvGauss
,
curvK1
,
curvK2
]
=
compute_curvatures
(
H
,
object_scale
,
pixel_size
,
voxel_depth
,
invert_z
)
end
%% Private static methods: utilities.
...
...
src/@deproj/from_heightmap.m
View file @
5d9ae4db
...
...
@@ -139,28 +139,12 @@ function obj = from_heightmap( ...
% Ref: http://users.vcnet.com/simonp/curvature.pdf
fprintf
(
'Compuing tissue local curvature.\n'
)
% We need to smooth the height-map over the scale of several cells.
Hs2
=
imgaussfilt
(
Hs1
,
3
*
object_scale
);
if
invert_z
Hs2
=
-
Hs2
;
end
[
Hx
,
Hy
]
=
gradient
(
Hs2
);
[
Hxx
,
Hxy
]
=
gradient
(
Hx
);
[
~
,
Hyy
]
=
gradient
(
Hy
);
% Gaussian curvature.
Nk
=
(
1.
+
Hx
.^
2
+
Hy
.^
2
);
curvGauss
=
(
Hxx
.*
Hyy
-
Hxy
.^
2
)
.
/
(
Nk
.^
2
);
% Mean curvature.
Dk1
=
(
1.
+
Hx
.^
2
)
.*
Hyy
;
Dk2
=
(
1.
+
Hy
.^
2
)
.*
Hxx
;
Dk3
=
-
2.
*
Hx
.*
Hy
.*
Hxy
;
curvMean
=
(
Dk1
+
Dk2
+
Dk3
)
.
/
(
2
*
Nk
.^
1.5
);
% Principle curvatures.
curvK1
=
curvMean
+
sqrt
(
curvMean
.*
curvMean
-
curvGauss
);
curvK2
=
curvMean
-
sqrt
(
curvMean
.*
curvMean
-
curvGauss
);
[
curvMean
,
curvGauss
,
curvK1
,
curvK2
]
=
deproj
.
compute_curvatures
(
...
Hs1
,
...
object_scale
,
...
pixel_size
,
...
voxel_depth
,
...
invert_z
);
%% Create epicell instances.
...
...
src/@deproj/plot_curvatures.m
View file @
5d9ae4db
...
...
@@ -43,7 +43,8 @@ function [ hf, ax1, ax2, ax3 ] = plot_curvatures( obj, scale_bar_length )
colormap
(
ax1
,
cmap
)
colormap
(
ax2
,
cmap
)
colormap
(
ax3
,
cmap
)
colorbar
(
ax3
,
'Location'
,
'EastOutside'
)
c
=
colorbar
(
ax3
,
'Location'
,
'EastOutside'
);
c
.
Label
.
String
=
sprintf
(
'Curvature (1/%s)'
,
obj
.
units
);
add_plot_scalebar
(
obj
,
scale_bar_length
,
ax3
);
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment