1 - Create a function to:
- calculate the area in hectares for each of the two bands of "imagebands1" ('vereda','arenizacao') and "imagebands2" ('vereda','freq_arenizacao');
- calculate the percentage of each of the two bands of each image as well;
- insert the result (area and percentage) in the properties of each feature of the featurecollection "table4" (apply ".map()" on table4);
The result should be the area of ​​the veredas and the sandblasting as a property in each feature of the featurecollection table4.
2 - Create another function to:
- generate an image with a constant value for each feature (put the value of the area calculated and inserted as a property previously);
- use "mosaic" to generate the final image;
- generate the visualization of the final image;
The result should be an image that shows the percentage in its colors
Here is the script example: Map.setOptions("SATELLITE"); // "ROADMAP", "SATELLITE", "HYBRID" or "TERRAIN"

var geometry = 
    ee.Geometry.Polygon(
        [[[-48.90990751290743, -8.920219511710798],
          [-48.90990751290743, -16.649225798686256],
          [-42.66967313790743, -16.649225798686256],
          [-42.66967313790743, -8.920219511710798]]], null, false);

var table4 = ee.FeatureCollection("projects/ee-maximoicmbio/assets/ottobacias_n5_urucuia_veredas_doc");

Map.addLayer(table4, {}, 'teste')

var veredasmapbiomasfreq = ee.FeatureCollection("users/maximomenezesgee/Otto_4_Urucuia_mapbiomas_veredas_Union2");
var arenizacao = ee.FeatureCollection("users/maximomenezesgee/Otto_4_Urucuia_Landsat_Union_arenizacao3");

var mascara1 = ee.Image(100).toInt().clip(veredasmapbiomasfreq);
var mascara2 = ee.Image(200).toInt().clip(arenizacao);

var mascara3 = ee.Image([mascara2, mascara1])
  .reduce(ee.Reducer.firstNonNull());

var verd_areniz1 = ee.Image("users/maximomenezesgee/campo_arenizacao_landsat_doutorado_raster")
  .select('arenizacao_count')
  .updateMask(mascara3);

var verd_areniz = ee.Image(300).toInt().updateMask(verd_areniz1);

var imagebands1 = ee.Image([
  mascara3.updateMask(mascara3.eq(100)),
  mascara3.updateMask(mascara3.eq(200))
]).rename('vereda', 'arenizacao');

var mascara4 = ee.Image([verd_areniz, mascara1])
  .reduce(ee.Reducer.firstNonNull());

var imagebands2 = ee.Image([
  mascara4.updateMask(mascara4.eq(100)),
  mascara4.updateMask(mascara4.eq(300))
]).rename('vereda','freq_arenizacao');
print(imagebands2)

Map.addLayer(imagebands1.select('vereda'), {
  min: 1,
  max: 200,
  palette: ['#9400D3', '#4B0082', '#0000FF', '#00FF00', '#FFFF00', '#FF7F00', '#FF0000']
}, 'Arenizacao_freq');

Map.addLayer(imagebands1.select('arenizacao'), {
  min: 1,
  max: 200,
  palette: ['#9400D3', '#4B0082', '#0000FF', '#00FF00', '#FFFF00', '#FF7F00', '#FF0000']
}, 'Arenizacao', null, 0.4);

// Função para calcular a área em hectares
var calculateArea = function(image) {
  var areaImage = image.multiply(ee.Image.pixelArea()).divide(10000); // Convert to hectares
  var totalArea = areaImage.reduceRegion({
    reducer: ee.Reducer.sum(),
    geometry: geometry,
    scale: 30,
    maxPixels: 1e9,
    bestEffort: true
  });
  
  return ee.Number(totalArea.get(image.bandNames().get(0))); // Retorna um ee.Number
};

// Calcula a área para cada classe na imagem
var areaVereda = calculateArea(imagebands1.select('vereda'));
var areaArenizacao = calculateArea(imagebands1.select('arenizacao'));

// Total da área
var totalArea = areaVereda.add(areaArenizacao);

//print(areaVereda, 'areaVereda')
//print(areaArenizacao, 'areaArenizacao')
//print(totalArea, 'totalArea')

// Calcula a porcentagem
var percentageVereda = areaVereda.divide(totalArea).multiply(100);
var percentageArenizacao = areaArenizacao.divide(totalArea).multiply(100);

// Prepara os dados para o gráfico de pizza
var pieChartData = ee.FeatureCollection([
  ee.Feature(null, {label: 'Vereda', area: percentageVereda}),
  ee.Feature(null, {label: 'Arenização', area: percentageArenizacao})
]);

var chart1 = ui.Chart.feature.byFeature(pieChartData, 'label', 'area')
  .setChartType('PieChart')//'ScatterChart', 'LineChart', 'ColumnChart', PieChart
  .setOptions({
    title: 'Porcentagem arenização',
    colors: ['#FF0000', '#00FF00'],
  });
print(chart1);

// Calcula a área para a frequência
var areaFreqVereda = calculateArea(imagebands2.select('vereda'));
var areaFreqArenizacao = calculateArea(imagebands2.select('freq_arenizacao'));

// Total da área de frequência
var totalFreqArea = areaFreqVereda.add(areaFreqArenizacao);

// Calcula a porcentagem de frequência
var percentageFreqVereda = areaFreqVereda.divide(totalFreqArea).multiply(100);
var percentageFreqArenizacao = areaFreqArenizacao.divide(totalFreqArea).multiply(100);

// Prepara os dados para o gráfico de pizza de frequência
var pieChartFreqData = ee.FeatureCollection([
  ee.Feature(null, {label: 'Vereda', area: percentageFreqVereda}),
  ee.Feature(null, {label: 'Frequência Arenização', area: percentageFreqArenizacao})
]);

var chart2 = ui.Chart.feature.byFeature(pieChartFreqData, 'label', 'area')
  .setChartType('PieChart')//'ScatterChart', 'LineChart', 'ColumnChart', 'PieChart'
  .setOptions({
    title: 'Porcentagem arenização (frequência)',
    colors: ['#FF0000', '#00FF00'],
  });
print(chart2);