Find the subset of a raster that best matches another raster
I have two raster objects of identical resolution but different sizes. And I need to find a subset of raster B that is most similar to raster A by for example a simple correlation measure. This subset of course needs to have the same size as A. Now I could loop through the dimensions of A and crop all possible subsets of size dim(A) and locate the one that has the highest correlation with A. However, I wonder if there are any more efficient algorithms to solve the problem.
b <- brick(system.file("external/rlogo.grd", package="raster"))
A <- crop(b[], extent(b[], 20, 60, 25, 75))