2

I am working on forest change detection in an area. I have taken two satellite images 2001 and 2016 to depict the forest change. I have taken four classes while classifying the images i.e., forest, non-forest, snow and water bodies.

I want to know, how we can make contingency table of both the two satellite images. The contingency table must show the change of pixel like how many pixels of class forest were present in 2001 and how many of those pixels transferred in 2016 in another class.

5
  • You should provide some code for a good answer, but a workaround could be table(raster::values(scene_2001),raster::values(scene_2016))
    – aldo_tapia
    Commented Sep 18, 2017 at 15:32
  • Could you please tell me more, if possible with an example. Commented Sep 19, 2017 at 8:12
  • @sourabsingh you should give an example - you shouldn't expect people answering questions here to do all the work of preparing data etc. You should try and give sample code that creates test datasets that we can use to help answer you. Edit your question to help us help you.
    – Spacedman
    Commented Sep 19, 2017 at 10:06
  • # Adding images # classified <- raster("E:/3rd_semester_project_work/classified_GEE/project/mask2000/mask2000.tif") classified1 <- raster("E:/3rd_semester_project_work/classified_GEE/project/mask2016/mask2016.tif") # Comparing the images to generate contingency table # table(raster::values("E:/3rd_semester_project_work/classified_GEE/project/mask2000/mask2000.tif"),raster::values("E:/3rd_semester_project_work/classified_GEE/project/mask2016/mask2016.tif")) BUT ITS NOT WORKING , NEED SOME HELP Commented Sep 19, 2017 at 11:09
  • Did you read function documentation? Why are you using a path inside values(). Check help(values)
    – aldo_tapia
    Commented Sep 19, 2017 at 13:03

1 Answer 1

2

The crosstab function in the raster package will make this for you, results are returned as pixel counts which can then be converted to area.

2
  • Thanks Tom, but could you please tell me more. If possible with an example. Commented Sep 19, 2017 at 8:13
  • From the crosstab documentation #making example rasters r <- raster(nc=5, nr=5) r[] <- runif(ncell(r)) * 2 s <- setValues(r, runif(ncell(r)) * 3) crosstab(r,s) Commented Sep 19, 2017 at 12:54

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.