I want that all the images in my imagecollection will contain only one band ('VH_Filtered').
The problem is that whenever I ask GEE to display the images in the imagecollection, I can see that the images display the original band and not the VH_Filtered and I don't understand why.
This is my code:
//Filter the collection for the VH product from the descending track
var Sentinel1 = ee.ImageCollection('COPERNICUS/S1_GRD')
.filter(ee.Filter.listContains('transmitterReceiverPolarisation', 'VH'))
.filter(ee.Filter.eq('orbitProperties_pass', 'DESCENDING'))
.filter(ee.Filter.eq('instrumentMode', 'IW'))
.select('VH')
.filterDate('2019-01-01','2019-11-12')
.filterBounds(geometry);
//Clip the image collection
var clippedVH= Sentinel1.map(function(im){
return im.clip(geometry);
});
//apply Filter
var filterSpeckles = function(img) {
var vh = img.select('VH') ;//select the VH polarization band
var VH_smoothed = vh.focal_median(35,'circle','meters').rename('VH_Filtered'); //Apply a focal median filter
return img.addBands(VH_smoothed); // Add filtered VH band to original image
};
var Clipped_Speckles = clippedVH.map(filterSpeckles);
print(Clipped_Speckles);
//check that speckle filter worked
var list_before=clippedVH.toList(clippedVH.size());
var list_after=Clipped_Speckles.toList(Clipped_Speckles.size());
var before=ee.Image(list_before.get(0));
var after=ee.Image(list_after.get(0)).clip(geometry).select('VH_Filtered');
//Map.addLayer(before,{min: -30, max: 1},'Before');
//Map.addLayer(after,{bands: 'VH_Filtered',min: -30, max: 1},'after');
// var clippedVHsize=clippedVH.size();
// print('SAR Size:',clippedVHsize);
// print('SAR images data:',clippedVH);
var listOfImagesSAR =(Clipped_Speckles.toList(Clipped_Speckles.size()));
var NumberOfImagesSAR=listOfImagesSAR.size();
var listOfNumbersSAR = ee.List.sequence(0, NumberOfImagesSAR.subtract(2));
listOfNumbersSAR = listOfNumbersSAR.map(function(n) {
return ee.Number(n).add(1);
});
print(typeof(listOfNumbersSAR));
listOfNumbersSAR=listOfNumbersSAR.getInfo();
for (var i in listOfNumbersSAR) {
var image = ee.Image(listOfImagesSAR.get(listOfNumbersSAR[i]));
var toexport=image.visualize({min: -30, max: 1}).addBands(image);
//Add the layer- here I can see it didnt work
Map.addLayer(image,{min: -30, max: 1},'SAR'+ i);
// Export.image.toDrive({
// image: toexport.toFloat(),
// description: i,
// scale:10,
// crs:'EPSG:4326',
// maxPixels:1310361348,
// region:geometry.geometry().bounds()
// });
}
The area is in Thailand so any polygon there wouold work.
my end goal: to have imagecolelction with only one band.
Best Answer
The images you are displaying are from your
Clipped_Speckles
, andfilterSpeckles
creates those images by adding a band called'VH_Filtered'
to the existing bands (the one band'VH'
). So if you want only that band, you shouldreturn VH_smoothed;
instead of usingaddBands
at all.If you want to keep the
'VH'
band around for further processing, but displayVH_Filtered
on the map, then you need to either do aselect
before displaying the image (I see you have a suitableselect
on the line that startsvar after=ee.Image...
but that isn't being used later so it doesn't have any effect); or you could specify the bands in the visualization parameters toMap.addLayer
: