if(FALSE){
g <- asgrid(matrix(runif(n = 48)> .7, 6, 8), xll = 0, yll = 0, cellsize = 10)
plot(g)
plot(findsmallpatches(g, 3, nr = 8))
}
findsmallpatches <- function (x, maxsize, nr=8, ... ){
UseMethod("findsmallpatches")
}
findsmallpatches.grid <- function(x, maxsize, nr=8, ... ){
x$m <- findsmallpatches(x$m, maxsize = maxsize, nr=8, ...)
}
findsmallpatches.matrix <- function(x, maxsize, nr=8, targetclasses = NA, ...){
patches <- patchscan(x, nr = nr)$patches
sizes <- table(patches)
small.patches <- as.numeric(names(sizes)[sizes <= maxsize])
rm(sizes)
small <- matrix(nrow = nrow(x), ncol = ncol(x), data = patches %in% small.patches )
rm(patches)
if(!is.na(targetclasses))
small <- small & x$m %in% targetclasses
return(small)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.