Spatial Analyst's SegmentMeanShift tool fails in standalone script

3577
12
10-18-2016 12:45 PM
EvanBlaisdell
Occasional Contributor

In ArcMap 10.4, I can run the SegmentMeanShift tool (Segment Mean Shift—Help | ArcGIS for Desktop ) in the Python window, or from the ArcToolbox, just fine. 

However, when trying to run a standalone script incorporating the tool, I receive the ever-useful "Unexpected Error." 

I am using the standalone tool template as provided in the link above. My Spatial Analyst licenses are valid. I am not using the optional band indexes parameter.

# Import system modules
import arcpy
from arcpy.sa import *

# Set local variables
inRaster = r"Path:\blah\blah\master.img"
spectral_detail = "15"
spatial_detail = "15"
min_segment_size = "10"

# Check out the ArcGIS Spatial Analyst extension license
arcpy.CheckOutExtension("Spatial")

# Execute
seg_raster = SegmentMeanShift(inRaster, spectral_detail, spatial_detail, min_segment_size)

# Save the output
seg_raster.save(r"Path:\blah\blah\seg_test.img")

This is the error: 

File "C:\Program Files (x86)\ArcGIS\Desktop10.4\ArcPy\arcpy\sa\Functions.py", line 7783, in SegmentMeanShift
band_indexes)
File "C:\Program Files (x86)\ArcGIS\Desktop10.4\ArcPy\arcpy\sa\Utils.py", line 53, in swapper
result = wrapper(*args, **kwargs)
File "C:\Program Files (x86)\ArcGIS\Desktop10.4\ArcPy\arcpy\sa\Functions.py", line 7776, in Wrapper
band_indexes)
File "C:\Program Files (x86)\ArcGIS\Desktop10.4\ArcPy\arcpy\geoprocessing\_base.py", line 506, in <lambda>
return lambda *args: val(*gp_fixargs(args, True))
arcgisscripting.ExecuteError: ERROR 999998: Unexpected Error.
Failed to execute (SegmentMeanShift).

Again, it works fine within ArcMap. I should say I have gotten it to work in a standalone script before, with different spectral, spatial, and min_size parameters. If it's a problem with the inputs I don't know why it would work within ArcMap.

Any thoughts? Thanks.

0 Kudos
12 Replies
DanPatterson_Retired
MVP Emeritus

it takes 5... at least in the newer software versions, check your version help if arcmap 10.6 and Pro 2.1 isn't being used

SegmentMeanShift (in_raster, {spectral_detail}, {spatial_detail}, {min_segment_size}, {band_indexes})

http://pro.arcgis.com/en/pro-app/tool-reference/spatial-analyst/segment-mean-shift.htm

from the help

seg_raster = SegmentMeanShift("c:/test/moncton.tif", "15", "10", "20", "4 3 2")

NilsRatnaweera1
Occasional Contributor

Yes that's what the error says, it takes only 5 arguments. I had tried it since Yi Zou (ESRI employee?) had suggested it.

Were you able to resolve your issue? I have problems running SegmentMeanShift within a python IDE as well.

0 Kudos
DanPatterson_Retired
MVP Emeritus

I am just a humble observer and I didn't have the problem, I am pointing out the current requirements... if the software was an older version or from a different package, the parameters might differ.  It is obvious in your case that Yi's solution doesn't apply

0 Kudos