[null,null,["最后更新时间 (UTC):2025-07-25。"],[[["\u003cp\u003e\u003ccode\u003eimage.reduceNeighborhood()\u003c/code\u003e applies a reducer within a sliding window (kernel) over an image.\u003c/p\u003e\n"],["\u003cp\u003eEach output pixel represents the reduction result from its surrounding neighborhood.\u003c/p\u003e\n"],["\u003cp\u003eKernels define the size and shape of the neighborhood used for calculations.\u003c/p\u003e\n"],["\u003cp\u003eAn example use case is calculating texture (standard deviation) of NDVI in NAIP imagery to identify landscape differences.\u003c/p\u003e\n"],["\u003cp\u003eNon-zero kernel values determine included pixels, with kernel weights applied by default.\u003c/p\u003e\n"]]],[],null,["# Statistics of Image Neighborhoods\n\nRather than specifying a region over which to perform a reduction, it is also possible\nto specify a neighborhood in which to apply a reducer. To reduce image neighborhoods, use\n`image.reduceNeighborhood()`. In this case, the reduction will\noccur in a sliding window over the input image, with the window size and shape specified\nby an `ee.Kernel`. The output of `reduceNeighborhood()` will be\nanother image, with each pixel value representing the output of the reduction in a\nneighborhood around that pixel in the input image. Figure 1 illustrates this type of\nreduction.\nFigure 1. Illustration of `reduceNeighborhood()`, where the reducer is applied in a kernel.\n\nFor example, consider using National Agriculture Imagery Program (NAIP) imagery to\nquantify landscape differences resulting from logging in the California redwood forests.\nSpecifically, use standard deviation (SD) in a neighborhood to represent the difference\nin texture between the logged area (SW of the image in Figure 2) and the protected area\n(NE of the image in Figure 2). For example, to get texture of a NAIP Normalized Difference\nVegetation Index (NDVI) image, use `reduceNeighborhood()` to compute SD\nin a neighborhood defined by a kernel:\n\n### Code Editor (JavaScript)\n\n```javascript\n// Define a region in the redwood forest.\nvar redwoods = ee.Geometry.Rectangle(-124.0665, 41.0739, -123.934, 41.2029);\n\n// Load input NAIP imagery and build a mosaic.\nvar naipCollection = ee.ImageCollection('USDA/NAIP/DOQQ')\n .filterBounds(redwoods)\n .filterDate('2012-01-01', '2012-12-31');\nvar naip = naipCollection.mosaic();\n\n// Compute NDVI from the NAIP imagery.\nvar naipNDVI = naip.normalizedDifference(['N', 'R']);\n\n// Compute standard deviation (SD) as texture of the NDVI.\nvar texture = naipNDVI.reduceNeighborhood({\n reducer: ee.Reducer.stdDev(),\n kernel: ee.Kernel.circle(7),\n});\n\n// Display the results.\nMap.centerObject(redwoods, 12);\nMap.addLayer(naip, {}, 'NAIP input imagery');\nMap.addLayer(naipNDVI, {min: -1, max: 1, palette: ['FF0000', '00FF00']}, 'NDVI');\nMap.addLayer(texture, {min: 0, max: 0.3}, 'SD of NDVI');\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# Define a region in the redwood forest.\nredwoods = ee.Geometry.Rectangle(-124.0665, 41.0739, -123.934, 41.2029)\n\n# Load input NAIP imagery and build a mosaic.\nnaip_collection = (\n ee.ImageCollection('USDA/NAIP/DOQQ')\n .filterBounds(redwoods)\n .filterDate('2012-01-01', '2012-12-31')\n)\nnaip = naip_collection.mosaic()\n\n# Compute NDVI from the NAIP imagery.\nnaip_ndvi = naip.normalizedDifference(['N', 'R'])\n\n# Compute standard deviation (SD) as texture of the NDVI.\ntexture = naip_ndvi.reduceNeighborhood(\n reducer=ee.Reducer.stdDev(), kernel=ee.Kernel.circle(7)\n)\n\n# Display the results.\nm = geemap.Map()\nm.center_object(redwoods, 12)\nm.add_layer(naip, {}, 'NAIP input imagery')\nm.add_layer(\n naip_ndvi, {'min': -1, 'max': 1, 'palette': ['FF0000', '00FF00']}, 'NDVI'\n)\nm.add_layer(texture, {'min': 0, 'max': 0.3}, 'SD of NDVI')\nm\n```\n\nAny pixel with a non-zero kernel value is included in the computation. The kernel\nweights are used by default, though you can change that behavior with the\n`inputWeight` argument. The input image and `reduceNeighborhood()`\noutput are compared in Figure 2. \nFigure 2a. NAIP imagery of the Northern California coast. \nFigure 2b. `reduceNeighborhood()` output using a standard deviation reducer."]]