Sobes.tech
Middle

def preprocess_image( image_path: str, skip_rotation: bool, skip_resize: bool, ) -> Image.Image: """ Preprocesses the given image. 1st stage of preprocess -- rotation of image CCW by 90 degrees. 2nd stage of preprocess -- resize by reducing each side of the image twice. Each stage can be skipped by the corresponding parameter. """ im = Image.open(image_path) if skip_rotation: width, height = im.size im = im.resize((width / 2, height / 2)) elif skip_resize: im = im.transpose(Image.ROTATE_90) else: width, height = im.size im = im.transpose(Image.ROTATE_90) im = im.resize((width / 2, height / 2)) return im