1

I'm using arcpy.sa.SegmentMeanShift() to produce a segmented raster in ArcGIS 10.7.1.

The segments in the output raster have values outside the range of values (1 to 248) in the input raster (-22 to 92)!

The new range of values in looks like a fit for stretched values (0-255). But I need the original values, not the stretched values.

How can I get the (mean) original values in my segmented raster?

I have tried arcpy.SetRasterProperties_management(inputRaster, data_type="PROCESSED"), but this has not helped.

UPDATE: ESRI Rubbish...?

Turns out the problem doesn't always happen. I've changed my output to be in a geodatabase, and the problem went away! I haven't tested conclusively if this is why the problem went away... to busy moving on to other things.

1 Answer 1

0

I have worked around this problem successfully by converting the values back to the unstretched values, using the formula for converting a number in one range to a number in another range as per, https://stackoverflow.com/questions/929103/convert-a-number-range-to-another-range-maintaining-ratio :

NewValue = (((OldValue - OldMin) * (NewMax - NewMin)) / (OldMax - OldMin)) + NewMin

But since I know that the stretched range (oldMin to oldMax) is 0-255, I can simplify the formula making it a little more specific to this range:

segRaster = ((segRaster * (newMax - newMin)) / 255) + newMin

This appears to be producing the correct results for me.

I'd still be interested to hear if there is any way to get the arcpy.sa.SegmentMeanShift() to produce un-stretched output.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.