'change LAS points ID to a different cluster according to a distance test

I have a LAS file of an orchard and I'm trying to segment each individual tree by using 'segment_tree' function in {lidR} library. the algorithm which I'm using is dalponte2016.

segmented_trees_las_silva <- lidR::segment_trees(nlas_trees,
                             silva2016(chm,ttops, max_cr_factor = 1.2,
                             ID = "treeID"))

segmented_plot = plot(segmented_trees_las_silva, color = "treeID")
add_treetops3d(segmented_plot, ttops)

the function output is that each point gets an ID=n which represents if the point is part of the n tree. The results are quite good, but as you might see, I have some points which shift to different trees (shown in the figure with white arrows) and are associated with the wrong tree, in a different orchard row.

Tree segmentation plot. the red dots represent the treetops, black background represents the ground. white represents N/A points

I want to add the algorithm a feature that will reduce those errors and associate those points to a tree that is in the same row (row of the orchard in this case). I thought about kNN algorithm but sometimes the distance to the wrong centroid is shorter so that leaves me at a dead end.

Maybe it is possible to create a new attribute to the LAS file "ROW_ID" so that each "tree_ID" must fall in the same "ROW_ID".

any ideas on how to implement it?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source