-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathcreateHeightMaps.m
52 lines (39 loc) · 1.39 KB
/
createHeightMaps.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
41
42
43
44
45
46
47
48
49
50
51
52
function [minMap,maxMap,heightMapCreationData] = ...
createHeightMaps(cloud,pixelSize)
%% Define grid over the cloud
[XY_indices,gridSize,xyMin,xyMax] = createOrthogonalGrid(cloud,pixelSize);
gridSize = fliplr(gridSize);
closingRadius = 3; % [pixels], radius of structuring element used for closing
%% Get z coordinates and set fill values
z = double(cloud.Location(:,3));
fillVal = nan;
%% Create min,max height-maps
minjmax_handle = @(x) minjmax(x);
minjmaxMap = ...
accumarray([XY_indices(:,2) XY_indices(:,1)],z,gridSize,minjmax_handle,fillVal);
minMap = real(minjmaxMap);
maxMap = imag(minjmaxMap);
% imshow(minMap,[])
% imshow(maxMap,[])
%% Identify which pixels need to be filled
dataMask = ~isnan(minMap);
% imshow(dataMask,[])
% close dataMask
se = strel('disk',closingRadius);
dataMask_closed = imclose(dataMask,se);
% imshow(dataMask_closed,[])
pixels2fill = dataMask_closed - dataMask == 1;
% imshow(pixels2fill,[])
%% Fill detected pixels (nearest neighbor interpolation)
[minMap,maxMap] = ...
fillPixels_NN(minMap,maxMap,dataMask,pixels2fill);
% imshow(minMap,[])
% imshow(maxMap,[])
minMap(isnan(minMap)) = inf;
maxMap(isnan(maxMap)) = -inf;
%% Set outputs
heightMapCreationData.gridSize = gridSize;
heightMapCreationData.xyMin = xyMin;
heightMapCreationData.xyMax = xyMax;
heightMapCreationData.XY_indices = XY_indices;
return