Apply transformations on a set of points (boundary box)

Hi everyone,

I’ve come across an issue that I can’t wrap my head around.

A part of my network outputs the (x, y, width, height) of a boundary box which I then use to localize the corresponding part of the initial image.

The issue is that I am also applying random transformations (RandomHorizontalFlip, RandomVerticalFlip, transforms.RandomRotation, RandomColorJitter) and so before I can go on and use the coordinates of the boundary box, I need to reverse the transformations that were applied. The reason for this is that I am dealing with huge images (whole slide images, digital pathology) and so I am always reading the images from the source.

Is there any direct or indirect way I can go about this? Also, if it’s of any help, I have stored the random seed that was used to generate the transformations. If I knew which transformations were applied and with what parameters, I would be able to reverse the transformations but I don’t think this is currently possible.

The only solution I can see is to implement the transformations myself. Any ideas on less time-consuming approaches?

Let me know if this is not clear enough. Thanks in advance!

@sgugger created recently a transformation package for fast.ai which seems to be working on images, bounding boxes, segmentation maps etc.
It seems to be the tool you are looking for. As I’m not that familiar with fast.ai I don’t know how easy it would be to use these transformations in PyTorch directly.

Let me know, if that would work for you!

1 Like

I am looking into it. Thanks for the fast reply! I will provide an update once I have something :slight_smile:

1 Like

its late though …

but for those who are still facing same problem … try this

1 Like