I'm working on an accuracy assessment of a classified landsat image and I'd like input on the best possible way to generate random points across both the classified image and a ground truth image I created by processing vector data from aerial photo interpretation.

I've processed both images and converted them to vectors in R and would like to generate random points in specific landcovers across both images so I can compare the predicted vs. actual landcover value at each random site.

My methodology so far has been to compare both vectors (in their entirety) and create a confusion matrix on them but the images this would include the training pixels in the supervised classification so I'd rather not have them as part of the accuracy assessment. A smaller subset of assessment pixels is probably best but I'd like feedback on those who have done this in R in the past as to best practices.

What approach should I take to generate random pixels in each image so I can compare the landcover values?

  • Use a randomly stratified sampling design: rstudio-pubs-static.s3.amazonaws.com/… – Aaron Jan 3 at 15:18
  • Thanks for the info but I'd also like to generate a certain number of random points inside each landcover type value. I also need to be able to generate and pull the random points across both images (same random points for each image) – jport Jan 3 at 16:01
  • Use your land over classes as the zones. In the example that I referenced, they use counties as zones. – Aaron Jan 3 at 16:03
  • This example is on a vector layer. My landcover zones are a raster layer. With pixel values not boundaries. Not sure if it will work on my images – jport Jan 3 at 16:15
  • Have you looked at the sampleStratified() function in the raster package? – Aaron Jan 3 at 17:08

It s best to avoid converting to vector to do the sampling if you do not have to. You can use the sampleStratified() function in the raster package to generate randomly stratified points in your land cover classes. For example:


# Generate some sample landcover raster data
r <- raster(ncol=10, nrow=10)
names(r) <- 'stratum'
values(r) <- round((runif(ncell(r))+0.5)*3)

# Randomly sample within each class (do not sample in NA)
s <- sampleStratified(r, size=3, na.rm=TRUE)

# Convert cell number to XY coords
xy <- xyFromCell(r,s) 

# Plot data
plot(r, col = topo.colors(3))

enter image description here

| improve this answer | |
  • Ok I got the accuracy assessment to work but realize that rather than a Stratified Random Sample I would like a Proportional Stratified Random Sample based on landcover class value totals across the entire image. – jport Jan 4 at 4:23
  • I would recommend opening a new question on that. – Aaron Jan 4 at 4:47

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.