ee.Image.expression
संग्रह की मदद से व्यवस्थित रहें
अपनी प्राथमिकताओं के आधार पर, कॉन्टेंट को सेव करें और कैटगरी में बांटें.
किसी इमेज पर मौजूद अंकगणितीय एक्सप्रेशन का आकलन करता है. इसमें अन्य इमेज भी शामिल हो सकती हैं.
मुख्य इनपुट इमेज के बैंड, पहले से मौजूद b() फ़ंक्शन का इस्तेमाल करके उपलब्ध होते हैं. जैसे, b(0) या b('band_name').
एक्सप्रेशन में मौजूद वैरिएबल को इमेज के अन्य पैरामीटर के तौर पर समझा जाता है. इन्हें 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);
Python सेटअप
Python API के बारे में जानकारी पाने और इंटरैक्टिव डेवलपमेंट के लिए geemap
का इस्तेमाल करने के लिए,
Python एनवायरमेंट पेज देखें.
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
जब तक कुछ अलग से न बताया जाए, तब तक इस पेज की सामग्री को Creative Commons Attribution 4.0 License के तहत और कोड के नमूनों को Apache 2.0 License के तहत लाइसेंस मिला है. ज़्यादा जानकारी के लिए, Google Developers साइट नीतियां देखें. Oracle और/या इससे जुड़ी हुई कंपनियों का, Java एक रजिस्टर किया हुआ ट्रेडमार्क है.
आखिरी बार 2025-07-25 (UTC) को अपडेट किया गया.
[null,null,["आखिरी बार 2025-07-25 (UTC) को अपडेट किया गया."],[[["\u003cp\u003e\u003ccode\u003eImage.expression()\u003c/code\u003e allows you to perform arithmetic calculations on images using expressions.\u003c/p\u003e\n"],["\u003cp\u003eYou can access image bands within the expression using \u003ccode\u003eb()\u003c/code\u003e with band indices or names, or by defining variables representing images.\u003c/p\u003e\n"],["\u003cp\u003eExpressions can incorporate arithmetic, relational, logical, and ternary operators, along with select JavaScript Math functions.\u003c/p\u003e\n"],["\u003cp\u003eNamed variables representing images can be used in the expression, and accessed by their names or through dot notation if they represent images.\u003c/p\u003e\n"],["\u003cp\u003eThe expression's result is a new image which can be assigned a name using the '=' operator if it is single-banded.\u003c/p\u003e\n"]]],[],null,["# ee.Image.expression\n\n\u003cbr /\u003e\n\nEvaluates an arithmetic expression on an image, possibly involving additional images.\n\n\u003cbr /\u003e\n\nThe bands of the primary input image are available using the built-in function b(), as b(0) or b('band_name').\n\nVariables in the expression are interpreted as additional image parameters which must be supplied in opt_map. The bands of each such image can be accessed like image.band_name or image\\[0\\].\n\nBoth b() and image\\[\\] allow multiple arguments, to specify multiple bands, such as b(1, 'name', 3). Calling b() with no arguments, or using a variable by itself, returns all bands of the image.\n\nIf the result of an expression is a single band, it can be assigned a name using the '=' operator (e.g.: x = a + b).\n\nReturns the image computed by the provided expression.\n\n| Usage | Returns |\n|-----------------------------------------|---------|\n| Image.expression`(expression, `*map*`)` | Image |\n\n| Argument | Type | Details |\n|---------------|-------------------------------|------------------------------------------|\n| this: `image` | Image | The Image instance. |\n| `expression` | String | The expression to evaluate. |\n| `map` | Dictionary\\\u003cImage\\\u003e, optional | A map of input images available by name. |\n\nExamples\n--------\n\n### Code Editor (JavaScript)\n\n```javascript\n// The following expressions calculate the normalized difference vegetation\n// index (NDVI): (NIR - Red) / (NIR + Red).\n// NIR is Landsat 8 L2 band 'SR_B5', the 4th band index.\n// Red is Landsat 8 L2 band 'SR_B4', the 3rd band index.\n\n// A Landsat 8 L2 surface reflectance image.\nvar img = ee.Image('LANDSAT/LC08/C02/T1_L2/LC08_044034_20210508');\n\n// Visualization parameters for NDVI.\nvar ndviVis = {min: 0, max: 0.5};\n\n// Expression using image band indices.\nvar bandIndexExp = '(b(4) - b(3)) / (b(4) + b(3))';\nvar bandIndexImg = img.expression(bandIndexExp).rename('NDVI');\nMap.setCenter(-122.14, 37.38, 11);\nMap.addLayer(bandIndexImg, ndviVis, 'NDVI 1');\n\n// Expression using image band names.\nvar bandNameExp = '(b(\"SR_B5\") - b(\"SR_B4\")) / (b(\"SR_B5\") + b(\"SR_B4\"))';\nvar bandNameImg = img.expression(bandNameExp).rename('NDVI');\nMap.addLayer(bandNameImg, ndviVis, 'NDVI 2');\n\n// Expression using named variables.\nvar namedVarsExp = '(NIR - Red) / (NIR + Red)';\nvar namedVarsImg = ee.Image().expression({\n expression: namedVarsExp,\n map: {\n NIR: img.select('SR_B5'),\n Red: img.select('SR_B4')\n }\n}).rename('NDVI');\nMap.addLayer(namedVarsImg, ndviVis, 'NDVI 3');\n\n// Expression using named variables with image band access by dot notation.\nvar namedVarsDotExp = '(ls8.SR_B5 - ls8.SR_B4) / (ls8.SR_B5 + ls8.SR_B4)';\nvar namedVarsDotImg = ee.Image().expression({\n expression: namedVarsDotExp,\n map: {ls8: img}\n}).rename('NDVI');\nMap.addLayer(namedVarsDotImg, ndviVis, 'NDVI 4');\n\n// Expressions can use arithmetic operators (+ - * / % **), relational\n// operators (== != \u003c \u003e \u003c= \u003e=), logical operators (&& || ! ^), the ternary\n// operator (condition ? ifTrue : ifFalse), and a subset of JavaScript Math\n// functions. Math functions are called by name directly, they are not accessed\n// from the Math object (e.g., sqrt() instead of Math.sqrt()).\nvar jsMathExp = 'c = sqrt(pow(a, 2) + pow(b, 2))';\nvar jsMathImg = ee.Image().expression({\n expression: jsMathExp,\n map: {\n a: ee.Image(5),\n b: img.select('SR_B2')\n }\n});\nMap.addLayer(jsMathImg, {min: 5000, max: 20000}, 'Hypotenuse', false);\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# The following expressions calculate the normalized difference vegetation\n# index (NDVI): (NIR - Red) / (NIR + Red).\n# NIR is Landsat 8 L2 band 'SR_B5', the 4th band index.\n# Red is Landsat 8 L2 band 'SR_B4', the 3rd band index.\n\n# A Landsat 8 L2 surface reflectance image.\nimg = ee.Image('LANDSAT/LC08/C02/T1_L2/LC08_044034_20210508')\n\n# Visualization parameters for NDVI.\nndvi_vis = {'min': 0, 'max': 0.5}\n\n# Expression using image band indices.\nband_index_exp = '(b(4) - b(3)) / (b(4) + b(3))'\nband_index_img = img.expression(band_index_exp).rename('NDVI')\nm = geemap.Map()\nm.set_center(-122.14, 37.38, 11)\nm.add_layer(band_index_img, ndvi_vis, 'NDVI 1')\n\n# Expression using image band names.\nband_name_exp = '(b(\"SR_B5\") - b(\"SR_B4\")) / (b(\"SR_B5\") + b(\"SR_B4\"))'\nband_name_img = img.expression(band_name_exp).rename('NDVI')\nm.add_layer(band_name_img, ndvi_vis, 'NDVI 2')\n\n# Expression using named variables.\nnamed_vars_exp = '(NIR - Red) / (NIR + Red)'\nnamed_vars_img = (\n ee.Image()\n .expression(\n expression=named_vars_exp,\n opt_map={'NIR': img.select('SR_B5'), 'Red': img.select('SR_B4')},\n )\n .rename('NDVI')\n)\nm.add_layer(named_vars_img, ndvi_vis, 'NDVI 3')\n\n# Expression using named variables with image band access by dot notation.\nnamed_vars_dot_exp = '(ls8.SR_B5 - ls8.SR_B4) / (ls8.SR_B5 + ls8.SR_B4)'\nnamed_vars_dot_img = (\n ee.Image()\n .expression(expression=named_vars_dot_exp, opt_map={'ls8': img})\n .rename('NDVI')\n)\nm.add_layer(named_vars_dot_img, ndvi_vis, 'NDVI 4')\n\n# Expressions can use arithmetic operators (+ - * / % **), relational\n# operators (== != \u003c \u003e \u003c= \u003e=), logical operators (&& || ! ^), the ternary\n# operator (condition ? ifTrue : ifFalse), and a subset of JavaScript Math\n# functions. Math functions are called by name directly, they are not accessed\n# from the Math object (e.g., sqrt() instead of Math.sqrt()).\njs_math_exp = 'c = sqrt(pow(a, 2) + pow(b, 2))'\njs_math_img = ee.Image().expression(\n expression=js_math_exp, opt_map={'a': ee.Image(5), 'b': img.select('SR_B2')}\n)\nm.add_layer(js_math_img, {'min': 5000, 'max': 20000}, 'Hypotenuse', False)\nm\n```"]]