jblindsay / whitebox-tools

An advanced geospatial data analysis platform
https://www.whiteboxgeo.com/
MIT License
945 stars 161 forks source link

Bug with IndividualTreeDetection detecting trees very close together #388

Open korotuharry opened 10 months ago

korotuharry commented 10 months ago

I noticed this bug when trying to detect tree tops within the following height-normalized las file: https://drive.google.com/file/d/13wc6oy8EogL4azWHSwyU8VMDUFldfjsw/view?usp=sharing.

The following code was run using the whitebox Python package: wbt.individual_tree_detection( i='tree_points.las', output='tree_tops.shp', min_search_radius=0.1224*2+0.3043, min_height=2, max_search_radius=0.1224*50+0.3043, max_height=50, only_use_veg=False, )

The tree top points when viewed on QGIS show two pairs of really close points near the top and top left of the plot. The points in each pair have the same height, with both pairs being around 21 m tall. At this height, with the formula used, the search radius should be 3 m but the points in each pair are about 0.3 m apart. image

Running the equivalent process using lidR's locate_trees method, I get the same results except that there is no second point in the pairs spotted using whitebox, leading me to believe that this is a bug. A fix would be greatly appreciated!

Izius commented 9 months ago

Hi! I am using the same tool right now. How can i come in contact with you to discuss choices of parameters and overall results. Reply would be greatly appreciated.

korotuharry commented 9 months ago

Hi! I am using the same tool right now. How can i come in contact with you to discuss choices of parameters and overall results. Reply would be greatly appreciated.

I don't believe there's a standardized approach to choosing parameters - it's likely that the choice of window size needs to be tuned to each particular case for optimal results. Search window radius is related to crown radius in some ways so in the example I provided above, the equation I used was derived by plotting crown radius vs tree height of all trees in the Tallo database located within Canada. The results were not great though.

Izius commented 9 months ago

Isn't your min and max search radius around 0.5 m and 5 m respectively? Maybe that's why you get two very close points (you said around 0.3 m). Maybe try plotting identified points and raw LIDAR data to see what is really going on. Today i discovered that for high trees this function is doing okay but in my case the problem is low vegetation. My LIDAR data is also not very well classified.

Izius commented 9 months ago

To add: for higher trees I get okay identification meaning that there are no "double trees" like in your case.

korotuharry commented 9 months ago

Have you attempted to use the data I provided? Looking at one case where I'm detecting two tree tops about 0.13 m apart both with a height of 22.87 m, I'm guessing that the reason for the doubling of tree tops is because the heights are identical. If the algorithm defines a local maximum as a point that has a height greater than or equal to the points around it, this could explain the issue. In this case, the fix could be as simple as changing the "greater than or equal" to just "greater than". I can't verify this because the code is not available though.