Just a small utility script that contains simple functions to
- generate a binary mask and the corresponding bounding box coordinates of a subject in an image.
- do simple transformations on an image (i.e. rotation, scaling, warping, overlaying, cropping, square resize) and modify the bounding box coordinates accordingly which could be quite challenging in some cases! For example, check this.
While creating a synthetic dataset for an object detection use-case, I often ran into image transformations where I had a hard time modifying the corresponding bounding box coordinates with respect to the transformation applied. So, I created these helper functions which do the same. I have used PIL and OpenCV interchangably as both have some functionalities which are easier to use.
Run python main.py
and the outputs would get saved to the images folder. If you set display = True
here, then the outputs would also be displayed on the screen one by one. The only requirements are OpenCV and Pillow libraries. To run the script on your own image, change this path to where your image is. The functions have docstrings attached and can be used individually as per requirement.