Reputation: 169
I would like to have a look at my raster statistics, similar to freq(raster)
in R, but in Google Earth Engine. I would like to know which pixel value appears how often (it is a classified raster). I can't seem to find the right ee function for this. Can anyone help?
Upvotes: 1
Views: 481
Reputation: 1300
These kind of statistics may require or NOT a region over which things are be computed depending on whether you are dealing with a bounded or an unbounded image. So, let's have a region of interest first:
var region =
/* color: #98ff00 */
/* displayProperties: [
{
"type": "rectangle"
}
] */
ee.Geometry.Polygon(
[[[-111.4018515625, 42.568784561631375],
[-111.4018515625, 35.47803445034791],
[-91.62646093750003, 35.47803445034791],
[-91.62646093750003, 42.568784561631375]]], null, false);
Now, we can load a classified image. Let's assume the IGBP classification since you mentioned a classified image and you didn't provide any:
var image = ee.Image('MODIS/051/MCD12Q1/2012_01_01')
.select('Land_Cover_Type_1');
If you want the frequencies as raw values, you can reduce the classified image as follows:
var freq = image.reduceRegion({
reducer: ee.Reducer.frequencyHistogram(),
geometry: region,
scale: 100
});
print(freq);
If you want a chart, you can use ui.Chart.image.histogram
as follows:
var chart = ui.Chart.image.histogram({
image: image,
region: region,
scale: 100
});
print(chart)
Upvotes: 1