To for application to very large remote sensing datasets, an approach to “Scalable image segmentation” presented in [1] using RSGISLib. In the paper a 30 m spatial resolution satellite mosaic of Australia was segmented by splitting into tiles, processing each tile on a separate node of a HPC, merging and then performing a second segmentation to remove artefacts at tile boundaries.
For a full description of the approach see section 5.3 of the open access paper (available to view online at http://www.mdpi.com/2072-4292/6/7/6111/htm).
A version of this approach, designed to be used on a single machine, is now available in RSGISLib through the performTiledSegmentation function. The function is called in a similar way to the existing runShepherdSegmentation function.
For instructions on installing the latest version of RSGISLib see this post, skipping to section 7 if you already have Linux or OS X installed.
The code below presents an example of applying either the tiled or standard segmentation through the use of a command line flag:
#!/usr/bin/env python """ Apply segmentation to image """ from __future__ import print_function import argparse import shutil import sys import tempfile from rsgislib.segmentation import tiledsegsingle from rsgislib.segmentation import segutils # Set values for clustering NUM_CLUSTERS = 60 MIN_PIXELS = 100 DIST_THRESHOLD = 100 # Set values for tiles segmentation TILE_WIDTH = 2000 TILE_HEIGHT = 2000 parser = argparse.ArgumentParser() parser.add_argument("inputimage", nargs=1, type=str, help="Input Image") parser.add_argument("outputclumps", nargs=1, type=str, help="Output clumps") parser.add_argument("--tiled", default=False, action="store_true", help="Use tiled segmentation") args = parser.parse_args() # Make temp directory for intermediate files temp_dir = tempfile.mkdtemp(prefix='rsgislib_seg_') if args.tiled: # If requested run tiled segmentation tiledsegsingle.performTiledSegmentation(args.inputimage[0], args.outputclumps[0], tmpDIR=temp_dir, tileWidth=TILE_WIDTH, tileHeight=TILE_HEIGHT, validDataThreshold=0.3, numClusters=NUM_CLUSTERS, minPxls=MIN_PIXELS, distThres=DIST_THRESHOLD, sampling=100, kmMaxIter=200) else: # If not run standard segutils.runShepherdSegmentation(args.inputimage[0], args.outputclumps[0], tmpath=temp_dir, numClusters=NUM_CLUSTERS, minPxls=MIN_PIXELS, distThres=DIST_THRESHOLD, sampling=100, kmMaxIter=200) shutil.rmtree(temp_dir)
Note, script edited for post – full version available from GitHub.
[1] Clewley, D.; Bunting, P.; Shepherd, J.; Gillingham, S.; Flood, N.; Dymond, J.; Lucas, R.; Armston, J.; Moghaddam, M. A Python-Based Open Source System for Geographic Object-Based Image Analysis (GEOBIA) Utilizing Raster Attribute Tables. Remote Sensing 2014, 6, 6111-6135. http://www.mdpi.com/2072-4292/6/7/6111