label-studio icon indicating copy to clipboard operation
label-studio copied to clipboard

Allow Oriented Bounding Boxes to go out of the image margin

Open ViktorYu234 opened this issue 1 year ago • 6 comments

Hello,

I am utilizing Label Studio at my work and one of my tasks is it to label rotated rectangles in my images. For this task I'm utilizing Oriented Bounding Boxes. But there's one issue in Label-Studio which prevents me from doing my task properly:

Label-Studio does not allow OBB to go out of the image margin

This is an issue for me because sometimes there are rectangles which partially go out of bounds, forcing me to either mark them as a not oriented BB or to make them appear smaller as they actually are. But both solutions are rather bad for me because they may confuse the AI which needs to learn to mark even them properly.

Take this image as an example:

grafik

The minimal size of the rectangle can be determined as marked in the image, but labeling it properly is impossible without going out of the margin. I need to either not use oriented BB and include a big part of the background and mark it as not rotated, or make the labeled area smaller than it actually is (the label marked in the image doesn't even cover 1/3 of the actual rectangle).

I would like to be able to place at least one corner of the labeled area per image side out of the image margin to allow me to deal with issues like I described (Or rather in a way that each side of the label can't go fully out of image margin, but that might be not enough for other users who work with fully identical rectangles going out of bounds or so).

Actually I do not need an immediate update which implements this feature. If somebody can tell me the location of the code snippet which prevents me from moving my OBB out of bounds, I could change it for me by myself which would also be enough for me.

Can anyone help me?

ViktorYu234 avatar Dec 23 '24 12:12 ViktorYu234

Hello,

I think it will require alot for you to change in LSO code snippet. It won't be just for the tool and it might cause some undesired behavior as well. Here is the file (https://github.com/HumanSignal/label-studio/blob/develop/web/libs/editor/src/components/ImageTransformer/ImageTransformer.jsx) and you are looking for dragBoundFunc method.

I would suggest the workaround as well.

  1. Alternative Workaround: As a temporary solution, you could pad your images with additional transparent or blank space around the edges before importing them into Label Studio. This would effectively increase the image dimensions, allowing you to annotate the full extent of objects that extend beyond the original margins.
  • Use an image editing tool or a script to add padding to your images.
  • Ensure that the annotations correspond correctly to the padded images for training your AI model.

Thank you, Abu

Comment by Abubakar Saad Workflow Run

heidi-humansignal avatar Dec 30 '24 23:12 heidi-humansignal

I face the same issue and I'd appreciate enabling to go out of the image with corners of bounding boxes. My colleagues told me they are able to do so sometimes, but we can't provide you a reproducer unfortunately, because we could't find the pattern.

jakub-h avatar Jan 09 '25 10:01 jakub-h

I thought I would be able to overcome this issue with a bit of Python coding, but the out of image margin code is written in Java. So I'll just go with the Alternative Workaround which can be implemented in Python by increasing the image size to 200% for labeling and reducing it back to original size once labeled (Actually I would have to increase image width by 50% of image height per side and vice versa to make sure that I actually can label a by 45° rotated rectangle which takes over one whole side, but that action can't be reversed without saving some data beforehand).

Thanks @heidi-humansignal for showing me where the code snippets are located at (which didn't help me fixing the issue but made me understand it better) and the alternative suggestion.

ViktorYu234 avatar Jan 13 '25 21:01 ViktorYu234

Hello,

No worries, please try out the suggestion and let us know how that went.

Thank you, Abu

Comment by Abubakar Saad Workflow Run

heidi-humansignal avatar Jan 13 '25 22:01 heidi-humansignal

An update to my status:

For the last two months I was working on a python script which automated importing, exporting and predicting images for me. Instead of importing images directly it creates a copy of the original image which gets expanded and uploaded instead of the original. 'json' files also get "expanded" whenever uploaded. And for exporting images I can simply take the original non-expanded image but I also have to reverse the expansion of annointments. It works quite good for me and makes labeling bounding boxes located at the corner less of a hassle. By doing so I also managed to add another feature I missed in Label Studio which is changing the brightness and contrast of the image.

My script was written on company time so I would have to ask my boss before sharing any of it on GitHub, but I'll keep you updated if I do so.

ViktorYu234 avatar Feb 16 '25 11:02 ViktorYu234

I had the same problem. After some digging, I found that remove some line in image.js works. You can either comment it out or delete it.

` if (x < 0) { width += x; x = 0; } else if (x + width > stageWidth) { width = stageWidth - x; }

if (y < 0) { height += y; y = 0; } else if (y + height > stageHeight) { height = stageHeight - y; } `

jinzuchi avatar Jun 03 '25 08:06 jinzuchi

I can confirm that the above solution works. But It is worth noting that you will have to apply this "fix" again if you decide to update to a newer version .

DefacedFace avatar Oct 17 '25 11:10 DefacedFace