RT_Convolution takes a raster column and a convolution kernel, and returns a raster column with the convolution kernel applied to each band of the input raster. Convolution is a spatial operation that applies a kernel (filter) to an input raster to produce an output raster where each pixel value is a weighted sum of its neighboring pixels.

RT_Convolution

You can specify one of the predefined kernels:

Kernel typeDescription
GradientGradient kernels can be used for directional gradient detection in 45-degree increments. Available kernels are:
  • gradient_east
  • gradient_north
  • gradient_north_east
  • gradient_north_west
  • gradient_south
  • gradient_west
LaplacianLaplacian kernels can be used for edge enhancement. They are commonly applied after smoothing to reduce sensitivity to noise. Available kernels are:
  • laplacian_3x3
  • laplacian_5x5
Line detectionLine detection kernels can be used for line detection in specific orientations. Better results may be achieved if smoothing is applied before edge detection. Available kernels are:
  • line_detect_horizontal
  • line_detect_left_diagonal
  • line_detect_right_diagonal
  • line_detect_vertical
SobelSobel kernels are used for edge detection. Available kernels are:
  • sobel_horizontal
  • sobel_vertical
SharpeningSharpening (high-pass) kernels accentuate local differences between a pixel and its neighbors. A high-pass filter calculates the focal sum statistic for each cell of the input using a weighted kernel neighborhood. It brings out the boundaries between features, thus sharpening edges between objects. Available kernels are:
  • sharpen
  • sharpen_more
  • sharpen_3x3
  • sharpen_5x5
SmoothingSmoothing (low-pass) kernels smooth the data by reducing local variation and removing noise. The low-pass filter calculates the average (mean) value for each neighborhood. The effect is that the high and low values within each neighborhood are averaged out, reducing the extreme values in the data. Available kernels are:
  • smooth_arithmetic_mean
  • smooth_3x3
  • smooth_5x5
Point spreadThe point spread kernel portrays the distribution of light from a point source through a lens. This will introduce a slight blurring effect. The available kernel is:
  • point_spread

You can also define a custom kernel. Use custom as the kernel name and provide the number of columns, number of rows, and an array of kernel values.

FunctionSyntax
Pythonconvolution(raster, kernel_name, num_cols=None, num_rows=None, kernel_values=None)
SQLRT_convolution(raster, kernel_name, width, height, weights)
Scalaconvolution(raster, kernelName, width, height, weights)

For more details, go to the GeoAnalytics Engine API reference for convolution.

Examples

PythonPythonSQLScala
Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17

from geoanalytics.raster import functions as RT

pixels = list(range(16))
df = spark.createDataFrame([[pixels]], ["pixels"]) \
          .withColumn("raster", RT.create_raster("pixels", 4, 4, "int8"))

# Apply a predefined kernel
r1 = df.select(RT.convolution("raster", "smooth_3x3").alias("convolution"))
r1.withColumn("smooth_pixels", RT.band_values("convolution", 1)).show(truncate=False)

# Apply a custom kernel
kernel = [1, 1, 1,
          1, 1, 1,
          1, 1, 1]
r2 = df.select(RT.convolution("raster", "custom", 3, 3, kernel).alias("convolution"))
r2.withColumn("custom_pixels", RT.band_values("convolution", 1)).show(truncate=False)
Result
Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
10
11
+-------------------------+-----------------------------------------------------------------------------------------------------+
|convolution              |smooth_pixels                                                                                        |
+-------------------------+-----------------------------------------------------------------------------------------------------+
|SqlRaster(1x4x4, Float32)|[0.9375, 1.75, 2.5, 3.0625, 3.25, 5.0, 6.0, 6.75, 6.25, 9.0, 10.0, 10.75, 6.1875, 8.75, 9.5, 10.0625]|
+-------------------------+-----------------------------------------------------------------------------------------------------+

+-----------------------+------------------------------------------------------------------------------------------------+
|convolution            |custom_pixels                                                                                   |
+-----------------------+------------------------------------------------------------------------------------------------+
|SqlRaster(1x4x4, Int16)|[10.0, 18.0, 24.0, 28.0, 27.0, 45.0, 54.0, 60.0, 51.0, 81.0, 90.0, 96.0, 42.0, 66.0, 72.0, 76.0]|
+-----------------------+------------------------------------------------------------------------------------------------+

Version table

ReleaseNotes

2.2.0

Python, SQL, and Scala functions introduced

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.