get_subwindow( inputImage, y, x, sizey, sizex , borderPolicy)
It is free for any use. If you use it, please cite: http://ieeexplore.ieee.org/xpl/articleDetails.jsp?arnumber=6310525
Documentation is a bit lacking, maybe worth adding input checking too. But I can see myself using it, thanks.
May help noting that borderpolicy may be a scalar or string ('circular', 'replicate', 'symmetric') and only applies if the subwindow is outside the original image space.
Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.