From 0f2bbcc5ce9403f0dfc250e7e2232488955e8b4a Mon Sep 17 00:00:00 2001 From: Lukasz Date: Mon, 23 Jan 2023 10:08:54 +0100 Subject: [PATCH 1/2] add option to use exif orientation from image metadata --- pyodi/apps/paint_annotations.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pyodi/apps/paint_annotations.py b/pyodi/apps/paint_annotations.py index 925e5c3..e2f2ca1 100644 --- a/pyodi/apps/paint_annotations.py +++ b/pyodi/apps/paint_annotations.py @@ -31,7 +31,7 @@ from matplotlib import pyplot as plt from matplotlib.collections import PatchCollection from matplotlib.patches import Polygon -from PIL import Image +from PIL import Image, ImageOps @logger.catch(reraise=True) @@ -45,6 +45,7 @@ def paint_annotations( show_label: bool = True, filter_crowd: bool = True, first_n: Optional[int] = None, + use_exif_orientation: bool = False ) -> None: """Paint `ground_truth_file` or `predictions_file` annotations on `image_folder` images. @@ -62,6 +63,8 @@ def paint_annotations( filter_crowd: Filter out crowd annotations or not. Default True. first_n: Paint only first n annotations and stop after that. If None, all images will be painted. + use_exif_orientation: If an image has an EXIF Orientation tag, other than 1, return a new image that + is transposed accordingly. The new image will have the orientation data removed """ Path(output_folder).mkdir(exist_ok=True, parents=True) @@ -103,6 +106,8 @@ def paint_annotations( if image_path.is_file(): image_pil = Image.open(image_path) + if use_exif_orientation: + image_pil = ImageOps.exif_transpose(image_pil) width, height = image_pil.size fig = plt.figure(frameon=False, figsize=(width / 96, height / 96)) From 0cf230d68e8d6ed854069a3775480bb9139c1710 Mon Sep 17 00:00:00 2001 From: Lukasz Date: Mon, 23 Jan 2023 11:16:56 +0100 Subject: [PATCH 2/2] fix code formatting --- pyodi/apps/paint_annotations.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pyodi/apps/paint_annotations.py b/pyodi/apps/paint_annotations.py index e2f2ca1..d64752d 100644 --- a/pyodi/apps/paint_annotations.py +++ b/pyodi/apps/paint_annotations.py @@ -45,7 +45,7 @@ def paint_annotations( show_label: bool = True, filter_crowd: bool = True, first_n: Optional[int] = None, - use_exif_orientation: bool = False + use_exif_orientation: bool = False, ) -> None: """Paint `ground_truth_file` or `predictions_file` annotations on `image_folder` images. @@ -64,7 +64,7 @@ def paint_annotations( first_n: Paint only first n annotations and stop after that. If None, all images will be painted. use_exif_orientation: If an image has an EXIF Orientation tag, other than 1, return a new image that - is transposed accordingly. The new image will have the orientation data removed + is transposed accordingly. The new image will have the orientation data removed. """ Path(output_folder).mkdir(exist_ok=True, parents=True)