0

Can someone please help me to write the code for the Validation of the classified images resulted from a fusion between Landsat and Corona images.

The code below but I keep getting errors about the validation using the classified images.

var acqDate = ee.Date('1976-08-13')

var images = ee.ImageCollection([
  samadi.set('name', 'Samadi'),
  khatmeen.set('name', 'Khatmeen'),
  kasba.set('name', 'Kasba')
])

// Find Landsat imagery and compute texture from Corona image
var getLandSatAndTexture = function(image) {
  // We find the closest landsat imagery
  var filtered = l1_t1.merge(l1_t2)
  .filter(ee.Filter.bounds(image.geometry()))

  var withTimeDiff = filtered.map(function (image) {
    var diff = acqDate.difference(
      image.get('system:time_start'), 'day')
    return image.set('dayDiff', ee.Number(diff).abs())
  })
  // We find the closest landsat imagery
  var landsat = ee.Image(withTimeDiff.sort('dayDiff').first())
  var texture = image.glcmTexture(3)
  return image.addBands(texture).addBands(landsat)
}

var imagesWithBands = images.map(getLandSatAndTexture)
var label = 'class';
var imageBand = ee.List(['b1'])
var landsatBands= ee.List(['B7', 'B6', 'B5', 'B4'])
var textureBands = ee.List(['b1_contrast', 'b1_ent', 'b1_var', 'b1_corr'])
var bands = imageBand.cat(landsatBands).cat(textureBands)
Map.addLayer(imagesWithBands.select(landsatBands))

var trainingImage = imagesWithBands.mosaic();
var trainingPoints = vegetation.merge(barren).merge(built)
var training = trainingImage.sampleRegions({
  collection: trainingPoints,
  properties: [label],
  scale: 5
});
var trained = ee.Classifier.svm().train(training, label, bands);

var classifiedImages = imagesWithBands.map(function(image) {
  var classified = image.select(bands).classify(trained);
  return classified
    .select('classification')
    .clip(image.geometry())
    .set('name', image.get('name'))
})

var vizParams = {min:1, max:3, palette: ['#44d649', '#aadcff', '#8b8753']}
//Map.centerObject(image)
//Map.addLayer(landsat, {bands: ['B6', 'B5', 'B4']})
Map.addLayer(images)
Map.addLayer(classifiedImages, {min:1, max:3, palette: ['#44d649', '#aadcff', '#8b8753']})

var visualized = classifiedImages.map(function(image) {
  return image.visualize(vizParams).set('name', image.get('name'))
})

var doExport = function() {
  print('Working')
  var ids = visualized.aggregate_array('system:index');
  // evaluate() will not block the UI and once the result is available
  // will be passed-on to the callback function where we will call
  // Export.image.toDrive()
  ids.evaluate(function(imageIds) {
    print('Total number of images', imageIds.length)
    print('Exporting now... (see Tasks tab)')
    for(var i = 0; i < imageIds.length; i++) {

      // Filter using the image id
      var image = ee.Image(visualized.toList(1, i).get(0));
      var name= image.get('name').getInfo()
      Export.image.toDrive({
        image: image,
        region: image.geometry(),
        scale: 10,
        fileNamePrefix: name + '_classified',
        folder: 'earthengine',
        description: 'Export_' + i + '_' + name
      })
      }
  })
}

print('Click button below to start export')
var button = ui.Button({label: 'Export', onClick: doExport})
print(button)

///////////////////Classification validation
//Merge into one FeatureCollection

var vtrainingPoints = vvegetation.merge(vbarren).merge(vbuilt)

//Sample your classification results to your new validation areas
var validation = classified.sampleRegions({
  collection: vtrainingPoints,
  properties: [label],
  scale: 10,
});

print(validation);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.