-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathR-3.6Segmentationcode
75 lines (59 loc) · 2.64 KB
/
R-3.6Segmentationcode
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
#print
library(lidR)
#if (!requireNamespace("BiocManager", quietly = TRUE))
# install.packages("BiocManager")
#BiocManager::install(version = "3.7")
#BiocManager::install("EBImage")
#las = readLAS("/home/rstudio/keys_work/keys/code/Example.las", select = "xyziar", filter = "-keep_first -drop_z_below_0")
#las = readLAS("/home/rstudio/keys_work/keys/code/NEON_D14_SRER_DP1_L090-1_2019091314_unclassified_point_cloud.laz")
las = readLAS("/home/rstudio/NEON_SRER_DP1.30003.001_2019/2019/FullSite/D14/2019_SRER_3/L1/DiscreteLidar/ClassifiedPointCloud/NEON_D14_SRER_DP1_501000_3519000_classified_point_cloud_colorized.laz")
#las = readLAS("/home/rstudio/NEON_SRER_DP1.30003.001_2019/2019/FullSite/D14/2019_SRER_3/L1/DiscreteLidar/ClassifiedPointCloud/NEON_D14_SRER_DP1_501000_3518000_classified_point_cloud_colorized.laz")
plot(las)
#finished
#second chunk
#las = lasground(las, csf())
#warning return number / number of returns not found. Data issue?
plot(las, color = "Classification")
#finished second chunk
#third chunk
las = lasnormalize(las, tin())#no issue
plot(las)
#finished third chunk
#fourth chunk
algo = pitfree(thresholds = c(0,10,20,30,40,50), subcircle = 0.2)
chm = grid_canopy(las, 0.5, algo)#error in proj4string(x) CRS object has comment which is lost in output. It seems to stop the top of the legend from rendering.
plot(chm, col = height.colors(50))
#finished fourth chunk
#fifth chunk
ker = matrix(1,3,3)
chm = focal(chm, w = ker, fun = median)
chm = focal(chm, w = ker, fun = median)
plot(chm, col = height.colors(50)) # check the image
#ignore previous error, the code still works with it. Still odd
#finished fifth chunk
#sixth chunk
algo = watershed(chm, th = 4)
las = lastrees(las, algo)
# remove points that are not assigned to a tree
#trees = filter(las, !is.na(treeID))
trees = lasfilter(las, !is.na(treeID))
plot(trees, color = "treeID", colorPalette = pastel.colors(100))
#Error, there were 50 or more warnings. Don't know why yet.
#finished sixth chunk
#seventh chunk
hulls = tree_hulls(las)#, func = .stdmetrics)
#Error in eval(bysub, x, parent.frame()) : object 'treeID' not found
spplot(hulls, "Z")
#object hulls not found, the previous code gets terminated. I think it is due to the 50+ warnings line.
#at this point, the plot is no longer going to run.
#finished 7th chunk
#eighth chunk
crowns = watershed(chm, th = 4)()
plot(crowns, col = pastel.colors(100))
#This piece of code basically creates the groundless crown system for the las. Looks like dots.
#ninth chunk
contour = rasterToPolygons(crowns, dissolve = TRUE)
plot(chm, col = height.colors(50))
plot(contour, add = T)
#this code adds the contour mapping to the crowns again.
#finished