> For the complete documentation index, see [llms.txt](https://guides.geospatial.bas.ac.uk/intro-to-google-earth-engine/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://guides.geospatial.bas.ac.uk/intro-to-google-earth-engine/how-to-use-google-earth-engine/using-the-code-editor/objects-and-methods/ee.imagecollection.md).

# ee.ImageCollection

Adding an Image on it's own is useful, but sometimes it's easier to search through a collection of images and filter according to their properties. &#x20;

The Data Catalog supplies Images often as part of an **ImageCollection**, which is a stack or sequence of Images. &#x20;

### Sentinel ImageCollection

Here, we're going to look through the Sentinel Collections, made available by the European Commission and European Space Agency's Copernicus Program.  It contains vast amounts of data which can be explored in the GEE Data Catalog:&#x20;

![Screenshot of the Sentinel Collection in the GEE data catalog https://developers.google.com/earth-engine/datasets/catalog/sentinel](https://129913967-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MjiZCnjzRgyoE8jhoZV%2Fuploads%2FWk33fdzuzh8d4CEts0Tk%2Fimage.png?alt=media\&token=2b570939-852e-4244-bdf7-941c96ae9e14)

Adding a Collection is straightforward - Earth Engine supplies a snippet that can be copied and used in Code Editor:&#x20;

![S2a MSI  ImageCollection landing page, GEE Data Catalog ](https://129913967-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MjiZCnjzRgyoE8jhoZV%2Fuploads%2FGZhhlwQf6TVjsnIJ04Sx%2Fimage.png?alt=media\&token=5164a8a5-46db-4213-ae00-8bf83d8e8dec)

### Filtering an Image

You can filter an **ImageCollection** by dataset properties, such as dates, spatial extent, quality etc. &#x20;

For the polar regions, it is useful to filter by date to remove times without sunlight, area of interest, or cloud cover. &#x20;

You can also chain filters so you apply them all at once:&#x20;

```javascript
var s2_filter = ee.ImageCollection('COPERNICUS/S2_SR')  
                .filterDate('2022-01-01', '2022-05-01')  
                .filterBounds(ee.Geometry.Point(-68.124, -67.5679))  
                .filter('CLOUDY_PIXEL_PERCENTAGE < 50');
```

### Sorting an ImageCollection&#x20;

Sometimes it is useful to sort a collection by properties such as by observation time, cloud cover etc.&#x20;

{% hint style="info" %}
**`ee.ImageCollection('').sort('property')`**&#x20;
{% endhint %}

This can look like:&#x20;

```javascript
var s2_sort_obs = ee.ImageCollection('COPERNICUS/S2_SR')
  .filterBounds(ee.Geometry.Point(-68.124, -67.5679))
  .filterDate('2022-11-01', '2022-03-01')  
  // Sort by observation time:
  .sort('system:time_start');
```

Or by cloudiness:&#x20;

```javascript
var s2_sort_clouds = ee.ImageCollection('COPERNICUS/S2_SR')
  .filterBounds(ee.Geometry.Point(-68.124, -67.5679))
  .filterDate('2022-01-01', '2022-05-01')
  // Sort by Cloud parameter: 
  .sort('CLOUDY_PIXEL_PERCENTAGE');
```

{% hint style="success" %}
Each **ImageCollection** has different parameters, according to the instrument that captured the data.  You can read more about each **ImageCollection** in the **Data Catalog**
{% endhint %}

### Reducing Images

Filtering an **ImageCollection** often results with multiple images. &#x20;

This can be reviewed in the **CodeEditor** by printing the results in the Console:&#x20;

```javascript
var s2_filter = ee.ImageCollection('COPERNICUS/S2_SR')  
                .filterDate('2021-09-01', '2022-03-01')  
                .filterBounds(ee.Geometry.Point(-68.124, -67.5679))  
                .filter('CLOUDY_PIXEL_PERCENTAGE < 50')
                
var s2_filter_rgb = s2_filter.select(['B4', 'B3', 'B2']);

print('s2_filter_rgb', s2_filter_rgb)
```

In the **Console** we can see that this filter has resulted in 11 images:

![Screenshot of GEE Code Editor, showing the Console tab.  In this case, filtering the ImageCollection has resulted in the selection of 11 Images.  ](https://129913967-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MjiZCnjzRgyoE8jhoZV%2Fuploads%2F0J242gQETidocI6SOLXl%2Fimage.png?alt=media\&token=0802d7da-69f8-42ee-8cda-2d5c0926aa0c)

While this is useful, it would be easier if we only had one image to manage.  We can do this by reducing the ImageCollection by value.  In this case, we can look for the Median values across each pixel.

{% hint style="info" %}
**`ee.ImageCollection.median`**
{% endhint %}

This can look like:&#x20;

```javascript
var s2_filter = ee.ImageCollection('COPERNICUS/S2_SR')  
                .filterDate('2021-09-01', '2022-03-01')  
                .filterBounds(ee.Geometry.Point(-68.124, -67.5679))  
                .filter('CLOUDY_PIXEL_PERCENTAGE < 50')


var s2_filter_rgb = s2_filter.select(['B4', 'B3', 'B2'])

var composite = s2_filter_rgb.median();

print('median composite:', composite)
```

And now the Console shows that the result is one single **Image**, composed of the 3 bands:&#x20;

![Screenshot of GEE Code Editor, showing the Console tab.  In this case, selecting the median values of the filtered ImageCollection has resulted in the selection of 1 Image.  ](https://129913967-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MjiZCnjzRgyoE8jhoZV%2Fuploads%2FazyNEMSQhleSpDlhpUMm%2Fimage.png?alt=media\&token=3f1e2290-dd00-4a3d-a28f-db30219fe991)

{% hint style="success" %}
Compared to the Filtered ImageCollection output, the Median Composite has less cloud-covered pixels.
{% endhint %}
