Closed liamirwin closed 8 months ago
This is to keep 1 point per voxel. For n points per voxel your approach is good, sorting is required. You could mix your approach with mine.
keep_x_per_voxel = function(res = 1, x = "max")
{
x = match.arg(x, c("min", "max", "mean"))
x <- lazyeval::uq(x)
res <- lazyeval::uq(res)
f = function(las)
{
by <- lidR:::group_grid_3d(las$X, las$Y, las$Z, res)
if (x == "max") return(las@data[, .I[which.max(Z)], by = by]$V1)
if (x == "min") return(las@data[, .I[which.min(Z)], by = by]$V1)
if (x == "mean") return(las@data[, .I[which.min(abs(Z - mean(Z)))], by = by]$V1)
}
f <- plugin_decimate(f)
return(f)
}
library(lidR)
LASfile <- system.file("extdata", "Megaplot.laz", package="lidR")
las <- readLAS(LASfile, select = "xyz")
thinned1 <- decimate_points(las, keep_x_per_voxel(2, "max"))
plot(thinned1)
Hi JR,
It would be very useful to have the option to decimate a point cloud using voxels but with the added functionality where the user is able to select which point(s) are retained rather than retaining a random point for each voxel like is currently available. This is especially useful when trying to account for differences in point density across multitemporal acquisitions (see below).
Selecting the highest/lowest point, or mean Z point would be great. I am unsure how much more work it would be to code in the flexibility for the user to define which point they are keeping.
Here is my current approach, it is quite slow and relies on LAStools to attribute a voxel ID to each point
Step 1: compute and attribute voxel IDs to each point in the point cloud (using LAStools as I couldn't find a method with lidR)
Link to LAStools output LAZ file: https://drive.google.com/file/d/1re_PDVriFcvcPolURqmDhV1ppHMuabFC/view?usp=sharing
Step 2: Load voxel attributed LAS as data.table and retain desired points (highest n points)