Image processing algorithms often require pixel values within a neighborhood of individual image locations. However, the neighborhood for boundary points is incomplete and needs special handling with various methods, e.g., mirror-reflecting, periodic, etc.
For linear operation, an efficient way is to turn the algorithm into a kernel and do 2D convolution. The convolution routine usual has boundary handling methods built in.
For arbitrary (non-linear) algorithms, one possibility is to pad the image first, gather all neighborhoods at once (e.g., with pad+neighbor), and do your operation in a vectorized way. However, this can be memory heavy as the doc suggested.
Loop through pixels and handle boundaries case by case is another way. But this can be slow in Python (though feasible in C/C++), and to provide all this mirror/periodic stuff seems to be cumbersome...
How to do this efficiently (and perhaps Pythonic) when implementing you own algorithms in Python?
And is there some function that returns the neighborhood of a specified pixel, and with specified boundary handling method?