I am working on Sentinel-1 images. I have created a mosaic and want to apply functions related to band mathematics on it.

//Define the time interval
var start_date = ee.Date('2021-11-15');
var end_date = start_date.advance(5,'days');
var date_filter = ee.Filter.date(start_date, end_date);

// Filter the collection for the VV product from the descending track
var collection1 = ee.ImageCollection('COPERNICUS/S1_GRD')
    .filter(ee.Filter.eq('instrumentMode', 'IW'))
    //.filter(ee.Filter.listContains('transmitterReceiverPolarisation', 'VV'))
    .filter(ee.Filter.eq('orbitProperties_pass', 'DESCENDING'))
    .filterMetadata ('resolution_meters', 'equals', 10)
    // .select(['VV','angle']);
var vis_paraVV = {bands:'VV', min:-25, max:5};
var vis_paraVH = {bands:'VH', min:-25, max:5};
var vis_paraAN = {bands:'angle', min:30.3, max:46.8};
Map.centerObject(roi, 6);

var Mo_VVVH1 = collection1.select(['VV','VH']).mosaic().clip(roi);
var Mo_Angl1 = collection1.select(['Angle']).mosaic().clip(roi);
// var VH_mosaic = collection1.select(['VH']).mosaic();
// var AN_mosaic = collection1.select(['angle']).mosaic();

//////Speckel Filter boxcar
var boxcar = ee.Kernel.square({ radius: 1.5, units: 'pixels', normalize: true});

////apply filter to VV and VH
var Mo_VVVH1 = Mo_VVVH1.convolve(boxcar);

function addVHminusVV(image) {
  var VHminusVV = ((image.select('VH')).subtract(image.select('VV'))).rename('Diff');
  return image.addBands(VHminusVV);
function addVHbyVV(image) {
  var VHbyVV = (image.select('VH')).divide(image.select('VV')).rename('Div');return image.addBands(VHbyVV);

If it's for image collection we can do following

var collection = collection1.map(addVHminusVV).map(addVHbyVV)

but how to do it for an image?

1 Answer 1

var yourVariable = addVHminusVV(yourImage)


var doubleFunction = addVHbyVV(addVHminusVV(Mo_VVVH1))
print(doubleFunction, 'doubleFunction')

But why not put it in one function like this:

function oneFunction(image) {
  var VHminusVV = ((image.select('VH')).subtract(image.select('VV'))).rename('Diff');
  var VHbyVV = (image.select('VH')).divide(image.select('VV')).rename('Div');
  return image.addBands(VHminusVV).addBands(VHbyVV);

var applyIt = oneFunction(Mo_VVVH1)
print(applyIt, 'oneFunction')


  • I want to map all functions at same time like we can do with image collection
    – Monish
    Commented Feb 11, 2022 at 10:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.