Announcement: All noncommercial projects registered to use Earth Engine before
April 15, 2025 must
verify noncommercial eligibility to maintain Earth Engine access.
ee.Kernel.add
Stay organized with collections
Save and categorize content based on your preferences.
Adds two kernels (pointwise) after aligning their centers.
Usage | Returns | Kernel.add(kernel2, normalize) | Kernel |
Argument | Type | Details | this: kernel1 | Kernel | The first kernel. |
kernel2 | Kernel | The second kernel. |
normalize | Boolean, default: false | Normalize the kernel. |
Examples
Code Editor (JavaScript)
// Two kernels, they do not need to have the same dimensions.
var kernelA = ee.Kernel.chebyshev({radius: 3});
var kernelB = ee.Kernel.square({radius: 1, normalize: false, magnitude: 100});
print(kernelA, kernelB);
/**
* Two kernel weights matrices
*
* [3, 3, 3, 3, 3, 3, 3]
* [3, 2, 2, 2, 2, 2, 3]
* [3, 2, 1, 1, 1, 2, 3] [100, 100, 100]
* A [3, 2, 1, 0, 1, 2, 3] B [100, 100, 100]
* [3, 2, 1, 1, 1, 2, 3] [100, 100, 100]
* [3, 2, 2, 2, 2, 2, 3]
* [3, 3, 3, 3, 3, 3, 3]
*/
print('Pointwise addition of two kernels', kernelA.add(kernelB));
/**
* [3, 3, 3, 3, 3, 3, 3]
* [3, 2, 2, 2, 2, 2, 3]
* [3, 2, 101, 101, 101, 2, 3]
* [3, 2, 101, 100, 101, 2, 3]
* [3, 2, 101, 101, 101, 2, 3]
* [3, 2, 2, 2, 2, 2, 3]
* [3, 3, 3, 3, 3, 3, 3]
*/
Python setup
See the
Python Environment page for information on the Python API and using
geemap
for interactive development.
import ee
import geemap.core as geemap
Colab (Python)
from pprint import pprint
# Two kernels, they do not need to have the same dimensions.
kernel_a = ee.Kernel.chebyshev(**{'radius': ee.Number(3)})
kernel_b = ee.Kernel.square(**{
'radius': 1,
'normalize': False,
'magnitude': 100
})
pprint(kernel_a.getInfo())
pprint(kernel_b.getInfo())
# Two kernel weights matrices
# [3, 3, 3, 3, 3, 3, 3]
# [3, 2, 2, 2, 2, 2, 3]
# [3, 2, 1, 1, 1, 2, 3] [100, 100, 100]
# A [3, 2, 1, 0, 1, 2, 3] B [100, 100, 100]
# [3, 2, 1, 1, 1, 2, 3] [100, 100, 100]
# [3, 2, 2, 2, 2, 2, 3]
# [3, 3, 3, 3, 3, 3, 3]
print('Pointwise addition of two kernels:')
pprint(kernel_a.add(kernel_b).getInfo())
# [3, 3, 3, 3, 3, 3, 3]
# [3, 2, 2, 2, 2, 2, 3]
# [3, 2, 101, 101, 101, 2, 3]
# [3, 2, 101, 100, 101, 2, 3]
# [3, 2, 101, 101, 101, 2, 3]
# [3, 2, 2, 2, 2, 2, 3]
# [3, 3, 3, 3, 3, 3, 3]
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2024-09-19 UTC.
[null,null,["Last updated 2024-09-19 UTC."],[[["\u003cp\u003e\u003ccode\u003eKernel.add\u003c/code\u003e combines two kernels by adding their weights pointwise after aligning their centers.\u003c/p\u003e\n"],["\u003cp\u003eThe resulting kernel has the same dimensions as the larger of the two input kernels.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003enormalize\u003c/code\u003e parameter can be used to normalize the resulting kernel.\u003c/p\u003e\n"],["\u003cp\u003eKernels do not need to have the same dimensions to be added.\u003c/p\u003e\n"]]],[],null,["# ee.Kernel.add\n\nAdds two kernels (pointwise) after aligning their centers.\n\n\u003cbr /\u003e\n\n| Usage | Returns |\n|--------------------------------------|---------|\n| Kernel.add`(kernel2, `*normalize*`)` | Kernel |\n\n| Argument | Type | Details |\n|-----------------|-------------------------|-----------------------|\n| this: `kernel1` | Kernel | The first kernel. |\n| `kernel2` | Kernel | The second kernel. |\n| `normalize` | Boolean, default: false | Normalize the kernel. |\n\nExamples\n--------\n\n### Code Editor (JavaScript)\n\n```javascript\n// Two kernels, they do not need to have the same dimensions.\nvar kernelA = ee.Kernel.chebyshev({radius: 3});\nvar kernelB = ee.Kernel.square({radius: 1, normalize: false, magnitude: 100});\nprint(kernelA, kernelB);\n\n/**\n * Two kernel weights matrices\n *\n * [3, 3, 3, 3, 3, 3, 3]\n * [3, 2, 2, 2, 2, 2, 3]\n * [3, 2, 1, 1, 1, 2, 3] [100, 100, 100]\n * A [3, 2, 1, 0, 1, 2, 3] B [100, 100, 100]\n * [3, 2, 1, 1, 1, 2, 3] [100, 100, 100]\n * [3, 2, 2, 2, 2, 2, 3]\n * [3, 3, 3, 3, 3, 3, 3]\n */\n\nprint('Pointwise addition of two kernels', kernelA.add(kernelB));\n\n/**\n * [3, 3, 3, 3, 3, 3, 3]\n * [3, 2, 2, 2, 2, 2, 3]\n * [3, 2, 101, 101, 101, 2, 3]\n * [3, 2, 101, 100, 101, 2, 3]\n * [3, 2, 101, 101, 101, 2, 3]\n * [3, 2, 2, 2, 2, 2, 3]\n * [3, 3, 3, 3, 3, 3, 3]\n */\n```\nPython setup\n\nSee the [Python Environment](/earth-engine/guides/python_install) page for information on the Python API and using\n`geemap` for interactive development. \n\n```python\nimport ee\nimport geemap.core as geemap\n```\n\n### Colab (Python)\n\n```python\nfrom pprint import pprint\n\n# Two kernels, they do not need to have the same dimensions.\nkernel_a = ee.Kernel.chebyshev(**{'radius': ee.Number(3)})\nkernel_b = ee.Kernel.square(**{\n 'radius': 1,\n 'normalize': False,\n 'magnitude': 100\n})\npprint(kernel_a.getInfo())\npprint(kernel_b.getInfo())\n\n# Two kernel weights matrices\n\n# [3, 3, 3, 3, 3, 3, 3]\n# [3, 2, 2, 2, 2, 2, 3]\n# [3, 2, 1, 1, 1, 2, 3] [100, 100, 100]\n# A [3, 2, 1, 0, 1, 2, 3] B [100, 100, 100]\n# [3, 2, 1, 1, 1, 2, 3] [100, 100, 100]\n# [3, 2, 2, 2, 2, 2, 3]\n# [3, 3, 3, 3, 3, 3, 3]\n\nprint('Pointwise addition of two kernels:')\npprint(kernel_a.add(kernel_b).getInfo())\n\n# [3, 3, 3, 3, 3, 3, 3]\n# [3, 2, 2, 2, 2, 2, 3]\n# [3, 2, 101, 101, 101, 2, 3]\n# [3, 2, 101, 100, 101, 2, 3]\n# [3, 2, 101, 101, 101, 2, 3]\n# [3, 2, 2, 2, 2, 2, 3]\n# [3, 3, 3, 3, 3, 3, 3]\n```"]]