Optimize feature extraction

36 views
Skip to first unread message

Vincenzo Fiozzo

unread,
Mar 24, 2020, 7:21:29 AM3/24/20
to RSGISLib Support

Hi, 
after repeating several tests with 'runShepherdSegmentation',I used the output to derive a shapefile to use with 'pixelStats2SHP' for feature extraction. Although everything works correctly, this last function requires a considerable processing time in my case, about two days. 
Could you kindly explain to me why it takes so long and if there is a way to optimize the timing. 

Thank you, I enclose the code I used.

Segmentation:

import rsgislib
from rsgislib.segmentation import segutils
import shutil

#input path
img
='/home/ubuntu/input/layer_stack.tif'
#output path
img_clump
='/home/ubuntu/output/output_raster.tif'
#mean path
img_mean
='/home/ubuntu/input/mean.tif'

segutils
.runShepherdSegmentation(img,img_clump,img_mean,gdalformat='GTiff',numClusters=500,minPxls=435,distThres=500,sampling=500,kmMaxIter=500)


Feature extraction:

import rsgislib
from rsgislib import zonalstats

#path input shp
inputimage
='/home/ubuntu/input/layer_stack.tif'
#path input shp
inputvector
='/home/ubuntu/output/shp_mask.shp'
#path output shp + fe
outputvector
='/home/ubuntu/output/output_fe.shp'

#pixelStats2SHP
zonalattributes
= zonalstats.ZonalAttributes(calcCount=False, calcMin=False, calcMax=False, calcMean=True, calcStdDev=True, calcMode=False, calcSum=False)

rsgislib
.zonalstats.pixelStats2SHP(inputimage, inputvector, outputvector, zonalattributes, True ,True, True, zonalstats.METHOD_POLYCONTAINSPIXELCENTER)

Daniel Clewley

unread,
Mar 26, 2020, 3:33:56 PM3/26/20
to Vincenzo Fiozzo, RSGISLib Support
Hi Vincenzo,

Doing raster in vector statistics requires a lot of processing to calculate if a pixel is contained within a polygon. Doing it for lots of complicated polygons (as you are likely to get from the output of a segmentation) will take a long time, there isn’t really a way to get around this.

Is there any reason not to use the raster GIS tools in RSGISLib? These will be much faster and is the recommended way of doing object based classification in RSGISLib. The equivalent function is ratutils.populateImageStats.

Thanks,

Dan

--
You received this message because you are subscribed to the Google Groups "RSGISLib Support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rsgislib-suppo...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/rsgislib-support/e5a7b886-24c9-4624-bb38-43cf10bab8a9%40googlegroups.com.

Vincenzo Fiozzo

unread,
Mar 27, 2020, 7:30:00 AM3/27/20
to rsgislib...@googlegroups.com
Hi Dan, thanks for getting back to me.

For my analysis I need to get the statistics of the segmentation of each single field in a shapefile.
However I did further tests with the KEA format and following your advice using the function 'ratutils.populateImageStats', I noticed that the work seems to happen in a few seconds, but when I check the output '.kea' on QGIS this crashes. Is there any way to get these statistics in a shapefile?

Sincerely

Vincenzo
Reply all
Reply to author
Forward
0 new messages