brycefrank / pyfor

Tools for analyzing aerial point clouds of forest data.
MIT License
94 stars 19 forks source link

Tree Segmentation #53

Closed DavidEic closed 5 years ago

DavidEic commented 5 years ago

Hi Bryce!

Im somewhat new to python so please pardon my lack of knowledge. Im trying to do a crown segmentation of a park at my university as part of my master thesis. When I perform the watershed segmentation with:

segmentation = chm.watershed_seg(min_distance=4, threshold_abs=4).plot()

I get:

/peak.py:185: RuntimeWarning: invalid value encountered in greater
  mask &= image > max(thresholds)

Also I dont get any polygons on the output. Its just the CHM again. See figure..

When I run:

segmentation.segments[segmentation.segments["raster_val"] > 0]

I get:

'NoneType' object has no attribute 'segments'

To be honest, Im a bit clueless whats actually wrong here. If you could help me it would be really appreciated.

Thanks so much in advance! David

Figure_1

brycefrank commented 5 years ago

A blind guess, here. When you make your CHM, interpolate NANs.

Try:

chm = pc.chm(your_cell_size, interp_method="nearest")
brycefrank commented 5 years ago

Also, I will be extracting the watershed segmentation to a stand-alone package called treeseg in the coming months (very slowly, I have a lot of things going on). Keep an eye out for that.

brycefrank commented 5 years ago

Any thoughts, @DavidEic ? If it is solved, I will close.

DavidEic commented 5 years ago

Hi Bryce!

Thanks for the quick response and sorry for the late reply! Unfortunately it is still not solved..

This is the Code that Im using:

chm = pc.chm(0.25, interp_method = "cubic", pit_filter="median")
chm.plot()

#perform segmentation on CHM model - parameters should be improved and verified
crowns = chm.watershed_seg(min_distance=2, threshold_abs=2)

#Look at output with crown.segments['geometry'] or crown.segments['raster_val']

#and save to shapefile (best to store parameters in the filename so you know what you are doing and comparing)
final_crowns = crowns.segments[crowns.segments["raster_val"] > 0]
#best to filter some more, for example by area
NP_pc_crown_fname = '/home/bodo/Dropbox/CampusGolm-Lidar/NP_DEichhorn/NP_clip2_25cm_mindist2_thresh2_crowns.shp'

final_crowns.to_file(NP_pc_crown_fname)

I also tried interp_method=”nearest” but the same result..

Something goes definitely wrong with the peak local max function. I tried a different approach without pyfor and still get the same error when using peak local max..

David

Sent from Mailhttps://go.microsoft.com/fwlink/?LinkId=550986 for Windows 10


From: Bryce Frank notifications@github.com Sent: Saturday, May 11, 2019 5:12:49 PM To: brycefrank/pyfor Cc: DavidEic; Mention Subject: Re: [brycefrank/pyfor] Tree Segmentation (#53)

Any thoughts, @DavidEichttps://github.com/DavidEic ? If it is solved, I will close.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/brycefrank/pyfor/issues/53#issuecomment-491519259, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AL7X4K6GVAAJ6MXLNA7PQQLPU3O7DANCNFSM4HK3ROEA.

brycefrank commented 5 years ago

Interesting. Could you tell me the output of:

import numpy as np
print(np.sum(np.isnan(chm.array)))
brycefrank commented 5 years ago

Alternatively you can send me the tile if you like and I can take a bit closer look:

bfrank70@gmail.com

I can get to it tomorrow or wed. However, if it is an issue with the current segmentation stuff in pyfor I am deprecating those in the next update, and any fixes will be relegated to treeseg, which I should have up and running in a couple weeks.

brycefrank commented 5 years ago

I am not sure the issue, I was able to get a GeoDataFrame of segments with the following. Furthermore, my canopy height model does not show nans like yours does:

import pyfor
import numpy as np

pc = pyfor.cloud.Cloud('your_las.las')
chm = pc.chm(0.25, interp_method="nearest", pit_filter="median")

np.sum(np.isnan(chm.array))
>>> 0

chm.watershed_seg(min_distance=4, threshold_abs=4).segments

>>>
                                               geometry  raster_val
0     POLYGON ((364536.8912518311 5807589.840157471,...         0.0
1     POLYGON ((364785.1412518311 5807589.840157471,...         0.0
2     POLYGON ((364614.3912518311 5807589.840157471,...        22.0
...

I was not able to get it plotted, though.

A couple of ideas for you:

Try updating the packages in your environment:

conda update -n pyfor_env --all

and also update pyfor using the instructions in the README.