AI-generated Key Takeaways
-
Generates a chart displaying the frequency distribution of pixel values within a specified image region.
-
The chart plots histograms for each band of the image, showing the number of pixels with values falling within specific ranges (buckets).
-
Users can customize the chart by defining the region, scale, and bucket parameters, as well as the maximum number of input values and pixels used in the calculation.
-
The chart is rendered with customizable axes, titles, and color options for each band.
-
ui.Chart.image.histogram()
returns aui.Chart
object, allowing for further manipulation and display within the Earth Engine Code Editor.
- X-axis: Histogram buckets (of band value).
- Y-axis: Frequency (number of pixels with a band value in the bucket).
Returns a chart.
Usage | Returns |
---|---|
ui.Chart.image.histogram(image, region, scale, maxBuckets, minBucketWidth, maxRaw, maxPixels) | ui.Chart |
Argument | Type | Details |
---|---|---|
image | Image | The image to generate a histogram from. |
region | Feature|FeatureCollection|Geometry, optional | The region to reduce. If omitted, uses the entire image. |
scale | Number, optional | The pixel scale used when applying the histogram reducer, in meters. |
maxBuckets | Number, optional | The maximum number of buckets to use when building a histogram; will be rounded up to a power of 2. |
minBucketWidth | Number, optional | The minimum histogram bucket width, or null to allow any power of 2. |
maxRaw | Number, optional | The number of values to accumulate before building the initial histogram. |
maxPixels | Number, optional | If specified, overrides the maximum number of pixels allowed in the histogram reduction. Defaults to 1e6. |
Examples
Code Editor (JavaScript)
// Define a MODIS surface reflectance composite. var modisSr = ee.ImageCollection('MODIS/006/MOD09A1') .filter(ee.Filter.date('2018-06-01', '2018-09-01')) .select(['sur_refl_b01', 'sur_refl_b02', 'sur_refl_b06']) .mean(); // Define a region to calculate histogram for. var histRegion = ee.Geometry.Rectangle([-112.60, 40.60, -111.18, 41.22]); // Define the chart and print it to the console. var chart = ui.Chart.image.histogram({image: modisSr, region: histRegion, scale: 500}) .setSeriesNames(['Red', 'NIR', 'SWIR']) .setOptions({ title: 'MODIS SR Reflectance Histogram', hAxis: { title: 'Reflectance (scaled by 1e4)', titleTextStyle: {italic: false, bold: true}, }, vAxis: {title: 'Count', titleTextStyle: {italic: false, bold: true}}, colors: ['cf513e', '1d6b99', 'f0af07'] }); print(chart);