기본 입력 이미지의 밴드는 b(0) 또는 b('band_name')과 같이 내장 함수 b()를 사용하여 사용할 수 있습니다.
표현식의 변수는 opt_map에 제공해야 하는 추가 이미지 매개변수로 해석됩니다. 이러한 각 이미지의 밴드는 image.band_name 또는 image[0]과 같이 액세스할 수 있습니다.
b()와 image[] 모두 여러 인수를 허용하여 b(1, 'name', 3)과 같이 여러 밴드를 지정할 수 있습니다. 인수 없이 b()를 호출하거나 변수 자체를 사용하면 이미지의 모든 밴드가 반환됩니다.
표현식의 결과가 단일 밴드인 경우 '=' 연산자를 사용하여 이름을 할당할 수 있습니다 (예: x = a + b).
제공된 표현식으로 계산된 이미지를 반환합니다.
사용 | 반환 값 |
---|---|
Image.expression(expression, map) | 이미지 |
인수 | 유형 | 세부정보 |
---|---|---|
다음과 같은 경우: image | 이미지 | 이미지 인스턴스입니다. |
expression | 문자열 | 평가할 표현식. |
map | Dictionary<Image>, 선택사항 | 이름으로 사용할 수 있는 입력 이미지의 맵입니다. |
예
코드 편집기 (JavaScript)
// The following expressions calculate the normalized difference vegetation // index (NDVI): (NIR - Red) / (NIR + Red). // NIR is Landsat 8 L2 band 'SR_B5', the 4th band index. // Red is Landsat 8 L2 band 'SR_B4', the 3rd band index. // A Landsat 8 L2 surface reflectance image. var img = ee.Image('LANDSAT/LC08/C02/T1_L2/LC08_044034_20210508'); // Visualization parameters for NDVI. var ndviVis = {min: 0, max: 0.5}; // Expression using image band indices. var bandIndexExp = '(b(4) - b(3)) / (b(4) + b(3))'; var bandIndexImg = img.expression(bandIndexExp).rename('NDVI'); Map.setCenter(-122.14, 37.38, 11); Map.addLayer(bandIndexImg, ndviVis, 'NDVI 1'); // Expression using image band names. var bandNameExp = '(b("SR_B5") - b("SR_B4")) / (b("SR_B5") + b("SR_B4"))'; var bandNameImg = img.expression(bandNameExp).rename('NDVI'); Map.addLayer(bandNameImg, ndviVis, 'NDVI 2'); // Expression using named variables. var namedVarsExp = '(NIR - Red) / (NIR + Red)'; var namedVarsImg = ee.Image().expression({ expression: namedVarsExp, map: { NIR: img.select('SR_B5'), Red: img.select('SR_B4') } }).rename('NDVI'); Map.addLayer(namedVarsImg, ndviVis, 'NDVI 3'); // Expression using named variables with image band access by dot notation. var namedVarsDotExp = '(ls8.SR_B5 - ls8.SR_B4) / (ls8.SR_B5 + ls8.SR_B4)'; var namedVarsDotImg = ee.Image().expression({ expression: namedVarsDotExp, map: {ls8: img} }).rename('NDVI'); Map.addLayer(namedVarsDotImg, ndviVis, 'NDVI 4'); // Expressions can use arithmetic operators (+ - * / % **), relational // operators (== != < > <= >=), logical operators (&& || ! ^), the ternary // operator (condition ? ifTrue : ifFalse), and a subset of JavaScript Math // functions. Math functions are called by name directly, they are not accessed // from the Math object (e.g., sqrt() instead of Math.sqrt()). var jsMathExp = 'c = sqrt(pow(a, 2) + pow(b, 2))'; var jsMathImg = ee.Image().expression({ expression: jsMathExp, map: { a: ee.Image(5), b: img.select('SR_B2') } }); Map.addLayer(jsMathImg, {min: 5000, max: 20000}, 'Hypotenuse', false);
import ee import geemap.core as geemap
Colab (Python)
# The following expressions calculate the normalized difference vegetation # index (NDVI): (NIR - Red) / (NIR + Red). # NIR is Landsat 8 L2 band 'SR_B5', the 4th band index. # Red is Landsat 8 L2 band 'SR_B4', the 3rd band index. # A Landsat 8 L2 surface reflectance image. img = ee.Image('LANDSAT/LC08/C02/T1_L2/LC08_044034_20210508') # Visualization parameters for NDVI. ndvi_vis = {'min': 0, 'max': 0.5} # Expression using image band indices. band_index_exp = '(b(4) - b(3)) / (b(4) + b(3))' band_index_img = img.expression(band_index_exp).rename('NDVI') m = geemap.Map() m.set_center(-122.14, 37.38, 11) m.add_layer(band_index_img, ndvi_vis, 'NDVI 1') # Expression using image band names. band_name_exp = '(b("SR_B5") - b("SR_B4")) / (b("SR_B5") + b("SR_B4"))' band_name_img = img.expression(band_name_exp).rename('NDVI') m.add_layer(band_name_img, ndvi_vis, 'NDVI 2') # Expression using named variables. named_vars_exp = '(NIR - Red) / (NIR + Red)' named_vars_img = ( ee.Image() .expression( expression=named_vars_exp, opt_map={'NIR': img.select('SR_B5'), 'Red': img.select('SR_B4')}, ) .rename('NDVI') ) m.add_layer(named_vars_img, ndvi_vis, 'NDVI 3') # Expression using named variables with image band access by dot notation. named_vars_dot_exp = '(ls8.SR_B5 - ls8.SR_B4) / (ls8.SR_B5 + ls8.SR_B4)' named_vars_dot_img = ( ee.Image() .expression(expression=named_vars_dot_exp, opt_map={'ls8': img}) .rename('NDVI') ) m.add_layer(named_vars_dot_img, ndvi_vis, 'NDVI 4') # Expressions can use arithmetic operators (+ - * / % **), relational # operators (== != < > <= >=), logical operators (&& || ! ^), the ternary # operator (condition ? ifTrue : ifFalse), and a subset of JavaScript Math # functions. Math functions are called by name directly, they are not accessed # from the Math object (e.g., sqrt() instead of Math.sqrt()). js_math_exp = 'c = sqrt(pow(a, 2) + pow(b, 2))' js_math_img = ee.Image().expression( expression=js_math_exp, opt_map={'a': ee.Image(5), 'b': img.select('SR_B2')} ) m.add_layer(js_math_img, {'min': 5000, 'max': 20000}, 'Hypotenuse', False) m