Skip to content
GitLab
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
6ca0ca5f
Commit
6ca0ca5f
authored
Jul 26, 2020
by
Jean-Yves TINEVEZ
Browse files
mesh_to_heightmap: Create a height-map from a mesh.
Brute force, thanks to the power of linear scattered interpolant.
parent
9042b518
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/@deproj/deproj.m
View file @
6ca0ca5f
...
...
@@ -131,7 +131,8 @@ classdef deproj
% Read a PLY file.
[
V
,
F
,
comments
]
=
ply_read
(
file_path
)
% Create a height-map from a mesh.
[
H
,
min_y
,
min_x
]
=
mesh_to_heightmap
(
V
,
pixel_size
)
end
...
...
@@ -144,6 +145,7 @@ classdef deproj
% Returns the cells from a BW image with ridges.
[
objects
,
junction_graph
]
=
mask_to_objects
(
I
,
downsample
)
end
end
src/@deproj/mesh_to_heightmap.m
0 → 100644
View file @
6ca0ca5f
function
[
H
,
min_y
,
min_x
]
=
mesh_to_heightmap
(
V
,
pixel_size
)
%MESH_TO_HEIGHTMAP Create a height-map from a mesh.
% Of course there are plenty of restriction on the mesh for this to be
% valid. Mainly: we need the mesh to be so that there is only 1 Z for each
% X, Y couple. Secondly, the X and Y coordinates need to be positive.
% Convert to pixel-coordinates.
x
=
V
(
:,
1
);
y
=
V
(
:,
2
);
xp
=
x
/
pixel_size
;
yp
=
y
/
pixel_size
;
z
=
V
(
:,
3
)
-
min
(
V
(
:,
3
)
);
% Allocate target image.
max_x
=
1
+
ceil
(
max
(
xp
)
);
max_y
=
1
+
ceil
(
max
(
yp
)
);
min_x
=
1
+
floor
(
min
(
xp
)
);
min_y
=
1
+
floor
(
min
(
yp
)
);
% Interpolate.
si
=
scatteredInterpolant
(
xp
,
yp
,
z
,
'linear'
,
'none'
);
% Create elevation on the the grid.
[
X
,
Y
]
=
meshgrid
(
min_x
:
max_x
,
min_y
:
max_y
);
z_im
=
si
(
X
(:),
Y
(:)
);
z_im
(
isnan
(
z_im
)
)
=
0.
;
H
=
reshape
(
z_im
'
,
[
(
max_y
-
min_y
+
1
)
(
max_x
-
min_x
+
1
)
]
);
end
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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