I have matrix of numbers...let's say it came from a picture with 16 x 16 pixels
Mat <- matrix(rbinom(16 * 16, 1, 0.5), ncol = 16, nrow = 16)
# Stride 1 pixel at at time each time looking at a 3x3 pixel kernel around the current pixel
for(c in 1:ncol(Mat)){
for(r in 1:nrow(Mat)){
if(r+2 < nrow(Mat) & c+2 < ncol(Mat)){
print("Here's the current 3x3:")
print(Mat[r:(r+2),c:(c+2)])
print("You can do your feature engineering step here.")
}
else if(r+2 < nrow(Mat) & !(c+2 < ncol(Mat))){
print("You could pad as you described but based on the rest of your
description the result would be the same as just ommitting the padded
cells.")
cc <- ncol(Mat)
print("Here's the current pseudo-3x3:")
print(Mat[r:(r+2),c:cc])
}
else if(!(r+2 < nrow(Mat)) & (c+2 < ncol(Mat))){
rr <- nrow(Mat)
print("Here's the current pseudo-3x3:")
print(Mat[r:rr,c:(c+2)])
}
else if(!(r+2 < nrow(Mat)) & !(c+2 < ncol(Mat))){
c <- ncol(Mat)
r <- nrow(Mat)
print("Here's the current pseudo-3x3:")
print(Mat[r:rr,c:cc])
}
}
}