Skip to content
Snippets Groups Projects
Commit 6ca0ca5f authored by Jean-Yves TINEVEZ's avatar 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
No related branches found
No related tags found
1 merge request!9Rework the whole code for the upcoming publication.
...@@ -131,7 +131,8 @@ classdef deproj ...@@ -131,7 +131,8 @@ classdef deproj
% Read a PLY file. % Read a PLY file.
[ V, F, comments ] = ply_read( file_path ) [ 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 end
...@@ -144,6 +145,7 @@ classdef deproj ...@@ -144,6 +145,7 @@ classdef deproj
% Returns the cells from a BW image with ridges. % Returns the cells from a BW image with ridges.
[ objects, junction_graph ] = mask_to_objects( I, downsample ) [ objects, junction_graph ] = mask_to_objects( I, downsample )
end end
end end
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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment