Statistics

Synthèse

Calculates statistics for each cell of an image based on a defined focal neighborhood.

Discussion

For more information about the methods and band orders used with this function, see the Statistics raster function.

The referenced raster dataset for the raster object is temporary. To make it permanent, you can call the raster object's save method.

Syntaxe

Statistics (raster, kernel_columns, kernel_rows, stat_type, {fill_no_data_only})
ParamètreExplicationType de données
raster

The input raster on which to perform focal statistics.

Raster
kernel_columns

The number of pixel columns to use in your focal neighborhood dimension.

(La valeur par défaut est 3)

Integer
kernel_rows

The number of pixel rows to use in your focal neighborhood dimension.

(La valeur par défaut est 3)

Integer
stat_type

Specify the type of statistics to calculate.

  • max Calculates the maximum value of the pixels within the neighborhood.
  • mean Calculates the average value of the pixels within the neighborhood. This is the default.
  • min Calculates the minimum value of the pixels within the neighborhood.
  • standarddeviationCalculates the standard deviation value of the pixels within the neighborhood.
  • medianCalculates the median value of the pixels within the neighborhood.
  • majority Calculates the majority value, or the value that occurs most frequently, of the pixels within the neighborhood.
  • minority Calculates the minority value, or the value that occurs least frequently, of the pixels within the neighborhood.

(La valeur par défaut est None)

String
fill_no_data_only

Specify whether NoData values are ignored in the analysis.

  • True—Fills NoData pixels only. This is the default.
  • False—NoData pixels will not be filled.

(La valeur par défaut est False)

Boolean
Valeur renvoyée
Type de donnéesExplication
Raster

The output raster.

Exemple de code

Statistics example

Fills in NoData values with the majority value in a 5 by 5 neighborhood for categorical data.

from arcpy.ia import *
LandCover_filled = arcpy.ia.Statistics("LandCover.tif", 5, 5, "majority", True)
LandCover_filles.save("LandCover_majority_5_by_5.tif")
Statistics example

Smooths an elevation raster in a 3 by 3 neighborhood using mean value.


import arcpy
from arcpy import env
from arcpy.ia import *

# Set environment settings
env.workspace = "C:/statistics_example/data"

# Set local variables
inRaster = "elevation.tif"
kernel_columns=3
kernel_rows=3
stat_type="Mean"
fill_no_data_only = False

# for each pixel, calculate the average value of pixels within its neighborhood. the neighborhood size is 5x5
output = Statistics(imagePath1, kernel_columns, kernel_rows, stat_type, fill_no_data_only)
output.save("statistics_mean_5_by_5.tif")