1

I have two rasters (Landsat slc-off images) in R. Both are missing some data, but the gap locations are completely offset. As an example, I create two rasters r1 and r2 below.

r1 <- raster(system.file("external/test.grd", package="raster"))
r1_mat <- as.matrix(r1)
r1[which(!is.na(as.matrix(r1)))[1:600]] <- NA
par(mfrow=c(3,1))
plot(r1)

r2 <- raster(system.file("external/test.grd", package="raster"))
r2[which(!is.na(as.matrix(r2)))[900:1400]] <- NA
plot(r2)

However, the second image is taken under different atmospheric conditions, say, with better solar illumination. To simulate this effect (very simply):

r2 <- r2 + 200

Now I would like to fill the missing data in r1, with r2 pixels that overlap the gaps which is trivially:

r3 <- cover(r1, r2)
plot(r3)

Looking at the result of plot(r3), the so called "stripping effect" also shown in Figure 2 on this page here is apparent. One of the recommended solutions is to normalize the two images by matching their histograms before doing the gap filling. The technique is based on the cumulative distribution functions of the candidate images e.g. as will be done in Grass 7.

How exactly can I achieve this in R? Thanks!

shekeine
  • 1,395
  • 8
  • 21
  • I'd suggest a gap fill approach like [this](https://github.com/azvoleff/teamlucc/tree/master/R). – Paulo E. Cardoso Dec 23 '14 at 11:32
  • Thanks for the suggestion, didnt know there was a GNSPI implementation for slc-off images in R!! However, I came to think that for a pixel based classification, perhaps it would be better to classify the two slc-off images separately and then merge the result. What do you think? – shekeine Dec 23 '14 at 11:59
  • Oops, just found out that with [teamlucc](https://github.com/azvoleff/teamlucc/blob/master/README.md) "IDL and ENVI are also needed to run the Landsat 7 SLC-off gap fill routine". The buck stops right there. A pure R implementation of the GNSPI gap fill algorithm would be great. – shekeine Dec 23 '14 at 12:05
  • Not sure. Probably not a good idea, particularly if they were obtained for different seasons or large time interval among them. – Paulo E. Cardoso Dec 23 '14 at 12:07
  • Well, now that I found there was no "native" GNSPI implementation in R; then I reckon this would be the best approach: Should be fine for a decadal scale study, also the two slc-off images are one year apart and from the same calendar date so that takes care of the sun, phenology, crop calendar etc. Also no drastic differences in the land surface state btw the 2 images e.g. floods or fires... – shekeine Dec 23 '14 at 12:29
  • You'll get discrepancies for the separate approaches. considering a pixel-based approach (but also for object oriented) you'll possibly add an extra step, to decide which class will be considered in the final classification. – Paulo E. Cardoso Dec 23 '14 at 15:25
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/67565/discussion-between-shekeine-and-paulo-cardoso). – shekeine Dec 23 '14 at 17:12

1 Answers1

1

After further Googling, I came across the cran package landsat. It has histmatch() and relnorm() functions to do just this. ?histmatch() explains it all perfectly with examples.

shekeine
  • 1,395
  • 8
  • 21