Skip to main content

Gradient

Краткая информация

Вычисляет градиент по x, y, x,y или заданному измерению.

Обсуждение

Функция Gradient работает на одноканальных входных данных. Если входные данные – многоканальное изображение, будет использоваться первый канал. Используйте функцию ExtractBand, чтобы задать требуемый канал.

Для многомерных входных данных, содержащих несколько переменных, будут обработаны все переменные. Если переменная не содержит указанного параметра gradient_dimension, она будет игнорироваться. Используйте функцию Многомерный фильтр, чтобы выбрать необходимые переменные.

Функцию Многомерный фильтр также можно использовать для определения диапазона измерений, к которому применяется функция.

В следующей таблице приведены уравнения для различных расчетов градиента:

Тип градиента

Уравнение

Градиент Х

\((правый \space пиксель \space – \space текущий \space пиксель) \space / \space Единица \space знаменателя\)

Градиент Y

\((нижний \space пиксель \space – \space текущий \space пиксель) \space / \space Единица \space знаменателя\)

Градиент для измерения

\((следующий \space срез \space – \space текущий \space срез) \space / \space Единица \space знаменателя\)

Синтаксис

Gradient(raster, {gradient_dimension}, {denominator_unit})

Параметр Объяснение Тип данных

raster

The input raster or list of rasters.

Raster

gradient_dimension

The available dimensions for which the gradient will be calculated.

For nonmultidimensional input, available dimension options are X, Y, and XY.

For multidimensional input, available dimension options are X, Y, XY, and all dimensions available in the data, including time (StdTime). If there are two or more dimensions, the gradient will be calculated on the gradient dimension for all slices in the available dimensions.

The XY option outputs a 2-band raster in which band 1 represents the gradient along the x-dimension, and band 2 represents the gradient along the y-dimension.

(Значение по умолчанию — X)

String

denominator_unit

The unit of the gradient denominator. The unit depends on the gradient_dimension argument value.

The following options are available for X, Y, and XY:

  • DEFAULT—The output will be the difference between adjacent cells. This is the default.

  • CELLSIZE—The output will be the difference between adjacent cells divided by the cell size of the input. The output unit will be the same as the unit of the x,y coordinates of the input. If the data is in a geographic coordinate system, it will be converted to meters.

The following options are available for StdTime:

  • DEFAULT—The output will be the difference between adjacent slices. This is the default.

  • PER_HOUR—The output will be the difference between adjacent slices divided by the difference between the time values and converted to the per-hour rate.

  • PER_DAY—The output will be the difference between adjacent slices divided by the difference between their time values and converted to the per-day rate.

  • PER_MONTH—The output will be the difference between adjacent slices divided by the difference between their time values and converted to the per-month rate.

  • PER_YEAR—The output will be the difference between adjacent slices divided by the difference between their time values and converted to the per-year rate.

  • PER_DECADE—The output will be the difference between adjacent slices divided by the difference between their time values and converted to the per-decade rate.

The following options are available for dimensions other than time dimensions:

  • DEFAULT—The output will be the difference between adjacent slices. This is the default.

  • DIMENSION_INTERVAL—The output will be the difference between adjacent slices divided by the difference between their dimension values.

(Значение по умолчанию — DEFAULT)

String

Возвращаемое значение

Тип данных Объяснение

Raster

Выходной растр.

Пример кода

Gradient, пример 1

Вычислите градиент по измерениям x и y на изображении Landsat.

# Import system modules
import arcpy
from arcpy.ia import *
arcpy.ia.Gradient(raster, gradient_dimension, denominator_unit)

# Set local variables
input_raster = in_multidimensional_raster = "C:/data/landsat.crf"
gradient_dimension = "XY"
denominator_unit = "Cellsize"
# Apply Gradient function
gradient_raster = arcpy.ia.Gradient (raster, gradient_dimension, denominator_unit)
# Save the output
gradient_raster.save("C:/output/landsat_xy_gradient.crf")
Gradient, пример 2

В этом примере вычисляется градиент вдоль StdTime временных рядов NDVI.

# Import system modules
import arcpy
from arcpy.ia import *
arcpy.ia.Gradient (raster, gradient_dimension, denominator_unit)

# Set local variables
input_raster = in_multidimensional_raster = "C:/data/ndvi_time_series.crf"
gradient_dimension = "StdTime"
denominator_unit = "Per Year"
# Apply Gradient function
gradient_raster = arcpy.ia.Gradient (raster, gradient_dimension, denominator_unit)
# Save the output
gradient_raster.save("C:/output/ndvi_stdtime_gradient.crf")