HumanSignal / label-studio

Label Studio is a multi-type data labeling and annotation tool with standardized output format
https://labelstud.io
Apache License 2.0
19.49k stars 2.42k forks source link

Coco export do not use image orientation when setting image height and width in result.json #6608

Open Binnette opened 2 weeks ago

Binnette commented 2 weeks ago

Describe the bug When I export with "Coco export". The resulting "result.json" contains bad image width and height. In fact this export do not respect image orientation. So It set width as height and height as width.

To Reproduce Steps to reproduce the behavior:

  1. Take a portrait picture with your phone
  2. Import in label-studio (the image is correctly shown in label-studio)
  3. Add one annotation on this picture
  4. Export project with "Coco export"
  5. Open result.json from exported zip file
  6. See that image width and height are incorrect.

Expected behavior Coco export should rotate image according to image orientation before getting its size and height (the ones that are set in result.json)

Environment (please complete the following information):

How to bypass the bug

heidi-humansignal commented 2 weeks ago

Hello,

The problem you're experiencing is due to how image orientation metadata (EXIF data) is handled. When you take a portrait photo with your phone, the image file is often saved with the original data in landscape orientation and includes an EXIF orientation tag that instructs image viewers to display it rotated. While Label Studio displays the image correctly by respecting this metadata, the COCO export process retrieves the image dimensions directly from the file without accounting for the EXIF orientation. This results in the width and height being swapped in the result.json file. Workaround Solution: To resolve this issue, you can preprocess your images to apply the EXIF orientation before importing them into Label Studio. This involves rotating the actual image data to match the desired orientation and removing the EXIF orientation tag. Here's how you can do it:

  1. Using ImageMagick's mogrify Tool: Before importing your images into Label Studio, run the following command in the directory containing your images:

    mogrify -auto-orient *.jpg

This command rotates all JPEG images to the correct orientation based on their EXIF metadata and updates the images accordingly.

  1. Re-import and Annotate:
  1. Exporting Annotations:

Thank you, Abu

Comment by Abubakar Saad Workflow Run

Binnette commented 2 weeks ago

Hi Abu, thank for the workaround. I hope this bug will be fixed in future. Have a nice day.

heidi-humansignal commented 2 weeks ago

No worries, yes, we will work on this

Thank you, Abu

Comment by Abubakar Saad Workflow Run