[null,null,["最后更新时间 (UTC):2025-07-25。"],[[["\u003cp\u003eThe \u003ccode\u003eimage.convolve()\u003c/code\u003e function is used to perform linear convolutions on images in Earth Engine using kernels to modify pixel values based on surrounding pixels.\u003c/p\u003e\n"],["\u003cp\u003eKernels such as boxcar (low-pass) smooth images while Laplacian kernels highlight edges; both are customizable in size and weight.\u003c/p\u003e\n"],["\u003cp\u003eKernels are applied to each band individually, and the \u003ccode\u003enormalize\u003c/code\u003e parameter can be set to ensure the kernel coefficients sum to one or zero depending on the presence of negative values.\u003c/p\u003e\n"],["\u003cp\u003eVarious predefined kernels, like Sobel, Prewitt, Roberts, Gaussian, and those with uniform weights, are available, and custom kernels can be built using \u003ccode\u003eee.Kernel.fixed()\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eFor consistent display, use the format specifier \u003ccode\u003eformat: 'png'\u003c/code\u003e in the visualization parameters when convolving images with edge-detection kernels, as it handles transparency of pixels outside the image boundary more effectively.\u003c/p\u003e\n"]]],[],null,["# Convolutions\n\nTo perform linear convolutions on images, use `image.convolve()`. The only\nargument to convolve is an `ee.Kernel` which is specified by a shape and the\nweights in the kernel. Each pixel of the image output by `convolve()`\nis the linear combination of the kernel values and the input image pixels covered by the\nkernel. The kernels are applied to each band individually. For example, you might want\nto use a low-pass (smoothing) kernel to remove high-frequency information. The following\nillustrates a 15x15 low-pass kernel applied to a Landsat 8 image:\n\n### Code Editor (JavaScript)\n\n```javascript\n// Load and display an image.\nvar image = ee.Image('LANDSAT/LC08/C02/T1_TOA/LC08_044034_20140318');\nMap.setCenter(-121.9785, 37.8694, 11);\nMap.addLayer(image, {bands: ['B5', 'B4', 'B3'], max: 0.5}, 'input image');\n\n// Define a boxcar or low-pass kernel.\nvar boxcar = ee.Kernel.square({\n radius: 7, units: 'pixels', normalize: true\n});\n\n// Smooth the image by convolving with the boxcar kernel.\nvar smooth = image.convolve(boxcar);\nMap.addLayer(smooth, {bands: ['B5', 'B4', 'B3'], max: 0.5}, 'smoothed');\n```\n\nThe output of convolution with the low-pass filter should look something like Figure\n1. Observe that the arguments to the kernel determine its size and coefficients.\nSpecifically, with the `units` parameter set to pixels, the `radius`\nparameter specifies the number of pixels from the center that the kernel will cover. If\n`normalize` is set to true, the kernel coefficients will sum to one. If\nthe `magnitude` parameter is set, the kernel coefficients will be multiplied by\nthe magnitude (if `normalize` is also true, the coefficients will sum to\n`magnitude`). If there is a negative value in any of the kernel coefficients,\nsetting `normalize` to true will make the coefficients sum to zero.\nFigure 1. Landsat 8 image convolved with a smoothing kernel. San Francisco Bay area, California, USA.\n\nUse other kernels to achieve the desired image processing effect. This example uses a\nLaplacian kernel for isotropic edge detection:\n\n### Code Editor (JavaScript)\n\n```javascript\n// Define a Laplacian, or edge-detection kernel.\nvar laplacian = ee.Kernel.laplacian8({ normalize: false });\n\n// Apply the edge-detection kernel.\nvar edgy = image.convolve(laplacian);\nMap.addLayer(edgy,\n {bands: ['B5', 'B4', 'B3'], max: 0.5, format: 'png'},\n 'edges');\n```\n\nNote the format specifier in the visualization parameters. Earth Engine sends display\ntiles to the Code Editor in JPEG format for efficiency, however edge tiles are sent in PNG\nformat to handle transparency of pixels outside the image boundary. When a visual\ndiscontinuity results, setting the format to PNG results in a consistent display. The\nresult of convolving with the Laplacian edge detection kernel should look something\nlike Figure 2.\nFigure 2. Landsat 8 image convolved with a Laplacian edge detection kernel. San Francisco Bay area, California, USA.\n\nThere are also anisotropic edge detection kernels (e.g. Sobel, Prewitt, Roberts), the\ndirection of which can be changed with `kernel.rotate()`. Other low pass\nkernels include a Gaussian kernel and kernels of various shape with uniform weights. To\ncreate kernels with arbitrarily defined weights and shape, use\n`ee.Kernel.fixed()`. For example, this code creates a 9x9 kernel of 1's\nwith a zero in the middle:\n\n### Code Editor (JavaScript)\n\n```javascript\n// Create a list of weights for a 9x9 kernel.\nvar row = [1, 1, 1, 1, 1, 1, 1, 1, 1];\n// The center of the kernel is zero.\nvar centerRow = [1, 1, 1, 1, 0, 1, 1, 1, 1];\n// Assemble a list of lists: the 9x9 kernel weights as a 2-D matrix.\nvar rows = [row, row, row, row, centerRow, row, row, row, row];\n// Create the kernel from the weights.\nvar kernel = ee.Kernel.fixed(9, 9, rows, -4, -4, false);\nprint(kernel);\n```"]]