0

I'm creating a custom image collection over a bound region as follows:

  1. Get image collection containing images taken by satellite in 7 days
var collection_to_covert_to_image = ee.ImageCollection("COPERNICUS/S2").filterDates(d1, d2).filterBounds(roi);
  1. Convert image collection to a single image:
var img = collection_to_convert_to_image.toBands(); 

Now this creates an image with bands list as a sum of all images in collection. Like instead of correct B1, B2, B3, B4, etc it is creating bands list having IMAGE_1_DATE_B1, ...IMAGE_1_DATE_B2, ..., IMAGE_2_DATE_B1, IMAGE_2_DATE_B2, ...

What I want the resulting combined image from image collection to have B1, B2, B3, B4, ...

  1. Repeat Steps 1 and 2 to get multiple 'combined' images and then creating image collection as follows:
var custom_col = ee.ImageCollection([ combined_img_1, combined_img_2, ... ]);

Finally to preview this collection, I add first image to the map:

Map.addLayer(custom_col.first(), { min: 0, max: 6000 });

But nothing gets displayed although layer is loaded. I believe this is because of new images not having proper B1, B2, etc bands

So how to make combined image that contains these bands as sum of child images' respective bands like e.g combined_img_B1 = img1_B1 + img2_B1 + ... in order to display it on map?

1 Answer 1

1

how to make combined image that contains these bands as sum of child images' respective bands

var img = collection_to_convert_to_image.sum();

You can also use .median(), .mean() and other such common mathematical operations.

The general tool is imageCollection.reduce(reducer) and then you can use any EE reducer to combine the images into one image; .sum() is a shortcut for .reduce(ee.Reducer.sum()) and so on.

2
  • Excellent! Thanks Kevin, it worked using .sum() But here's a small issue arising: It does create and show new combined image. But this image is showing edges of child images. They are not seen when showing initial image collection of children images on a map. Why is it so?
    – Waleed93
    Commented Jul 5, 2020 at 10:00
  • 1
    @Wallee When do Map.addLayer on an image collection, the default behavior is to mosaic the collection: at each pixel, to take the most recent image. That is available as the .mosaic() operation on collections. But if you take the sum, then the magnitude of the value will depend on the number of images being summed at each point. Thus, overlaps are brighter. I assumed since you asked for sum you wanted .sum(), but perhaps .mosaic() is what you want. Or .median() if you want the median of all the images rather than the most reent available image.
    – Kevin Reid
    Commented Jul 5, 2020 at 15:33

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.