2

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)
1
  • Just a note: I am aware of the Inspector, so my question is about how to code this issue?
    – banbar
    Commented Feb 2, 2017 at 7:20

3 Answers 3

4
// 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)
5
  • Thank you -now I can get the pixel value of a given point. The follow-up questions are; i) how did you estimate the scale to be 10m, ii) what is really meant by scale, since changing its value changes the outcome?
    – banbar
    Commented Mar 3, 2017 at 13:48
  • @banbar May be this will help you developers.google.com/earth-engine/reducers_reduce_region Commented Mar 6, 2017 at 12:27
  • What is "B3" in this?
    – naman1994
    Commented Jul 27, 2020 at 9:45
  • in the question says the pixel value of band 3... that is B3... the band that holds the data for the green portion of the solar spectrum (around 560 nm) Commented Jul 27, 2020 at 10:06
  • How can I do the same in the code Rodrigo posted, but for one band of a Landsat Collection 2 Level 2 image collection for all it images from a start_date to an end_date and get as output a CSV with "image ID", and the "value of the band" at the point of interest.
    – Gab
    Commented Nov 20, 2021 at 12:23
1

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.

0

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.

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.