Detect tree height and crown width in numpy array

711 Views Asked by At

I have a 3D-LiDAR pointcoud repesenting a tree loaded into python with the laspy package. It is now stored as a numpy array. My purpose is to calculate the height of the tree by finding the point with the highest z-value and calculate the distance to the lowest z-value beneath it. So I imported the data via:

inFile = laspy.file.File("~/DATA/tree.las", mode='r')
point_records = inFile.points

At the moment, i calculated the height by:

min = inFile.header.min
max = inFile.header.max
zdist = max[2] -min[2]

The problem is that this way, i do not take slope in the terrain into account. How can i index the point that is exactly below the highest one?

1

There are 1 best solutions below

0
On

This is just a blind guess, because for a good answer, there is a lot of information missing.

Suppose we have an array of 3 points with (x,y,z)

A = [1,2,3]

B = [1,2,4]

C = [0,1,2].

We have identified point A as being the maximum in z and have its lat and long with

lat = 1
long = 2

Basically, you go through the list of point and filter out all the points, you want to look at, and take the minimal point. Below is a straightforward way to do that, using a for-loop. This is not ideal for speed. np.where() and fancy indexing can be used, to do that easier and faster, but this is more readable and adjustable:

import numpy as np
# This is some test data, with three data points
a = np.array([[1,2,3],[1,2,4],[0,1,2]])
# Now we define the lat and long we want to get
filter_x = 1
filter_y = 2
filtered_points = []
for i in range(a.shape[0]): # iterating through all points
    if a[i][0] == filter_x and a[i][1] == filter_y: 
        filtered_points.append(a[i][2]) # Append z of point to list
print min(filtered_points) # print minimum