Search code examples
annotationsobject-detection

Label Studio imports bounding boxes incorrectly


I am having issues loading my bounding boxes into label studio. I noticed that label studio resized my original image and think that the issue might be arising from that. The orginal image is 6000x4000 and the new one is about 866x574. I am importing a JSON file with the bounding boxes, but in the end they become much larger than the original ones. So I think label studio is trying to do some scaling incorrectly. This is my JSON file:

[{
  "data": {
    "image": "/data/upload/1/2e158a26-DSC05326.JPG" 
  },

  "predictions": [{
    "model_version": "one",
    "score": 0.5,
    "result": [
      {
        "id": "result1",
        "type": "rectanglelabels",        
        "from_name": "label", "to_name": "image",
        "original_width": 6000, "original_height": 4000,
        "image_rotation": 0,
        "value": {
          "rotation": 0,          
          "x": 712, "y": 1553,
          "width": 154, "height": 143,
          "rectanglelabels": ["Olive"]
        }
      },
      {
        "id": "result2",
        "type": "rectanglelabels",        
        "from_name": "label", "to_name": "image",
        "original_width": 6000, "original_height": 4000,
        "image_rotation": 0,
        "value": {
          "rotation": 0,          
          "x": 355, "y": 1161,
          "width": 182, "height": 169,
          "rectanglelabels": ["Branch"]
        }
      }
    ]
  }]
}]

And the labels values that appear in Label Studio are as follow: for olive:

enter image description here

and for branch:

enter image description here

Anyone know what is causing this, or how I should scale my json file to get it to be correct? I have tried to scale all the inputs, including the original image values, into the new image size, but that did not work.


Solution

  • For anyone else who got stuck on this (I did), the annotation syntax is in percentages so that the max X and Y co-ordinates are 100. This is explained here: https://labelstud.io/tags/image

    So, scale X coordinates by 100 / original_image.width, and Y coordinates by 100 / original_image.height.