Reputation: 299
In Google Earth Engine, is it possible to obtain the pixel values of an image? The following code displays the details of the image and we can see that the image has 10980*10980 pixels for the bands 2,3 and 4. How can we obtain the pixel value of band 3 at the (x,y) pixel or a specific (lat,lon)?
var im1 = ee.Image('COPERNICUS/S2/20160422T084804_20160422T123809_T36TVK')
print(im1)
Upvotes: 2
Views: 15474
Reputation: 74
Another note, if you need the value of a pixel for all images in an ImageCollection, for example, is that you can turn the ImageCollection into an image using:
image_with_bands = original_image_name.toBands()
Then when you do a reduceRegion and the .getInfo()
(or .get()
for Java), you get a list of all of the values for all of the bands, where the bands are named by the original band name with an _ and then the date! Another good tool for this kind of calculation is the geemap package, which has a lot of these tools ready to go.
Upvotes: 0
Reputation: 11
You can also use the inspector tool, next to the console tab on the right upper area of the interface. After clicking on a location on the map you will see the values of each band for each map layer displayed for that pixel corresponding to that location.
Upvotes: 1
Reputation: 1311
// Image
var im1 = ee.Image('COPERNICUS/S2/20160422T084804_20160422T123809_T36TVK')
// Point
var p = ee.Geometry.Point(32.3, 40.3)
// Extract the data
var data = im1
.select("B3")
.reduceRegion(ee.Reducer.first(),p,10)
.get("B3")
// Convert to Number for further use
var dataN = ee.Number(data)
// Show data
print(dataN)
// Add Layers
Map.centerObject(im1)
Map.addLayer(im1,{bands:["B4","B3","B2"],min:0,max:5000})
Map.addLayer(p)
Upvotes: 4