This script is used to convert mask images to the real size of the corresponding images, multiply the mask by 255, and store the new masks in a new directory. It also converts the mask to RLE (Run-Length Encoding) format and stores the RLE format in a JSON file.
- Python 3
- OpenCV
- label-studio
You can install the required Python packages using pip:
pip install opencv-python label-studio-converter
You can run the script using the following command:
python script.py --images_path <images_path> --masks_path <masks_path> --new_masks_path <new_masks_path> --class_name <class_name> --json_name <json_name>
To ensure compatibility and optimal processing, adhere to the following file format requirements:
- Images: Must be in
.jpg
format. - Masks: Should be in
.png
format.
It's essential that the images and masks are named correspondingly to ensure they are correctly paired during processing.
Before importing the generated JSON file, you must configure Label Studio to connect to your local storage. This setup enables Label Studio to access the images and masks for annotation.
- Navigate to the Label Studio documentation on local storage setup: Local Storage Configuration Guide.
- Follow the instructions to configure your local storage connection. This typically involves setting up paths to your image and mask directories within Label Studio.
After configuring local storage and generating the JSON file with your annotations:
- Open your Label Studio project.
- Navigate to the Data Import section.
- Select the option to import tasks from a JSON file.
- Upload the generated JSON file containing your mask annotations.
This process will import your pre-annotated masks into Label Studio, ready for further annotation or review.
- Ensure that the local storage configuration is completed before importing the JSON file to avoid any discrepancies or issues with accessing the images and masks.
- The JSON file should match the format expected by Label Studio, as detailed in the documentation.