코드 ee.Terrain.slope(srtm)에서 srtm 이미지가 경사 알고리즘의 인수로 제공됩니다. 결과는 그림 3과 같이 표시됩니다.
그림 3. 경사 이미지
이미지 수학
이미지 객체에서 호출할 수 있는 ee.Image 클래스의 메서드도 있습니다. 예를 들어 이미지 밴드를 사용하여 수학을 수행한다고 가정해 보겠습니다 (밴드 수학 또는 지도 대수라고도 함). 예를 들어 측면 이미지에 대한 삼각 함수 연산에 관심이 있을 수 있습니다. 이렇게 하려면 먼저 종횡비 이미지를 라디안으로 변환한 다음 sin()를 호출합니다. srtm 이미지를 재사용합니다.
결과는 그림 4와 같이 표시됩니다. aspect.divide(180).multiply(Math.PI).sin() 코드를 자세히 살펴보는 것이 좋습니다. 이와 같이 여러 메서드를 연결하면 코드는 '종횡비를 180으로 나누고 그 결과를 π로 곱한 다음 최종적으로 sin을 취하라'고 말합니다. 이러한 방식으로 메서드를 결합하여 이미지에 복잡한 수학 연산을 실행할 수 있습니다. 수학 연산, add(), subtract(), multiply() 등의 전체 목록은 Image 문서를 참고하세요.
그림 4. 지형 측면의 죄.
이미지 통계
이미지에서 유용한 또 다른 작업 클래스는 이미지 영역 또는 래스터-벡터 오버레이에서 픽셀 통계를 계산하는 것입니다. Earth Engine에서 통계를 계산하려면 ee.Reducer 패키지의 클래스로 표시되는 리듀서를 사용합니다. 예를 들어 특정 지역의 평균 고도에 관심이 있다고 가정해 보겠습니다. 기하학적 도형 그리기 도구를 사용하여 다각형을 그려 리전을 정의할 수 있습니다.
영역을 대화형으로 그리려면 다각형 그리기 도구()를 가져온 다음 관심 영역 위에 다각형을 디지털화하고 완료되면 나가기를 클릭합니다. 결과 ee.Geometry 객체는 자동으로 geometry로 이름이 지정되고 스크립트 상단에 가져오기로 추가됩니다. 가져오기에서 변수 이름을 클릭하고 새 이름을 입력하여 변수 이름을 'polygon'으로 변경합니다.
여기에서 몇 가지 사항을 확인해야 합니다. 먼저 reduceRegion()는 Image 객체에 사용할 수 있는 메서드입니다 (여기에서 지역 축소에 대해 자세히 알아보기). 두 번째로 메서드 인수는 단일 인수로 전달되는 JavaScript 객체에 제공됩니다. (구체적으로 객체의 키는 메서드 매개변수의 이름입니다. 값은 메서드의 인수입니다. 셋째, reducer 매개변수는 계산할 통계 유형을 지정하고 geometry 매개변수는 통계를 계산할 리전을 지정합니다. scale 매개변수는 사용할 픽셀 크기(미터)입니다. 모호성을 방지하려면 축소할 때 항상 스케일을 지정해야 합니다. Earth Engine에서 입력으로부터 적절한 스케일을 자동으로 결정하지 못할 수 있기 때문입니다.
(Earth Engine의 스케일 자세히 알아보기)
마지막으로 reduceRegion()의 반환 값은 키가 밴드 이름이고 값이 밴드의 픽셀 통계인 사전입니다. 사전의 get() 메서드는 인수로 제공된 키에 해당하는 값을 반환합니다. 이 경우 srtm 이미지에는 'elevation'이라는 밴드가 하나 있으므로 예시 코드는 딕셔너리에서 해당 통계를 가져와 출력합니다.
이 코드를 실행할 때 다음과 같은 오류가 표시되면
걱정하지 마세요. 오류를 해결하기 위해 할 수 있는 몇 가지 방법이 있습니다. reduceRegion() 메서드에는 계산에 이렇게 많은 픽셀을 포함할지 여부를 고려하도록 하는 검사가 있습니다. 이는 전 세계의 모든 1미터 픽셀의 평균을 계산하는 것과 같은 어리석은 작업을 실수로 실행하지 않도록 하기 위한 것입니다 (이러한 작업을 실행하지 마세요). 이 오류를 해결하려면 매개변수 사전에 bestEffort: true를 추가하여 bestEffort 매개변수를 true로 설정하거나 maxPixels 매개변수를 기본값인 1,000만 픽셀보다 높은 값으로 설정하세요. bestEffort가 true이면 Earth Engine에서 maxPixels를 초과하지 않도록 자동으로 스케일을 다시 계산합니다.
여담: Earth Engine의 스케일
이전 예에서 scale은 SRTM 이미지의 기본 해상도에 가깝게 설정됩니다. 다음 명령어를 사용하여 이미지의 기본 해상도를 확인할 수 있습니다.
기본 해상도보다 작은 스케일을 지정하면 Earth Engine에서 가장 가까운 이웃을 사용하여 입력 이미지를 리샘플링한 다음 이러한 작은 픽셀을 모두 계산에 포함합니다. 스케일을 더 크게 설정하면 Earth Engine에서 집계된 버전의 입력에서 입력 픽셀을 사용합니다 (즉, 이미지 피라미드의 상위 수준에서 픽셀을 가져옴). Earth Engine에서 규모를 처리하는 방법을 이 문서에서 자세히 알아보세요.
지금까지는 단일 밴드가 있는 단일 이미지를 사용했습니다. 다음 페이지에서는 다중 밴드 이미지와 이미지 컬렉션에 대해 알아봅니다.
[null,null,["최종 업데이트: 2025-07-26(UTC)"],[[["\u003cp\u003eThis tutorial demonstrates how to apply computations to images in Earth Engine, such as calculating slope and performing trigonometric operations on bands.\u003c/p\u003e\n"],["\u003cp\u003eIt explains the use of reducers for computing image statistics within regions, like finding the mean elevation within a polygon.\u003c/p\u003e\n"],["\u003cp\u003eThe tutorial highlights the importance of scale in Earth Engine and how to handle errors related to exceeding the pixel limit in computations.\u003c/p\u003e\n"],["\u003cp\u003eIt also introduces the concept of band math, chaining methods for complex operations, and accessing image metadata like native resolution.\u003c/p\u003e\n"],["\u003cp\u003eUsers are guided on how to draw polygons for region-based calculations and provided with links to relevant documentation for further exploration.\u003c/p\u003e\n"]]],[],null,["# Computations using Images\n\nNow that you know how to load and display an image, it's time to apply a computation to it.\nFor example, you can compute the slope of terrain, by passing the SRTM elevation image to the\n[`slope` method of the `ee.Terrain`\npackage](/earth-engine/apidocs/ee-terrain-slope).\n\n### Code Editor (JavaScript)\n\n```javascript\n// Load the SRTM image.\nvar srtm = ee.Image('CGIAR/SRTM90_V4');\n\n// Apply an algorithm to an image.\nvar slope = ee.Terrain.slope(srtm);\n\n// Display the result.\nMap.setCenter(-112.8598, 36.2841, 9); // Center on the Grand Canyon.\nMap.addLayer(slope, {min: 0, max :60}, 'slope');\n```\n\nNote that in the code `ee.Terrain.slope(srtm)`, the `srtm` image is\nprovided as an argument to the slope algorithm. The result should look something like\nFigure 3.\nFigure 3. Slope image.\n\nImage math\n----------\n\nThere are also methods in the `ee.Image` class that can be invoked on an\nimage object. For example, suppose you'd like to do some math using image bands (sometimes\ncalled *band math* or *map algebra* ). For example, you may be interested in\ntrigonometric operations on an aspect image. To accomplish that, first convert an\naspect image to radians, then call `sin()` on it. Reusing our `srtm`\nimage,\n\n### Code Editor (JavaScript)\n\n```javascript\n// Get the aspect (in degrees).\nvar aspect = ee.Terrain.aspect(srtm);\n\n// Convert to radians, compute the sin of the aspect.\nvar sinImage = aspect.divide(180).multiply(Math.PI).sin();\n\n// Display the result.\nMap.addLayer(sinImage, {min: -1, max: 1}, 'sin');\n```\n\nThe result should look something like Figure 4. It's worth taking a closer look at the\n`aspect.divide(180).multiply(Math.PI).sin()` code. By chaining multiple methods\nlike this, the code says, 'divide the aspect by 180, multiply the result of that by\nπ, and finally take the sin'. You can perform complex mathematical operations on\nimages by combining methods in this manner. See the\n[`Image` docs](/earth-engine/apidocs/ee-image) for a complete list of mathematical\noperations, `add()`, `subtract()`, `multiply()`, etc.\nFigure 4. Sin of terrain aspect.\n\nImage statistics\n----------------\n\nAnother useful class of operations on images involves computing pixel statistics in image\nregions, or raster-vector overlays. To compute statistics in Earth Engine, use a\n*reducer* as represented by classes in the\n[`ee.Reducer` package](/earth-engine/guides/reducers_intro). For example, suppose\nyou're interested in the mean of elevation in some region. You can define a region by\ndrawing a polygon using the [geometry drawing tools](/earth-engine/guides/playground#geometry-tools).\nTo interactively draw a region, get the polygon drawing tool\n(), then digitize a polygon over your\narea of interest and click **Exit** when you're done. Note that the resultant\n`ee.Geometry` object is automatically named `geometry` and added\nas an import at the top of your script. Rename that variable to 'polygon' by clicking\non the variable name in the imports and typing the new name.\n\nNext, get the mean pixel value in the polygon using the following code:\n\n### Code Editor (JavaScript)\n\n```javascript\n// Compute the mean elevation in the polygon.\nvar meanDict = srtm.reduceRegion({\n reducer: ee.Reducer.mean(),\n geometry: polygon,\n scale: 90\n});\n\n// Get the mean from the dictionary and print it.\nvar mean = meanDict.get('elevation');\nprint('Mean elevation', mean);\n```\n\nThere are several things to note here. First, observe that `reduceRegion()` is\na method available for `Image` objects ([learn\nmore about reducing regions here](/earth-engine/guides/reducers_reduce_region)). Second, the method arguments are provided in a\nJavaScript object that is passed as a single argument. (Specifically, the keys of the\nobject are the names of the method parameters. The values are the arguments to the\nmethod). Third, the `reducer` parameter specifies the type of statistic to\ncompute and the `geometry` parameter specifies the region in which to compute\nthe statistic. The `scale` parameter is the pixel size in meters to use. To\navoid ambiguity, you should always specify scale when doing reductions as Earth Engine\nmay not be able to automatically determine the appropriate scale from the inputs.\n([Learn more about scale in Earth Engine](/earth-engine/guides/scale)).\n\nLastly, the return value of `reduceRegion()` is a dictionary\nin which keys are band names and values are the pixel statistics for the bands. The\n`get()` method on a dictionary returns the value corresponding to the key\nprovided as an argument. In this case, the `srtm` image has one band,\n'elevation', so the example code gets that statistic from the dictionary and prints it.\n\nWhen you run this code, if you get an error that looks like:\n| ComputedObject (Error) \n| Image.reduceRegion: Too many pixels in the region. Found 527001545, but only 10000000 allowed. \n\nFear not! There are several things you can do to resolve the error. The\n`reduceRegion()` method has a check to make sure you consider whether you\nreally want to include so many pixels in your computation. This is intended to prevent\nyou from accidentally doing something silly, like trying compute the mean of every\none-meter pixel in the world (don't do that). To resolve the error, either set the\n`bestEffort` parameter to `true` by adding `bestEffort: true`\nto the dictionary of parameters, or set the `maxPixels` parameter to a value\nhigher than the default of 10 million pixels, or both. If `bestEffort` is\ntrue, Earth Engine will automatically recompute the scale such that `maxPixels`\nis not exceeded.\n\nDigression: Scale in Earth Engine\n---------------------------------\n\nIn the previous example, `scale` is set to approximately the native resolution\nof the SRTM image. You can discover the native resolution of an image with:\n\n### Code Editor (JavaScript)\n\n```javascript\nvar scale = srtm.projection().nominalScale();\nprint('SRTM scale in meters', scale);\n```\n\nIf you specify a scale smaller than the native resolution, Earth Engine will happily\nresample the input image using nearest neighbor, then include all those smaller pixels in the\ncomputation. If you set the scale to be larger, Earth Engine will use input pixels from\nan aggregated version of the input (i.e. get pixels from a higher level of the image\npyramid). Learn more about how Earth Engine handles scale in\n[this doc](/earth-engine/guides/scale).\n\nSo far, you've been working with a single image with a single band. In the next page, you'll\nlearn about multi-band images and image collections. \n[arrow_backPrevious page](/earth-engine/tutorials/tutorial_api_02) [Next pagearrow_forward](/earth-engine/tutorials/tutorial_api_04)"]]