-
Notifications
You must be signed in to change notification settings - Fork 0
/
reconLandslideDEM.m
102 lines (79 loc) · 3.56 KB
/
reconLandslideDEM.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
function [X, Y, Z, reconstructedZSmooth] = reconLandslideDEM(OrigindataResolution, gausscore, SCARFile, SMOOTHZoneFile, BATHYFile)
% Load the data
DATA = load(BATHYFile);
ScarShapedata = readmatrix(SCARFile);
% Extract X, Y, Z coordinates from the data
X = DATA(:, 1);
Y = DATA(:, 2);
Z = DATA(:, 3);
% Define the area boundaries
x_area_min = min(X);
x_area_max = max(X);
y_area_min = min(Y);
y_area_max = max(Y);
% Create a grid for interpolation
[xq, yq] = meshgrid(x_area_min:OrigindataResolution:x_area_max, y_area_min:OrigindataResolution:y_area_max);
zq = griddata(X, Y, Z, xq, yq, 'linear');
Z = zq(:);
% Reconstruct the landslide area
[X, Y, reconstructedZ, reconstructedZq] = reconstructProcess(xq, yq, zq, ScarShapedata);
% Apply Gaussian smoothing within the specified gauss zone
[X, Y, reconstructedZSmooth] = applyGaussianSmoothing(xq, yq, reconstructedZq, SMOOTHZoneFile, gausscore);
reconstructedZSmooth = reconstructedZSmooth - min(reconstructedZSmooth);
end
function [X, Y, reconstructedZ, reconstructedZq] = reconstructProcess(xq, yq, zq, ScarShapedata)
% Initialize cell arrays for storing coordinates
polygonsX = cell(1, size(ScarShapedata, 2)/2);
polygonsY = cell(1, size(ScarShapedata, 2)/2);
% Loop to separate X and Y coordinates and remove NaN
for i = 1:2:size(ScarShapedata, 2)
slideX = ScarShapedata(:, i);
slideY = ScarShapedata(:, i+1);
% Remove NaN values
slideX = slideX(~isnan(slideX));
slideY = slideY(~isnan(slideY));
% Store in cell arrays
polygonsX{(i+1)/2} = slideX;
polygonsY{(i+1)/2} = slideY;
end
% Initialize the cumulative mask as false for all grid points
cumulativeMask = false(size(xq));
% Loop through all polygons to update the cumulative mask
for i = 1:length(polygonsX)
% Check if points are inside the current polygon
[in, on] = inpolygon(xq, yq, polygonsX{i}, polygonsY{i});
mask = in | on; % Combine points inside and on the boundary
% Update the cumulative mask to include points inside or on this polygon
cumulativeMask = cumulativeMask | mask;
end
% Now cumulativeMask contains true for points inside any of the polygons
% Clip the DEM data using the mask
clippedZ = zq;
clippedZ(cumulativeMask) = NaN; % Set values inside the polygon to NaN
% % Interpolate over NaN values using griddata 'linear'
xq_valid = xq(~isnan(clippedZ));
yq_valid = yq(~isnan(clippedZ));
zq_valid = zq(~isnan(clippedZ));
reconstructedZq = griddata(xq_valid, yq_valid, zq_valid, xq, yq, 'linear');
X = xq(:);
Y = yq(:);
reconstructedZ = reconstructedZq(:);
end
function [X, Y, blurredZ] = applyGaussianSmoothing(xq, yq, zq, SMOOTHZoneFile, gausscore)
% Load Gaussian smoothing zone data
gaussData = readmatrix(SMOOTHZoneFile);
gaussX = gaussData(:, 1);
gaussY = gaussData(:, 2);
% Remove NaN values
gaussX = gaussX(~isnan(gaussX));
gaussY = gaussY(~isnan(gaussY));
% Identify points inside the gausszone
[in, on] = inpolygon(xq, yq, gaussX, gaussY);
mask = in | on; % Combine points inside and on the boundary
% Create a subset of original elevation data
z_blurred = imgaussfilt(zq, gausscore);
zq(mask) = z_blurred(mask);
X = xq(:);
Y = yq(:);
blurredZ = zq(:); % Flatten the array
end