Friday 5 August 2016

python - How to find the minimum pixel value within a region of interest?


I am working on a Python script for dark object subtraction, a radiometric correction method for remotely sensed data.To accomplish this, I need to find the minimum band pixel value of a waterbody within a region of interest (ROI) (screenshot). My initial thought was to create a polygon within a Landsat scene and use Zonal Statistics as Table to find the minimum value. However, I cannot easily call this minimum value later on in the script. Another thought was to convert the band to a numpy array and find the min value (excluding 0), although I am uncertain how to subset the array to my ROI. How can I find the minimum value using a region of interest so that I can easily call this value later on in the script?


enter image description here



Answer



Related to answer I gave to a similar question (determine min and max elevation ... within my current extent), I wonder if this would work:


import arcpy


# this sets extent to current display, you can instead set it to ROI polygon
arcpy.env.extent = arcpy.mapping.MapDocument.activeView.Extent

# for a multi-band raster, pay attention to the band index (last input)
arcpy.MakeRasterLayer_management("c:/temp/raster.tif", "rlayer", "#", arcpy.env.extent, "1")

# Get the geoprocessing result object
bandMinResult = arcpy.GetRasterProperties_management("rlayer", "MINIMUM")
# Get the elevation minimum value from geoprocessing result object
bandMinDN = elevMinResult.getOutput(0)

No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...