def resolve_crop(im, crop):
    """Convert a crop (i.e. slice definition) to only positive values
    crops might contain None, or - values"""
    # only works for two dimension
    crop = list(crop)
    assert len(crop) == 2
    for i in (0, 1):
        assert len(crop[i]) == 2
        for j in (0, 1):
            if crop[i][j] is None:
                crop[i][j] = j * im.shape[1-j]
            elif crop[i][j] < 0:
                crop[i][j] += im.shape[1-j]
    return crop