Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Binnette opened this issue Nov 6, 2024 · 3 comments

Comments

@Binnette
Copy link

Binnette commented Nov 6, 2024

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):

  • OS: Debien
  • Label Studio Version: 1.14.0

How to bypass the bug

  • I checked database in .local/share/label-studio/label_studio.sqlite3 everything about my image seems correct.
  • I opened .local/share/label-studio/upload/1
    • My image is correctly (correct orientation) shown when I open it with default debian image viewer
    • When I open the image with gimp, Gimp advise me to rotate image according to orientation. So yes "original image" is 90° incorrect. But when Gimp applied image orientation, then image is correct. So I overwrite image with Gimp. Then the Coco Export work great for this image. But I was having errors on all other portraits images
    • Finally I run command "mogrify -auto-orient *.jpg" in folder .local/share/label-studio/upload/1 to fix all images orientation. Then Coco export worked perfectly
@heidi-humansignal
Copy link
Collaborator

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:
  • After running the command, the images will have the correct orientation embedded in the actual image data.
  • Import the images into Label Studio and proceed with your annotations as usual.
  1. Exporting Annotations:
  • When you export your project using the COCO format, the image dimensions in the result.json file should now be correct, reflecting the proper width and height.

Thank you,
Abu

Comment by Abubakar Saad
Workflow Run

@Binnette
Copy link
Author

Binnette commented Nov 8, 2024

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

@heidi-humansignal
Copy link
Collaborator

No worries, yes, we will work on this

Thank you,
Abu

Comment by Abubakar Saad
Workflow Run

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants