332 - All about image annotations
Вставка
- Опубліковано 11 вер 2024
- This video tutorial walks you through the process of converting binary or labeled masks, often associated with scientific images, into coco style json annotations using python code. It also walks you through the process of converting the coco json annotations to YOLO v8 compatible annotations. As a bonus, I share code to display YOLO v8 annotations using python code.
Code from this video is available here: github.com/bns...
Part 1: Convert binary annotations to COCO JSON
For each binary mask, the code extracts contours using OpenCV.
These contours represent the boundaries of objects within the images. This is a key step in converting binary masks to polygon-like annotations.
Then, convert the contours into annotations, including bounding boxes, area, and segmentation information. Each annotation is associated with an image ID, category ID, and other properties required by the COCO format.
The code also creates an images section containing metadata about the images, such as their filenames, widths, and heights. In my example, I have used exactly the same file names for all images and masks so that a given mask can be easily mapped to the image.
All the annotations, images, and categories are assembled into a dictionary that follows the COCO JSON format. This includes sections for "info," "licenses," "images," "categories," and "annotations."
Finally, the assembled COCO JSON data is saved to a file, making it ready to be used with tools and frameworks that support the COCO data format.
Part 2: Converting COCO JSON annotation to YOLO v8
It reads coco style json annotations supplied as a single json file and also
images as input.
Here are the key steps in the code:
1. Convert Images to YOLO Format: The convert_to_yolo function takes paths for input images and annotations (in JSON format), and directories to store the output images and labels. It then performs the following operations:
- Reads the input JSON file containing annotations.
- Copies all PNG images from the input directory to the output directory.
- Normalizes the polygon segmentation data related to each image and writes them to text files, mapping them to the appropriate category (e.g., Alpha, Cells, Mito, Vessels).
- The resulting text files contain information about the object category and the normalized coordinates of the polygons that describe the objects.
2. Create YAML Configuration File: The create_yaml function takes paths to the input JSON file containing categories, training, validation, and optional test paths. It then:
- Extracts the category names and the number of classes.
- Constructs a dictionary containing information about class names, the number of classes, and paths to the training, validation, and test datasets.
- Writes this dictionary to a YAML file, which can be used as a configuration file for training a model (e.g., a YOLO model).
Thank you for your hard work to disseminate your knowledge, Sreeni. Greetings from the UK
your channel is literaly my BA computer science thesis
Thank you very much for it!!!11!!!1!!1!!!!
Thank you so much for all your tutorials! For our 3D data we now have all the tools to make labels, use them to train our own custom models (Detectron2/SAM etc) and create our binary masks. Could you PLEASE PLEASE create a tutorial on how we can then visualise our data as discrete 3D objects for downstream counting/quantification? Thank you Sreeni!!
Your information for the model is very helpful for us to get into the same phase that what is the model, exactly. It's very informative, please always keep it in all video series and your way of teaching code is wonderful. I am very grateful to you. Thank you sir🙏
Thank you sir, Your background information for the product and model is very helpful for us to get into the same phase that what is the model, exactly. It's very informative, please always keep it in all video series and your way of teaching code is marvellous. I am very grateful to you. Thanks🙏
Thanks a lot! Have seen many videos in your channel, those were really helpful!
Awesome video! Exactly the information I have been looking for. Much appreciated 👍
Thx for the quality of your videos and explanations - awesome like usual.
Thanks a lot for your great effort
I wish to see tutorials on Yolo algorithm on instance segmentation on custom data
Thanks a lot, this is very valuable. I could not find this info anywhere else.
My pleasure :)
Thanks for sharing the video, it was helpful for me.
excelente tutorial, gracias x compartir estos contenidos saludos desde Argentina
would love a walk through for image masks to detectron2 then using our own model to detect and output the masks in the same folder structure
please keep explaining sir so we can fully understand the process
and if you can make a video on yolo-nas on a costume dataset i would greatly appreciate it
thanks for your explaintion
Thank you very much.
hello thank you for the video yet i have a problem ihave a dataset with multi masks on the the same pictures with diffrent shades of gray is it possible to convert it to yolo v8 labels or to binary masks for each image then yolo v8
This is very nice! But I am having difficulty in converting json file to coco json file. Can you help me with it?
I have the base img and color masked image and I am stuck at making a decent json file (there are >9k images so nope I am not labelling them again) does any1 know the solution?
sir how you have created binary masks for each category of object from images
really thanks
thank u sir , can i use this yolov8 for hippocampus segmentation from brain MRI
why is when i run it said file_name is not defined
sir, could you please explain about Perceptilabs
Thanks!
Thank you very much :)
Thanks
appreciate
Please, I have question about image isolation by color, like the sunspot images there are black and gray, umbra and penumbra. I want to separate then to calculate the ratio of umbra to penumbra. Can you please help me . Every thing in black and gray , I will send the image hear
no one will replay
@@cattnation6257 what does that mean?
@@joaosousa9620 everybody is busy brother
@@cattnation6257 Ah, reply. But yes, the question should be more focused.
@@joaosousa9620 yeah I can understand his question why and only work on image last two weeks why can't a person who work on 7 8 year can't understand it?
thanks
Thanks!
Thank you