공지사항:
2025년 4월 15일 전에 Earth Engine 사용을 위해 등록된 모든 비상업용 프로젝트는 Earth Engine 액세스를 유지하기 위해
비상업용 자격 요건을 인증해야 합니다.
수학 연산
컬렉션을 사용해 정리하기
내 환경설정을 기준으로 콘텐츠를 저장하고 분류하세요.
이미지 수학은 add()
및 subtract()
와 같은 연산자를 사용하여 실행할 수 있지만, 두 개 이상의 항이 있는 복잡한 계산의 경우 expression()
함수가 좋은 대안이 됩니다. 연산자 및 표현식에 관한 자세한 내용은 다음 섹션을 참고하세요.
연산자
수학 연산자는 이미지 밴드에서 기본 산술 연산을 실행합니다. 두 개의 이미지 또는 하나의 이미지와 상수 항(마스킹된 픽셀이 없는 단일 밴드 상수 이미지로 해석됨)이라는 두 가지 입력을 사용합니다. 작업은 각 밴드의 픽셀당 실행됩니다.
기본 예로 VIIRS 이미지를 사용하여 정규 식생 지수 (NDVI)를 계산하는 작업을 생각해 보겠습니다. 여기서 add()
, subtract()
, divide()
연산자가 사용됩니다.
코드 편집기 (JavaScript)
// Load a VIIRS 8-day surface reflectance composite for May 2024.
var viirs202405 = ee.ImageCollection('NASA/VIIRS/002/VNP09H1').filter(
ee.Filter.date('2024-05-01', '2024-05-16')).first();
// Compute NDVI.
var ndvi202405 = viirs202405.select('SurfReflect_I2')
.subtract(viirs202405.select('SurfReflect_I1'))
.divide(viirs202405.select('SurfReflect_I2')
.add(viirs202405.select('SurfReflect_I1')));
Python 설정
Python API 및 대화형 개발을 위한 geemap
사용에 관한 자세한 내용은
Python 환경 페이지를 참고하세요.
import ee
import geemap.core as geemap
Colab (Python)
# Load a VIIRS 8-day surface reflectance composite for May 2024.
viirs202405 = (
ee.ImageCollection('NASA/VIIRS/002/VNP09H1')
.filter(ee.Filter.date('2024-05-01', '2024-05-16'))
.first()
)
# Compute NDVI.
ndvi202405 = (
viirs202405.select('SurfReflect_I2')
.subtract(viirs202405.select('SurfReflect_I1'))
.divide(
viirs202405.select('SurfReflect_I2').add(
viirs202405.select('SurfReflect_I1')
)
)
)
두 입력 간의 마스크가 적용되지 않은 픽셀의 교차점만 고려되고 마스크가 적용되지 않은 것으로 반환되며 그 외 모든 픽셀은 마스크가 적용됩니다. 일반적으로 입력 중 하나에 밴드가 하나만 있으면 다른 입력의 모든 밴드에 사용됩니다. 입력의 밴드 수가 같지만 이름이 같지 않은 경우 자연 순서로 쌍으로 사용됩니다. 출력 밴드는 두 입력 중 더 긴 입력의 이름을 따르며, 길이가 같은 경우에는 첫 번째 입력의 순서를 따릅니다. 출력 픽셀의 유형은 입력 유형의 합집합입니다.
다음 멀티밴드 이미지 차감 예에서는 밴드가 자동으로 일치하여 공존하는 각 밴드의 각 픽셀에 대해 '변경 벡터'가 생성되는 방식을 보여줍니다.
코드 편집기 (JavaScript)
// Load a VIIRS 8-day surface reflectance composite for September 2024.
var viirs202409 = ee.ImageCollection('NASA/VIIRS/002/VNP09H1').filter(
ee.Filter.date('2024-09-01', '2024-09-16')).first();
// Compute multi-band difference between the September composite and the
// previously loaded May composite.
var diff = viirs202409.subtract(ndvi202405);
Map.addLayer(diff, {
bands: ['SurfReflect_I1', 'SurfReflect_I2', 'SurfReflect_I3'],
min: -1,
max: 1
}, 'difference');
// Compute the squared difference in each band.
var squaredDifference = diff.pow(2);
Map.addLayer(squaredDifference, {
bands: ['SurfReflect_I1', 'SurfReflect_I2', 'SurfReflect_I3'],
min: 0,
max: 0.7
}, 'squared diff.');
Python 설정
Python API 및 대화형 개발을 위한 geemap
사용에 관한 자세한 내용은
Python 환경 페이지를 참고하세요.
import ee
import geemap.core as geemap
Colab (Python)
# Load a VIIRS 8-day surface reflectance composite for September 2024.
viirs202409 = (
ee.ImageCollection('NASA/VIIRS/002/VNP09H1')
.filter(ee.Filter.date('2024-09-01', '2024-09-16'))
.first()
)
# Compute multi-band difference between the September composite and the
# previously loaded May composite.
diff = viirs202409.subtract(ndvi202405)
m = geemap.Map()
m.add_layer(
diff,
{
'bands': ['SurfReflect_I1', 'SurfReflect_I2', 'SurfReflect_I3'],
'min': -1,
'max': 1,
},
'difference',
)
# Compute the squared difference in each band.
squared_difference = diff.pow(2)
m.add_layer(
squared_difference,
{
'bands': ['SurfReflect_I1', 'SurfReflect_I2', 'SurfReflect_I3'],
'min': 0,
'max': 0.7,
},
'squared diff.',
)
display(m)
이 예의 두 번째 부분에서는 image.pow(2)
를 사용하여 차이의 제곱을 계산합니다. 기본 산술, 삼각법, 지수, 반올림, 변환, 비트 연산 등을 처리하는 수학 연산자의 전체 목록은 API 문서를 참고하세요.
표현식
더 복잡한 수학식을 구현하려면 수학 연산의 텍스트 표현을 파싱하는 image.expression()
를 사용하는 것이 좋습니다.
다음 예에서는 expression()
를 사용하여 향상된 식물지수 (EVI)를 계산합니다.
코드 편집기 (JavaScript)
// Load a Landsat 8 image.
var image = ee.Image('LANDSAT/LC08/C02/T1_TOA/LC08_044034_20140318');
// Compute the EVI using an expression.
var evi = image.expression(
'2.5 * ((NIR - RED) / (NIR + 6 * RED - 7.5 * BLUE + 1))', {
'NIR': image.select('B5'),
'RED': image.select('B4'),
'BLUE': image.select('B2')
});
Map.centerObject(image, 9);
Map.addLayer(evi, {min: -1, max: 1, palette: ['a6611a', 'f5f5f5', '4dac26']});
Python 설정
Python API 및 대화형 개발을 위한 geemap
사용에 관한 자세한 내용은
Python 환경 페이지를 참고하세요.
import ee
import geemap.core as geemap
Colab (Python)
# Load a Landsat 8 image.
image = ee.Image('LANDSAT/LC08/C02/T1_TOA/LC08_044034_20140318')
# Compute the EVI using an expression.
evi = image.expression(
'2.5 * ((NIR - RED) / (NIR + 6 * RED - 7.5 * BLUE + 1))',
{
'NIR': image.select('B5'),
'RED': image.select('B4'),
'BLUE': image.select('B2'),
},
)
# Define a map centered on San Francisco Bay.
map_evi = geemap.Map(center=[37.4675, -122.1363], zoom=9)
# Add the image layer to the map and display it.
map_evi.add_layer(
evi, {'min': -1, 'max': 1, 'palette': ['a6611a', 'f5f5f5', '4dac26']}, 'evi'
)
display(map_evi)
expression()
의 첫 번째 인수는 수학 연산의 텍스트 표현이고, 두 번째 인수는 키가 표현식에 사용된 변수 이름이고 값이 변수를 매핑해야 하는 이미지 밴드인 사전입니다. 이미지의 밴드는 사전을 제공하는 대신 b("band name")
또는 b(index)
(예: b(0)
)으로 참조될 수 있습니다. 밴드 맵 사전을 사용할 때는 입력이 아닌 다른 이미지에서 밴드를 정의할 수 있습니다. expression()
는 두 정수를 나눌 때 나머지를 삭제하고 정수를 반환하는 'floor division'을 사용합니다. 예를 들면 다음과 같습니다. 10 / 20 = 0
이 동작을 변경하려면 피연산자 중 하나에 1.0
: 10 * 1.0 / 20 = 0.5
를 곱합니다. 두 개 이상의 소스 이미지의 밴드를 평가할 때는 마스크가 적용되지 않은 픽셀의 교차점만 고려되고 마스크가 적용되지 않은 것으로 반환됩니다. 지원되는 표현식 연산자는 다음 표에 나와 있습니다.
expression()
의 연산자
유형 |
기호 |
이름 |
산술 |
+ - * / % ** |
더하기, 빼기, 곱하기, 나누기, 나머지, 지수 |
관계형 |
== != < > <= >= |
같음, 같지 않음, 작음, 큼 등 |
논리 |
&& || ! ^ |
And, Or, Not, Xor |
Ternary |
? : |
if then else |
달리 명시되지 않는 한 이 페이지의 콘텐츠에는 Creative Commons Attribution 4.0 라이선스에 따라 라이선스가 부여되며, 코드 샘플에는 Apache 2.0 라이선스에 따라 라이선스가 부여됩니다. 자세한 내용은 Google Developers 사이트 정책을 참조하세요. 자바는 Oracle 및/또는 Oracle 계열사의 등록 상표입니다.
최종 업데이트: 2025-07-25(UTC)
[null,null,["최종 업데이트: 2025-07-25(UTC)"],[[["\u003cp\u003eEarth Engine provides tools for performing image math, including operators for basic arithmetic and the \u003ccode\u003eexpression()\u003c/code\u003e function for complex computations.\u003c/p\u003e\n"],["\u003cp\u003eOperators like \u003ccode\u003eadd()\u003c/code\u003e, \u003ccode\u003esubtract()\u003c/code\u003e, and \u003ccode\u003edivide()\u003c/code\u003e enable pixel-wise calculations between images or an image and a constant.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eexpression()\u003c/code\u003e function allows implementing custom formulas by parsing text representations of mathematical operations and mapping variables to image bands.\u003c/p\u003e\n"],["\u003cp\u003eWhen using \u003ccode\u003eexpression()\u003c/code\u003e, ensure to handle integer division appropriately by multiplying one operand by \u003ccode\u003e1.0\u003c/code\u003e to preserve decimal values if needed.\u003c/p\u003e\n"],["\u003cp\u003eBoth operators and expressions automatically handle band matching and masking, considering only unmasked pixels in the calculations.\u003c/p\u003e\n"]]],[],null,["# Mathematical Operations\n\n|---------------------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------|\n| [Run in Google Colab](https://colab.research.google.com/github/google/earthengine-community/blob/master/guides/linked/generated/image_math.ipynb) | [View source on GitHub](https://github.com/google/earthengine-community/blob/master/guides/linked/generated/image_math.ipynb) |\n\nImage math can be performed using operators like `add()` and\n`subtract()`, but for complex computations with more than a couple of terms, the\n`expression()` function provides a good alternative. See the following sections\nfor more information on [operators](#operators) and\n[expressions](#expressions).\n\nOperators\n---------\n\nMath operators perform basic arithmetic operations on image bands. They take two inputs:\neither two images or one image and a constant term, which\nis interpreted as a single-band constant image with no masked pixels. Operations are performed\nper pixel for each band.\n\nAs a basic example, consider the task of calculating the Normalized Difference Vegetation\nIndex (NDVI) using VIIRS imagery, where `add()`, `subtract()`,\nand `divide()` operators are used:\n\n### Code Editor (JavaScript)\n\n```javascript\n// Load a VIIRS 8-day surface reflectance composite for May 2024.\nvar viirs202405 = ee.ImageCollection('NASA/VIIRS/002/VNP09H1').filter(\n ee.Filter.date('2024-05-01', '2024-05-16')).first();\n\n// Compute NDVI.\nvar ndvi202405 = viirs202405.select('SurfReflect_I2')\n .subtract(viirs202405.select('SurfReflect_I1'))\n .divide(viirs202405.select('SurfReflect_I2')\n .add(viirs202405.select('SurfReflect_I1')));\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\n# Load a VIIRS 8-day surface reflectance composite for May 2024.\nviirs202405 = (\n ee.ImageCollection('NASA/VIIRS/002/VNP09H1')\n .filter(ee.Filter.date('2024-05-01', '2024-05-16'))\n .first()\n)\n\n# Compute NDVI.\nndvi202405 = (\n viirs202405.select('SurfReflect_I2')\n .subtract(viirs202405.select('SurfReflect_I1'))\n .divide(\n viirs202405.select('SurfReflect_I2').add(\n viirs202405.select('SurfReflect_I1')\n )\n )\n)\n```\n| **Note:** the normalized difference operation is available as a shortcut method: [`normalizedDifference()`](/earth-engine/apidocs/ee-image-normalizeddifference).\n\nOnly the intersection of unmasked pixels between the two inputs are\nconsidered and returned as unmasked, all else are masked. In general, if either input has only\none band, then it is used against all the bands in the other input. If the inputs have the same\nnumber of bands, but not the same names, they're used pairwise in the natural order. The\noutput bands are named for the longer of the two inputs, or if they're equal in length, in the\nfirst input's order. The type of the output pixels is the union of the input types.\n\nThe following example of multi-band image subtraction demonstrates how bands are matched\nautomatically, resulting in a \"change vector\" for each pixel for each co-occurring band.\n\n### Code Editor (JavaScript)\n\n```javascript\n// Load a VIIRS 8-day surface reflectance composite for September 2024.\nvar viirs202409 = ee.ImageCollection('NASA/VIIRS/002/VNP09H1').filter(\n ee.Filter.date('2024-09-01', '2024-09-16')).first();\n\n// Compute multi-band difference between the September composite and the\n// previously loaded May composite.\nvar diff = viirs202409.subtract(ndvi202405);\nMap.addLayer(diff, {\n bands: ['SurfReflect_I1', 'SurfReflect_I2', 'SurfReflect_I3'],\n min: -1,\n max: 1\n}, 'difference');\n\n// Compute the squared difference in each band.\nvar squaredDifference = diff.pow(2);\nMap.addLayer(squaredDifference, {\n bands: ['SurfReflect_I1', 'SurfReflect_I2', 'SurfReflect_I3'],\n min: 0,\n max: 0.7\n}, 'squared diff.');\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\n# Load a VIIRS 8-day surface reflectance composite for September 2024.\nviirs202409 = (\n ee.ImageCollection('NASA/VIIRS/002/VNP09H1')\n .filter(ee.Filter.date('2024-09-01', '2024-09-16'))\n .first()\n)\n\n# Compute multi-band difference between the September composite and the\n# previously loaded May composite.\ndiff = viirs202409.subtract(ndvi202405)\n\nm = geemap.Map()\nm.add_layer(\n diff,\n {\n 'bands': ['SurfReflect_I1', 'SurfReflect_I2', 'SurfReflect_I3'],\n 'min': -1,\n 'max': 1,\n },\n 'difference',\n)\n\n# Compute the squared difference in each band.\nsquared_difference = diff.pow(2)\n\nm.add_layer(\n squared_difference,\n {\n 'bands': ['SurfReflect_I1', 'SurfReflect_I2', 'SurfReflect_I3'],\n 'min': 0,\n 'max': 0.7,\n },\n 'squared diff.',\n)\ndisplay(m)\n```\n\nIn the second part of this example, the squared difference is computed using\n`image.pow(2)`. For the complete list of mathematical operators handling\nbasic arithmetic, trigonometry, exponentiation, rounding, casting, bitwise operations\nand more, see the [API documentation](/earth-engine/apidocs).\n\nExpressions\n-----------\n\nTo implement more complex mathematical expressions, consider using\n`image.expression()`, which parses a text representation of a math operation.\nThe following example uses `expression()` to compute the Enhanced\nVegetation Index (EVI):\n\n### Code Editor (JavaScript)\n\n```javascript\n// Load a Landsat 8 image.\nvar image = ee.Image('LANDSAT/LC08/C02/T1_TOA/LC08_044034_20140318');\n\n// Compute the EVI using an expression.\nvar evi = image.expression(\n '2.5 * ((NIR - RED) / (NIR + 6 * RED - 7.5 * BLUE + 1))', {\n 'NIR': image.select('B5'),\n 'RED': image.select('B4'),\n 'BLUE': image.select('B2')\n});\n\nMap.centerObject(image, 9);\nMap.addLayer(evi, {min: -1, max: 1, palette: ['a6611a', 'f5f5f5', '4dac26']});\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\n# Load a Landsat 8 image.\nimage = ee.Image('LANDSAT/LC08/C02/T1_TOA/LC08_044034_20140318')\n\n# Compute the EVI using an expression.\nevi = image.expression(\n '2.5 * ((NIR - RED) / (NIR + 6 * RED - 7.5 * BLUE + 1))',\n {\n 'NIR': image.select('B5'),\n 'RED': image.select('B4'),\n 'BLUE': image.select('B2'),\n },\n)\n\n# Define a map centered on San Francisco Bay.\nmap_evi = geemap.Map(center=[37.4675, -122.1363], zoom=9)\n\n# Add the image layer to the map and display it.\nmap_evi.add_layer(\n evi, {'min': -1, 'max': 1, 'palette': ['a6611a', 'f5f5f5', '4dac26']}, 'evi'\n)\ndisplay(map_evi)\n```\n\nObserve that the first argument to `expression()` is the textual representation of\nthe math operation, the second argument is a dictionary where the keys are variable names used\nin the expression and the values are the image bands to which the variables should be\nmapped. Bands in the image may be referred to as `b(\"band name\")` or\n`b(index)`, for example `b(0)`, instead\nof providing the dictionary. Bands can be defined from images other than the input when using\nthe band map dictionary. Note that `expression()` uses \"floor division\", which\ndiscards the remainder and returns an integer when two integers are divided. For example\n`10 / 20 = 0`. To change this behavior, multiply one of the operands by\n`1.0`: `10 * 1.0 / 20 = 0.5`. Only the intersection of unmasked pixels\nare considered and returned as unmasked when bands from more than one source image are\nevaluated. Supported expression operators are listed in the following table.\n\n| Type | Symbol | Name |\n|----------------|---------------------|----------------------------------------------------|\n| **Arithmetic** | + - \\* / % \\*\\* | Add, Subtract, Multiply, Divide, Modulus, Exponent |\n| **Relational** | == != \\\u003c \\\u003e \\\u003c= \\\u003e= | Equal, Not Equal, Less Than, Greater than, etc. |\n| **Logical** | \\&\\& \\|\\| ! \\^ | And, Or, Not, Xor |\n| **Ternary** | ? : | If then else |\n[Operators for `expression()`]"]]