Skip to content

Commit

Permalink
Fix exif image orientation (facebookresearch#262)
Browse files Browse the repository at this point in the history
Summary:
hi.

I tried demo.py our data.
I found small problem for image have exif information.

I fixed it. please check it. thanks.
Pull Request resolved: facebookresearch#262

Differential Revision: D18424793

Pulled By: ppwwyyxx

fbshipit-source-id: 3660f7d8637027b6aafe51801fe1f716bc55b933
  • Loading branch information
higumachan authored and facebook-github-bot committed Nov 11, 2019
1 parent ebb9f8c commit 556da42
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 3 deletions.
5 changes: 4 additions & 1 deletion detectron2/data/detection_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import numpy as np
import torch
from fvcore.common.file_io import PathManager
from PIL import Image
from PIL import Image, ImageOps

from detectron2.structures import (
BitMasks,
Expand All @@ -34,6 +34,7 @@ class SizeMismatchError(ValueError):
def read_image(file_name, format=None):
"""
Read an image into the given format.
Will apply rotation and flipping if the image has such exif information.
Args:
file_name (str): image file path
Expand All @@ -45,6 +46,8 @@ def read_image(file_name, format=None):
with PathManager.open(file_name, "rb") as f:
image = Image.open(f)

image = ImageOps.exif_transpose(image)

if format is not None:
# PIL only supports RGB, so convert to RGB and flip channels over below
conversion_format = format
Expand Down
4 changes: 4 additions & 0 deletions docs/notes/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
* 2019-10-10: initial release.


### Minor Changes in Code

* 2019-11-11: detectron2.data.detection_utils.read_image is transposing with exif information.

### Config Version Change Log

* v1: Rename `RPN_HEAD.NAME` to `RPN.HEAD_NAME`.
Expand Down
3 changes: 2 additions & 1 deletion docs/tutorials/datasets.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ The fields are often optional, and some functions may be able to
infer certain fields from others if needed, e.g., the data loader
can load an image from "file_name" if the "image" field is not available.

+ `file_name`: the full path to the image file.
+ `file_name`: the full path to the image file. Will apply rotation and flipping if the image has such exif information.
+ `sem_seg_file_name`: the full path to the ground truth semantic segmentation file.
+ `image`: the image as a numpy array.
+ `sem_seg`: semantic segmentation ground truth in a 2D numpy array. Values in the array represent
Expand Down Expand Up @@ -160,3 +160,4 @@ NOTE: For background on the difference between "thing" and "stuff" categories, s
In detectron2, the term "thing" is used for instance-level tasks,
and "stuff" is used for semantic segmentation tasks.
Both are used in panoptic segmentation.

2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def get_extensions():
python_requires=">=3.6",
install_requires=[
"termcolor>=1.1",
"Pillow",
"Pillow>=6.0",
"yacs>=0.1.6",
"tabulate",
"cloudpickle",
Expand Down

0 comments on commit 556da42

Please sign in to comment.