[GIS] NDVI Scaling in Google Earth Engine

google-earth-enginemodisndvipython

I am trying to download NDVI data from the Google Earth Engine MODIS satellite. I used the following dataset:

img = ee.ImageCollection("MODIS/006/MOD13A2")

To actually download it, I ran img.getDownloadUrl() to produce a URL and retrieve the data.

According to the website https://developers.google.com/earth-engine/datasets/catalog/MODIS_006_MOD13A2, it states that NDVI has a minimum value of -2000, a maximum of 10000, and a scale factor of 0.0001, inorder to scale the NDVI between the standard values of -0.2 and 1.0.

However, the images downloaded from ee.ImageCollection are tif grayscale images, and using cv2.read() on those images produces a matrix of values between 0 and 255 inclusive. Can anyone explain what the true NDVI values of the image are? Furthermore, most of the values are between 0 and 35, while water is returning values of 250+. Im confused as to what is going on? How is the data that I am downloading being scaled?

Update: I have the code below

print(img.projection().getInfo())
path = img.getDownloadUrl({
    'crs': 'EPSG:4326',
    'crsTransform': [926.625433056, 0.0, -20015109.354, 0.0, -926.625433055, 10007554.677],
    #'scale':1000
    'bands': [{'id':'NDVI'}],
    'region': '[[' + str(currentMinLng) + ',' + str(currentMaxLat) + '],['+str(currentMaxLng) + ',' + str(currentMaxLat) + '],['+str(currentMaxLng) + ',' + str(currentMinLat)  + '],[' + str(currentMinLng) + ',' +str(currentMinLat) + '],[' + str(currentMinLng) + ',' + str(currentMaxLat)+ ']]'
    #'region': '[[16.499050771335575,-29.07796275949132],[18.584367695114103,-29.07796275949132],[18.584367695114103,-30.882],[16.499050771335575,-30.882],[16.499050771335575,-29.07796275949132]]'
    #'region': '[[20.2431,-28.882],[22.2431,-28.882],[22.2431,-30.882],[20.2431,-30.88]]'
})

In the above code, the "img" variable is a Google Earth Image from the "MODIS/006/MYD13A2" image collection.The variable "path" produces a download link to the image. When I open the image using opencv and read the .TIF file, I get a bunch of pixels that are oddly scaled. What could cause this to happen?

I realized that it may not be the .TIF thats causing the problem but rather the way I am reading it. What would be the correct way to read in this .TIF using python?

Best Answer

Alright, I found it. It turns out that cv2.imread() is not a good idea for reading TIFF files. This was distorting the data is got and consequently messing up the numbers. Now, if you use from PIL import Image, and use Image.open(), the data is read correctly.

Related Question