I would like to make an accuracy assessment using a confusion matrix between classified Landsat image and reference dataset. Maps have the same resolution and extent. I would like to evaluate the agreement by pixel-by-pixel. In many studies I have found that they used moving-kernel window (ideal 3x3) to "deal" with the Landsat pixels misregistration. However I couldn't find any approach to do use this moving window for confusion matrix evaluation in R, normally it is used to values interpolation.
Do you have any ideas how to implement moving window into classification accuracy assessment? Or am I misunderstanding this approach?
Thanks a lot,
Example:
library("raster")
clas <- raster(ncols=5, nrows=5)
values(clas)<-c(2,1,0,0,1,
2,1,0,0,0,
1,0,0,0,0,
0,0,0,0,0,
2,1,0,0,2)
reference <- raster(ncols=5, nrows=5)
values(reference)<-c(2,1,0,0,0,
2,1,0,0,1,
0,0,0,0,0,
1,2,0,0,2,
0,0,0,0,0)
EDIT:
After utilisation of movingFun
(raster) I think this is mostly to get information in one cell taking into consideration the cells around.
so if I have a
ref<-c(0,0,0,0,1,0,0,0,0)
class<-c(0,0,0,0,1,1,1,0,1)
and I apply movingFun
mov_ref<-movingFun(ref, n=3)
mov_clas<-movingFun(class, n=3)
I will obtain
mov_ref
NA, 0.0000000 0.0000000 0.3333333 0.3333333 0.3333333 0.0000000
0.0000000 NA
mov_clas
NA 0.0000000 0.0000000 0.3333333 0.6666667 1.0000000 0.6666667
0.6666667 NA
For accuracy assessment needs could I directly compare mov_ref
and mov_class
? Or do I have maybe to reclass
it into 0,1 (by threshold 0.5) to compare them? If I leave the numbers as 0.3333 I dont reach a good result in classification accuracy.
movingFun()
which does exactly what you want. For frequencies of miss-classification you could also look atcrosstab