andrew-plowright / ForestTools

Detect and segment individual tree from remotely sensed data
63 stars 20 forks source link

Problem with winFun in TreeTopFinder #4

Closed QuirinH closed 6 years ago

QuirinH commented 6 years ago

Hi,

I am having trouble with the TreeTopFinder in ForestTools. The winFun function seems to result in oversized window sizes that give me back an error.

My code:

library(ForestTools) library(raster) raster <- raster("~/Desktop/FileName.tif") lin <- function(x){x * 0.05 + 0.6}

The data has the following specs:

raster class : RasterLayer dimensions : 167, 248, 41416 (nrow, ncol, ncell) resolution : 2.995115e-05, 2.991972e-05 (x, y) extent : -123.4957, -123.4882, 48.94425, 48.94925 (xmin, xmax, ymin, ymax) coord. ref. : +proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0 data source : /Users/name/Desktop/FileName.tif names : FileName values : 0.002187729, 33.21095 (min, max)

ttops <- TreeTopFinder(CHM = raster, winFun = lin, minHeight = 5, verbose = TRUE)

ttops <- TreeTopFinder(CHM = raster, winFun = lin, minHeight = 5, verbose = TRUE) Reading input raster Error in TreeTopFinder(CHM = raster, winFun = lin, : Input function for 'winFun' yields a window size of 200001, which is wider than 'maxWinDiameter'. Change input function or set 'maxWinDiameter' to a higher value (or to NULL).

I am not sure why the calculated values for window size a re so big. My max value in the data is 33.2. Thank you for your support!

Cheers, Quirin

andrew-plowright commented 6 years ago

Hi Quirin,

The function uses the resolution of the raster to figure out how many cells the window needs to cover. Since it can't know what unit the raster values are in, it assumes that they are the same as the map unit. The problem here is that your raster values are presumably in meters while your resolution is in degrees decimal.

Andrew

QuirinH commented 6 years ago

Hi Andrew,

Thank you so much for the quick reply! Stupid mistake on my side… It is running now.

Cheers, Quirin

Quirin Hohendorf

MSc student School of Environmental Studies, University of Victoria Faculty of Graduate Studies Council Representative

On Feb 4, 2018, at 9:32 PM, Andrew Plowright notifications@github.com wrote:

Hi Quirin,

The function uses the resolution of the raster to figure out how many cells the window needs to cover. Since it can't know what unit the raster values are in, it assumes that they are the same as the map unit. The problem here is that your raster values are presumably in meters while your resolution is in degrees decimal.

Andrew

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/AndyPL22/ForestTools/issues/4#issuecomment-362985969, or mute the thread https://github.com/notifications/unsubscribe-auth/AieMaGHXE4IncBQ7X1grWfJoUzNemZD3ks5tRpJ3gaJpZM4R46vw.

andrew-plowright commented 6 years ago

No problem Quirin, Good luck with your analysis

Tehn01 commented 3 years ago

Hi Andrew and Quiring

I am Having this error;Error in vwf(CHM = fri_chm, winFun = lin, minHeight = 2) : Input function for 'winFun' yields a window diameter of 119 cells, which is wider than the maximum allowable value in 'maxWinDiameter'. Change the 'winFun' function or set 'maxWinDiameter' to a higher value (or to NULL)

I think it is the same issue raised, but I am still a beginner and I am not sure how to rectify this.

This is the code; library(ForestTools) library(raster) library(rgdal) fri_chm <- raster("G:/MSc Thesis/UAV DATA/Resampling/chm/fri_chm.tif") plot(fri_chm, xlab = "", ylab = "", xaxt='n', yaxt = 'n') lin <- function(x){x * 0.05 + 0.6} ttops <- vwf(CHM = fri_chm, winFun = lin, minHeight = 2)

Please help!

QuirinH commented 3 years ago

Hi Tehn01,

I am citing Andrew from above: "The problem here is that your raster values are presumably in meters while your resolution is in degrees decimal." IT was a simple mistake on my end.

For my data it helped to change the dimension to degrees decimal if I remember correctly. I can did up my analysis if that doesn't help.

Good Luck!

andrew-plowright commented 3 years ago

Hi @Tehn01,

What @QuirinH said is indeed a common issue. Let's confirm: can you tell us what projection system your CHM is in?

Andrew

Tehn01 commented 3 years ago

Hi @QuirinH @andrew-plowright

Thank you for the feedback, and yes you were right. it was a projection issue. I however have a new inquiry today.

I managed to run the treetop detection and crowns segmentation, however the results are not convincing since most treetops and crowns are not tagged. Is there a way I can improve on the linear function of play around window size for better results?

Cheers!

andrew-plowright commented 3 years ago

@Tehn01 yes, the window size is dynamically set by the winFun argument, which takes a function that relates the CHM pixel value to the search window's radius.

The inventors of the algorithm discuss ways to calibrate the window function to specific forest structures: https://www.ingentaconnect.com/contentone/asprs/pers/2004/00000070/00000005/art00003?crawler=true