def calc_num_patches(height, width, window, stride=None, ret_hw=False):
    """Calculate number of patches given image dimension and window size"""
    if stride is None:
        stride = window
    numPatchesH = (height - window) // stride + 1
    numPatchesW = (width - window) // stride + 1
    if ret_hw:
        return numPatchesH, numPatchesW
    else:
        return numPatchesH * numPatchesW