Overlapping patch extraction from images

I want to extract overlapping patches from RGB images. The patches should not be randomly extracted. please share some logic or piece of code i. I tried it in MATLAB using the %mat2cell function but unable to extract overlapping patches.

thank you in advance

Maybe Unfold(Unfold — PyTorch 1.7.0 documentation) is what you need.