def quantized_rotation(img, factor):
    """
    Rotate an image counterclockwise by an integer factor times 90 degrees.
    """
    if factor % 4 == 0:
        pass
    elif factor % 4 == 1:
        img = img.transpose(-2, -1).flip(-1)
    elif factor % 4 == 2:
        img = img.flip(-2).flip(-1)
    elif factor % 4 == 3:
        img = img.transpose(-2, -1).flip(-2)
    return img