I have a array image: var blist = change.select('tBreak'); Each pixel value in the image is a time.The time format uses is the serial date, starting from 0000-01-01.

And I have an image collection of NDSI values per day.

var imgcollection = ee.ImageCollection('LANDSAT/LT05/C01/T1')
    .map(function(image){return image.clip(table)}) ;

function NDSI_V1(img) {
 var ndsi = img.normalizedDifference(["B2","B5"]);
 return ndsi;

var ndsi = imgcollection.map(NDSI_V1);

I want to get an image where each pixel is the ndsi difference of the time provided by blist.For example, there is a pixel blist whose value is [t1, t2]. Then, the pixel value of the target image is the value of ndsi at time t2 subtract the value of ndsi at time t1. I hope someone can help me.Thanks

This is my array and image

  • 1
    Hi YYu - this sounds like an interesting problem. However, your change and table assets are not shared publicly, so it is difficult to experiment with a solution. Can you please share these assets so it is easier for folks interested in answering your question to do so. If the assets are not public, perhaps you can make mock examples. Thanks! – Justin Braaten Mar 12 at 20:38

I'm not completely clear what you want to do, and your assets are still not shared. The below script could maybe give you some ideas, even if it doesn't do exactly what you're after. It does the following:

  • Create a collection of NDSI images
  • Take the last two (non-zero) tBreak values
  • Convert them to unix time millis images
  • Build two NDSI mosaics, one for each of the time images. Each a quality mosaic with the distance from the time image as quality band.
  • The NDSI change is the difference between the two NDSI mosaic.


var change = ee.Image('users/wiell/CCDCExamples/segments')
var blist = change.select('tBreak')
blist = blist.arrayMask(blist.gt(0))
var region = blist.geometry()

var l5 = ee.ImageCollection('LANDSAT/LT05/C01/T1_SR')
  .select(['B2', 'B5', 'pixel_qa'], ['green', 'swir1', 'pixel_qa'])

var l8 = ee.ImageCollection('LANDSAT/LC08/C01/T1_SR')
  .select(['B3', 'B6', 'pixel_qa'], ['green', 'swir1', 'pixel_qa'])

var ndsiCollection = l5.merge(l8)
  .map(function (image) {
    return image
      .select([]).addBands( // Replace bands to keep properties
        image.normalizedDifference(['green', 'swir1'])

var segmentCount = blist.arrayLength(0)
var time1 = toUnixMillis(segmentCount.subtract(2))
var time2 = toUnixMillis(segmentCount.subtract(1))

var ndsi1 = ndsiForTime(time1)
var ndsi2 = ndsiForTime(time2)
var ndsiChange = ndsi2.subtract(ndsi1)

Map.addLayer(ndsiChange, {min: -0.5, max: 0.5, palette: 'red,orange,yellow,green,blue'}, 'ndsi change')

function ndsiForTime(time) {
  return ndsiCollection
    .map(function (image) {
      var timeDiff = time.subtract(image.date().millis())
      return image.addBands(timeDiff)

function toUnixMillis(index) {
  var t = blist.arrayGet([index])
  .updateMask(segmentCount.gte(2)) // Need to have at least 2 segments
  var epochDay = 719529
  return t.subtract(epochDay).multiply(1000).multiply(3600).multiply(24)  

function landsatMask(image) {
  var qa = image.select('pixel_qa')
  var clean = qa.bitwiseAnd(1 << 1)
  var water = qa.bitwiseAnd(1 << 2)
  return clean.or(water)


| improve this answer | |
  • Thank you very much for your answer, it completely solved my problem – YYu Mar 18 at 19:51
  • Sorry to bother you again. How do I get all the change segments? and Does segmentCount record segments with several changes? – YYu Mar 21 at 19:30
  • In what sense, get all change segments? segmentCount is the number of segments with detected breaks. – Daniel Wiell Mar 23 at 14:24
  • Sorry, I have a related question I want to ask you again.I want to get the NDSI average value of each pixel in the image between time1 and time2.I don't know how to express the image between time1 and time2 of each pixel.Hope you can help me.Many thanks – YYu Jun 26 at 17:10
  • I used your code and asked this question, you can answer there – YYu Jun 26 at 17:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.