def crop_gt(im, w, h, stride):
    """
    Crop a 2D image into patches of size [w, h] using a fixed stride.
    :param im: Image to crop ground truth labels from
    :param w: Width of the crops
    :param h: Height of the crops
    :param stride: Stride of the crops
    :return: List of patches in row-major ordering from image
    """
    assert len(im.shape) == 2, 'Expected grayscale image.'
    list_patches = []
    imgwidth = im.shape[0]
    imgheight = im.shape[1]
    for i in range(0, imgheight, stride):
        for j in range(0, imgwidth, stride):
            im_patch = im[j:j + w, i:i + h]
            list_patches.append(im_patch)
    return list_patches