3

I'm trying to retrieve Sentinel-2 satellite images from Google Earth Engine using Python, and export them as a video to google drive. But the problem I'm facing is that regardless of the export settings, the video ends up as completely black with a white tile that moves every second.

I've also tried changing the coordinates, filters and bands, but it still gives me the same result. Any idea why this might be the case?

Images below for reference:

enter image description here

enter image description here

This is the code:


import ee
import time
from ee import batch

# Authenticating and connecting to Drive
# Fetching the Sentinel Image Collection


## Authenticating
ee.Authenticate()

## Initialize 
ee.Initialize()

## define your collection
collectionSentinel = ee.ImageCollection('COPERNICUS/S2').filterDate('2015-06-23', '2021-03-18')
print('collection done')

coodinates = [[66.79667713688107,24.885210852891888], [67.31749775455685,24.885210852891888], [67.31749775455685,25.185855686990557],  [66.79667713688107,25.185855686990557],  [66.79667713688107,24.885210852891888]]
print("coordinates received")

geoRegion = ee.Geometry.Polygon([coordinates])
pathrowSentinel = collectionSentinel.filterBounds(geoRegion)
print('region done')

##Filter cloudy scenes.
cloudsSentinel = pathrowSentinel.filter(ee.Filter.lt('CLOUDY_PIXEL_PERCENTAGE', 30))
print('clouds filtered')

## select the bands, we are going for true colour... but could be any!
bandsSentinel = cloudsSentinel.select(['B4', 'B3', 'B2'])
print('bands selected')

##make the data 8-bit.
def convertBit(image):
    return image.multiply(512).uint8()  

## call the conversion    
outputVideoSentinel = bandsSentinel.map(convertBit)
print('converted')

#Export to video.
print("about to build Sentinel video")
outSentinel = batch.Export.video.toDrive(outputVideoSentinel, description='khi_video_sentinel', dimensions = 720, framesPerSecond = 12, region=geoRegion, maxFrames=10000)
outSentinel.start()
print("process sentinel sent to cloud")


2 Answers 2

1

For me using .visualize() has always worked the best when trying to export to video.

It takes ordinary visualization parameters (which unfortunately you can't use that often in the python api I guess since you can't call Map.addLayer, but you could test your visualization out with folium).

Here's how I would do it for Sentinel 2 Images:

visParams = {"opacity":1,"bands":["B4","B3","B2"],"max":3000,"gamma":1}

def convertBit(image){
    return image.visualize(visParams)
}

outputVideoSentinel = s2masked.map(convertBit)

By the way, the specific issue that you are having, is that you are assuming here image.multiply(512).uint8() that the Sentinel 2 values are between 0 and 1, which they aren't. They are integers with a scaling factor of 10000. So are between 0 and 10000.

This means, that after your calculation almost all values are larger than 255, the largest value in uint8. When converting to uint8, all of them get capped to 255, giving you entirely white images. So you would first have to divide all the values by 10000 to get to a value range between 0 and 1.

0

Try to specifies your file name and the output folder

outSentinel = batch.Export.video.toDrive(outputVideoSentinel, description='khi_video_sentinel', dimensions = 720, framesPerSecond = 12, region=geoRegion, maxFrames=10000,fileNamePrefix = 'Video_Name',folder = 'Video_outputfolder')

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.