I have an image with 3 distinct value (0,1,2), and use the frequency histogram reducer to count frequency of each pixel value in certain geometry (sort of like a zonal statistic function).
I am trying to export the result of the frequency histogram to a CSV file, but it always returns an error saying "Invalid argument: 'collection' must be a FeatureCollection."
Is there a way to convert the frequency histogram object into a feature collection? OR even better, any other straight forward method to export that simple table as CSV?
Here's snippet of my code:
// COUNT EACH PIXEL VALUE FREQUENCY (ZONAL STATS)
var stats = primary2020.reduceRegion({
reducer: ee.Reducer.frequencyHistogram(),
geometry: geometry,
scale: 30,
maxPixels: 1e15
});
print(stats)
// EXPORT TABLE TO DRIVE
Export.table.toDrive({
collection: stats,
description: 'PrimaryForest2020stats',
fileFormat: 'CSV',
});