segment-toolkit 1.0.0__tar.gz → 1.0.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {segment_toolkit-1.0.0/segment_toolkit.egg-info → segment_toolkit-1.0.2}/PKG-INFO +66 -33
- segment_toolkit-1.0.0/PKG-INFO → segment_toolkit-1.0.2/README.md +58 -51
- {segment_toolkit-1.0.0 → segment_toolkit-1.0.2}/segment_toolkit/__init__.py +1 -1
- segment_toolkit-1.0.2/segment_toolkit/__main__.py +17 -0
- segment_toolkit-1.0.0/README.md → segment_toolkit-1.0.2/segment_toolkit.egg-info/PKG-INFO +84 -32
- {segment_toolkit-1.0.0 → segment_toolkit-1.0.2}/segment_toolkit.egg-info/SOURCES.txt +1 -0
- {segment_toolkit-1.0.0 → segment_toolkit-1.0.2}/setup.py +8 -2
- {segment_toolkit-1.0.0 → segment_toolkit-1.0.2}/segment_toolkit/cli.py +0 -0
- {segment_toolkit-1.0.0 → segment_toolkit-1.0.2}/segment_toolkit/helpers.py +0 -0
- {segment_toolkit-1.0.0 → segment_toolkit-1.0.2}/segment_toolkit/source.py +0 -0
- {segment_toolkit-1.0.0 → segment_toolkit-1.0.2}/segment_toolkit.egg-info/dependency_links.txt +0 -0
- {segment_toolkit-1.0.0 → segment_toolkit-1.0.2}/segment_toolkit.egg-info/entry_points.txt +0 -0
- {segment_toolkit-1.0.0 → segment_toolkit-1.0.2}/segment_toolkit.egg-info/requires.txt +0 -0
- {segment_toolkit-1.0.0 → segment_toolkit-1.0.2}/segment_toolkit.egg-info/top_level.txt +0 -0
- {segment_toolkit-1.0.0 → segment_toolkit-1.0.2}/setup.cfg +0 -0
- {segment_toolkit-1.0.0 → segment_toolkit-1.0.2}/tests/test_converter.py +0 -0
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: segment_toolkit
|
|
3
|
-
Version: 1.0.
|
|
3
|
+
Version: 1.0.2
|
|
4
4
|
Summary: A Python toolkit to convert between binary segmentation masks and YOLO labels
|
|
5
|
-
|
|
5
|
+
Home-page: https://github.com/zkzkGamal/mask-to-yolo-toolkit
|
|
6
|
+
Author: Zakria Gamal
|
|
7
|
+
Author-email: zekogml11@gmail.com
|
|
8
|
+
Project-URL: Source Code, https://github.com/zkzkGamal/mask-to-yolo-toolkit
|
|
9
|
+
Project-URL: Bug Tracker, https://github.com/zkzkGamal/mask-to-yolo-toolkit/issues
|
|
6
10
|
Requires-Python: >=3.6
|
|
7
11
|
Description-Content-Type: text/markdown
|
|
8
12
|
Requires-Dist: numpy
|
|
@@ -11,55 +15,65 @@ Requires-Dist: pillow
|
|
|
11
15
|
Requires-Dist: pandas
|
|
12
16
|
Requires-Dist: matplotlib
|
|
13
17
|
Dynamic: author
|
|
18
|
+
Dynamic: author-email
|
|
14
19
|
Dynamic: description
|
|
15
20
|
Dynamic: description-content-type
|
|
21
|
+
Dynamic: home-page
|
|
22
|
+
Dynamic: project-url
|
|
16
23
|
Dynamic: requires-dist
|
|
17
24
|
Dynamic: requires-python
|
|
18
25
|
Dynamic: summary
|
|
19
26
|
|
|
20
|
-
# Segment Toolkit
|
|
27
|
+
# Segment Toolkit
|
|
21
28
|
|
|
22
|
-
A modern, robust, and premium Python package designed to bridge the gap between pixel-level
|
|
29
|
+
A modern, robust, and premium Python package designed to bridge the gap between pixel-level binary segmentation masks and YOLO bounding box labels. It provides a bidirectional pipeline with exception handling, extensive logging, a command-line interface (CLI), and a Python API.
|
|
23
30
|
|
|
24
31
|
---
|
|
25
32
|
|
|
26
|
-
##
|
|
33
|
+
## Features
|
|
27
34
|
|
|
28
35
|
- **Bidirectional Conversion**:
|
|
29
36
|
- **Forward Pipeline**: Convert binary masks to YOLO format labels (supports standard axis-aligned or advanced minimum area rotated bounding boxes).
|
|
30
37
|
- **Reverse Pipeline**: Reconstruct binary masks from YOLO labels.
|
|
31
|
-
- **Automatic Dependency Installer**: Missing required packages (
|
|
38
|
+
- **Automatic Dependency Installer**: Missing required packages (numpy, opencv-python, pillow, pandas, matplotlib) are automatically detected and installed via pip upon package import or script execution.
|
|
32
39
|
- **Robust Exception Handling**: Try-catch blocks wrapped around file I/O, contour finding, and resizing to prevent application crashes on corrupted or missing files.
|
|
33
|
-
- **Dynamic Dataset Matching**: Read classification mappings (in
|
|
34
|
-
- **YOLO Dataset Splitting**: Automatically shuffles and partitions images
|
|
40
|
+
- **Dynamic Dataset Matching**: Read classification mappings (in CSV or JSON format) to automatically assign multi-class IDs matching standard dataset schemas (like the ISIC dataset).
|
|
41
|
+
- **YOLO Dataset Splitting**: Automatically shuffles and partitions images and labels into training and testing sets with customizable split ratios, creating standard data.yaml configs.
|
|
35
42
|
- **Overlay Visualizer**: Overlay bounding boxes and class indicators directly onto source images for annotation inspection.
|
|
36
|
-
- **Dual Interface**: Use as a command-line application (
|
|
43
|
+
- **Dual Interface**: Use as a command-line application (segment-toolkit) or import as a Python library (import segment_toolkit).
|
|
37
44
|
|
|
38
45
|
---
|
|
39
46
|
|
|
40
|
-
##
|
|
47
|
+
## Installation
|
|
41
48
|
|
|
42
|
-
|
|
49
|
+
### 1. Standard Installation (via PyPI)
|
|
50
|
+
To install the latest stable version of the package directly from PyPI:
|
|
43
51
|
|
|
44
52
|
```bash
|
|
45
|
-
pip install -
|
|
53
|
+
pip install segment-toolkit
|
|
46
54
|
```
|
|
47
55
|
|
|
48
|
-
###
|
|
49
|
-
If you
|
|
56
|
+
### 2. Local Installation (via Git Clone)
|
|
57
|
+
If you want to clone the repository for local development, run:
|
|
50
58
|
|
|
51
59
|
```bash
|
|
52
|
-
|
|
53
|
-
|
|
60
|
+
# Clone the repository
|
|
61
|
+
git clone https://github.com/zkzkGamal/mask-to-yolo-toolkit.git
|
|
62
|
+
|
|
63
|
+
# Navigate into the project folder
|
|
64
|
+
cd LabelFile-for-yoloModel
|
|
65
|
+
|
|
66
|
+
# Install in editable mode
|
|
67
|
+
pip install -e .
|
|
54
68
|
```
|
|
55
69
|
|
|
56
70
|
---
|
|
57
71
|
|
|
58
|
-
##
|
|
72
|
+
## Usage
|
|
59
73
|
|
|
60
74
|
### 1. Command Line Interface (CLI)
|
|
61
75
|
|
|
62
|
-
The package installs a console script called
|
|
76
|
+
The package installs a console script called segment-toolkit.
|
|
63
77
|
|
|
64
78
|
#### Convert Masks to YOLO Labels
|
|
65
79
|
- **Single File Conversion**:
|
|
@@ -81,8 +95,8 @@ The package installs a console script called `segment-toolkit`.
|
|
|
81
95
|
```
|
|
82
96
|
|
|
83
97
|
- **Options**:
|
|
84
|
-
- `--rotated`: Use rotated minimum area rectangles (
|
|
85
|
-
- `--resize WIDTH HEIGHT`: Set target size for image and mask resizing (default:
|
|
98
|
+
- `--rotated`: Use rotated minimum area rectangles (cv2.minAreaRect) instead of standard axis-aligned rectangles.
|
|
99
|
+
- `--resize WIDTH HEIGHT`: Set target size for image and mask resizing (default: 640 640).
|
|
86
100
|
|
|
87
101
|
#### Convert YOLO Labels to Masks
|
|
88
102
|
- **Single File Conversion**:
|
|
@@ -109,7 +123,7 @@ segment-toolkit visualize \
|
|
|
109
123
|
```
|
|
110
124
|
|
|
111
125
|
#### Split Dataset
|
|
112
|
-
Organize folders into YOLO-compliant structure (
|
|
126
|
+
Organize folders into YOLO-compliant structure (dataset/train and dataset/test splits) and output data.yaml:
|
|
113
127
|
```bash
|
|
114
128
|
segment-toolkit split \
|
|
115
129
|
--images images/ \
|
|
@@ -121,13 +135,32 @@ segment-toolkit split \
|
|
|
121
135
|
|
|
122
136
|
---
|
|
123
137
|
|
|
124
|
-
|
|
138
|
+
## Validation and Demonstration Outputs
|
|
139
|
+
|
|
140
|
+
To verify the library, we run automated validation on sample datasets. All validation output files (YOLO coordinates, reconstructed masks, and drawing overlays) are stored in the [validate_data/](file:///home/aloha-zkaria/LabelFile-for-yoloModel/validate_data) folder.
|
|
141
|
+
|
|
142
|
+
### Validation Overlays
|
|
143
|
+
|
|
144
|
+
Here are the bounding box overlays generated by the toolkit visualizer:
|
|
145
|
+
|
|
146
|
+
#### ISIC Melanoma Skin Lesion Validation
|
|
147
|
+

|
|
148
|
+
|
|
149
|
+
#### Plant Leaf Disease Validation
|
|
150
|
+

|
|
151
|
+
|
|
152
|
+
### Video Demonstration
|
|
153
|
+
A video demonstrating installation, CLI commands, and programming API pipelines can be placed in the [demo/](file:///home/aloha-zkaria/LabelFile-for-yoloModel/demo) directory.
|
|
154
|
+
|
|
155
|
+
---
|
|
156
|
+
|
|
157
|
+
## Ground Truth Formats
|
|
125
158
|
|
|
126
|
-
The
|
|
159
|
+
The --ground-truth parameter in batch conversion supports both CSV and JSON formats.
|
|
127
160
|
|
|
128
161
|
#### CSV Format
|
|
129
|
-
Assumes the first column contains the image identifier/filename, and the subsequent columns represent binary indicator classes (where
|
|
130
|
-
Example
|
|
162
|
+
Assumes the first column contains the image identifier/filename, and the subsequent columns represent binary indicator classes (where 1 indicates class presence).
|
|
163
|
+
Example GroundTruth.csv:
|
|
131
164
|
```csv
|
|
132
165
|
image,MEL,NV,BCC,AKIEC,BKL,DF,VASC
|
|
133
166
|
ISIC_0024306,0,1,0,0,0,0,0
|
|
@@ -164,11 +197,11 @@ Supports three distinct schemas:
|
|
|
164
197
|
]
|
|
165
198
|
```
|
|
166
199
|
|
|
167
|
-
*Note: Class name strings (like
|
|
200
|
+
*Note: Class name strings (like "MEL", "NV") are automatically mapped to standard ISIC IDs (AKIEC=0, BCC=1, BKL=2, DF=3, MEL=4, NV=5, VASC=6). Custom column names default to index-based IDs.*
|
|
168
201
|
|
|
169
202
|
---
|
|
170
203
|
|
|
171
|
-
|
|
204
|
+
## Python API
|
|
172
205
|
|
|
173
206
|
Import classes directly into your code to programmatically build custom pipelines:
|
|
174
207
|
|
|
@@ -195,23 +228,23 @@ yolo_conv.convert_dataset(
|
|
|
195
228
|
|
|
196
229
|
---
|
|
197
230
|
|
|
198
|
-
##
|
|
231
|
+
## Technical Details
|
|
199
232
|
|
|
200
233
|
### Coordinate Conversion Math
|
|
201
234
|
|
|
202
235
|
#### Bounding Box Center Calculation (Pixel Space)
|
|
203
|
-
For standard bounding boxes, the pixel coordinates from
|
|
236
|
+
For standard bounding boxes, the pixel coordinates from boundingRect are (xmin, ymin, w_pixel, h_pixel).
|
|
204
237
|
$$\text{Center } X \quad x_{center} = x_{min} + \frac{w_{pixel}}{2.0}$$
|
|
205
238
|
$$\text{Center } Y \quad y_{center} = y_{min} + \frac{h_{pixel}}{2.0}$$
|
|
206
239
|
|
|
207
240
|
#### Coordinate Normalization (YOLO Format)
|
|
208
|
-
All coordinates are normalized to the range
|
|
241
|
+
All coordinates are normalized to the range [0.0, 1.0]:
|
|
209
242
|
$$x_{norm} = \frac{x_{center}}{img\_width}, \quad y_{norm} = \frac{y_{center}}{img\_height}$$
|
|
210
243
|
$$w_{norm} = \frac{w_{pixel}}{img\_width}, \quad h_{norm} = \frac{h_{pixel}}{img\_height}$$
|
|
211
244
|
|
|
212
245
|
---
|
|
213
246
|
|
|
214
|
-
##
|
|
247
|
+
## Author
|
|
215
248
|
**Zakria Gamal**
|
|
216
|
-
- Computer Vision
|
|
217
|
-
-
|
|
249
|
+
- Computer Vision and AI Engineer
|
|
250
|
+
- LinkedIn: [Zakria Gamal](https://www.linkedin.com/in/zkaria-gamal-82b486267/)
|
|
@@ -1,65 +1,53 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
Summary: A Python toolkit to convert between binary segmentation masks and YOLO labels
|
|
5
|
-
Author: Antigravity
|
|
6
|
-
Requires-Python: >=3.6
|
|
7
|
-
Description-Content-Type: text/markdown
|
|
8
|
-
Requires-Dist: numpy
|
|
9
|
-
Requires-Dist: opencv-python
|
|
10
|
-
Requires-Dist: pillow
|
|
11
|
-
Requires-Dist: pandas
|
|
12
|
-
Requires-Dist: matplotlib
|
|
13
|
-
Dynamic: author
|
|
14
|
-
Dynamic: description
|
|
15
|
-
Dynamic: description-content-type
|
|
16
|
-
Dynamic: requires-dist
|
|
17
|
-
Dynamic: requires-python
|
|
18
|
-
Dynamic: summary
|
|
19
|
-
|
|
20
|
-
# Segment Toolkit 🛠️
|
|
21
|
-
|
|
22
|
-
A modern, robust, and premium Python package designed to bridge the gap between pixel-level **binary segmentation masks** and **YOLO bounding box labels**. It provides a bidirectional pipeline with exception handling, extensive logging, a command-line interface (CLI), and a Python API.
|
|
1
|
+
# Segment Toolkit
|
|
2
|
+
|
|
3
|
+
A modern, robust, and premium Python package designed to bridge the gap between pixel-level binary segmentation masks and YOLO bounding box labels. It provides a bidirectional pipeline with exception handling, extensive logging, a command-line interface (CLI), and a Python API.
|
|
23
4
|
|
|
24
5
|
---
|
|
25
6
|
|
|
26
|
-
##
|
|
7
|
+
## Features
|
|
27
8
|
|
|
28
9
|
- **Bidirectional Conversion**:
|
|
29
10
|
- **Forward Pipeline**: Convert binary masks to YOLO format labels (supports standard axis-aligned or advanced minimum area rotated bounding boxes).
|
|
30
11
|
- **Reverse Pipeline**: Reconstruct binary masks from YOLO labels.
|
|
31
|
-
- **Automatic Dependency Installer**: Missing required packages (
|
|
12
|
+
- **Automatic Dependency Installer**: Missing required packages (numpy, opencv-python, pillow, pandas, matplotlib) are automatically detected and installed via pip upon package import or script execution.
|
|
32
13
|
- **Robust Exception Handling**: Try-catch blocks wrapped around file I/O, contour finding, and resizing to prevent application crashes on corrupted or missing files.
|
|
33
|
-
- **Dynamic Dataset Matching**: Read classification mappings (in
|
|
34
|
-
- **YOLO Dataset Splitting**: Automatically shuffles and partitions images
|
|
14
|
+
- **Dynamic Dataset Matching**: Read classification mappings (in CSV or JSON format) to automatically assign multi-class IDs matching standard dataset schemas (like the ISIC dataset).
|
|
15
|
+
- **YOLO Dataset Splitting**: Automatically shuffles and partitions images and labels into training and testing sets with customizable split ratios, creating standard data.yaml configs.
|
|
35
16
|
- **Overlay Visualizer**: Overlay bounding boxes and class indicators directly onto source images for annotation inspection.
|
|
36
|
-
- **Dual Interface**: Use as a command-line application (
|
|
17
|
+
- **Dual Interface**: Use as a command-line application (segment-toolkit) or import as a Python library (import segment_toolkit).
|
|
37
18
|
|
|
38
19
|
---
|
|
39
20
|
|
|
40
|
-
##
|
|
21
|
+
## Installation
|
|
41
22
|
|
|
42
|
-
|
|
23
|
+
### 1. Standard Installation (via PyPI)
|
|
24
|
+
To install the latest stable version of the package directly from PyPI:
|
|
43
25
|
|
|
44
26
|
```bash
|
|
45
|
-
pip install -
|
|
27
|
+
pip install segment-toolkit
|
|
46
28
|
```
|
|
47
29
|
|
|
48
|
-
###
|
|
49
|
-
If you
|
|
30
|
+
### 2. Local Installation (via Git Clone)
|
|
31
|
+
If you want to clone the repository for local development, run:
|
|
50
32
|
|
|
51
33
|
```bash
|
|
52
|
-
|
|
53
|
-
|
|
34
|
+
# Clone the repository
|
|
35
|
+
git clone https://github.com/zkzkGamal/mask-to-yolo-toolkit.git
|
|
36
|
+
|
|
37
|
+
# Navigate into the project folder
|
|
38
|
+
cd LabelFile-for-yoloModel
|
|
39
|
+
|
|
40
|
+
# Install in editable mode
|
|
41
|
+
pip install -e .
|
|
54
42
|
```
|
|
55
43
|
|
|
56
44
|
---
|
|
57
45
|
|
|
58
|
-
##
|
|
46
|
+
## Usage
|
|
59
47
|
|
|
60
48
|
### 1. Command Line Interface (CLI)
|
|
61
49
|
|
|
62
|
-
The package installs a console script called
|
|
50
|
+
The package installs a console script called segment-toolkit.
|
|
63
51
|
|
|
64
52
|
#### Convert Masks to YOLO Labels
|
|
65
53
|
- **Single File Conversion**:
|
|
@@ -81,8 +69,8 @@ The package installs a console script called `segment-toolkit`.
|
|
|
81
69
|
```
|
|
82
70
|
|
|
83
71
|
- **Options**:
|
|
84
|
-
- `--rotated`: Use rotated minimum area rectangles (
|
|
85
|
-
- `--resize WIDTH HEIGHT`: Set target size for image and mask resizing (default:
|
|
72
|
+
- `--rotated`: Use rotated minimum area rectangles (cv2.minAreaRect) instead of standard axis-aligned rectangles.
|
|
73
|
+
- `--resize WIDTH HEIGHT`: Set target size for image and mask resizing (default: 640 640).
|
|
86
74
|
|
|
87
75
|
#### Convert YOLO Labels to Masks
|
|
88
76
|
- **Single File Conversion**:
|
|
@@ -109,7 +97,7 @@ segment-toolkit visualize \
|
|
|
109
97
|
```
|
|
110
98
|
|
|
111
99
|
#### Split Dataset
|
|
112
|
-
Organize folders into YOLO-compliant structure (
|
|
100
|
+
Organize folders into YOLO-compliant structure (dataset/train and dataset/test splits) and output data.yaml:
|
|
113
101
|
```bash
|
|
114
102
|
segment-toolkit split \
|
|
115
103
|
--images images/ \
|
|
@@ -121,13 +109,32 @@ segment-toolkit split \
|
|
|
121
109
|
|
|
122
110
|
---
|
|
123
111
|
|
|
124
|
-
|
|
112
|
+
## Validation and Demonstration Outputs
|
|
113
|
+
|
|
114
|
+
To verify the library, we run automated validation on sample datasets. All validation output files (YOLO coordinates, reconstructed masks, and drawing overlays) are stored in the [validate_data/](file:///home/aloha-zkaria/LabelFile-for-yoloModel/validate_data) folder.
|
|
115
|
+
|
|
116
|
+
### Validation Overlays
|
|
117
|
+
|
|
118
|
+
Here are the bounding box overlays generated by the toolkit visualizer:
|
|
119
|
+
|
|
120
|
+
#### ISIC Melanoma Skin Lesion Validation
|
|
121
|
+

|
|
122
|
+
|
|
123
|
+
#### Plant Leaf Disease Validation
|
|
124
|
+

|
|
125
|
+
|
|
126
|
+
### Video Demonstration
|
|
127
|
+
A video demonstrating installation, CLI commands, and programming API pipelines can be placed in the [demo/](file:///home/aloha-zkaria/LabelFile-for-yoloModel/demo) directory.
|
|
128
|
+
|
|
129
|
+
---
|
|
130
|
+
|
|
131
|
+
## Ground Truth Formats
|
|
125
132
|
|
|
126
|
-
The
|
|
133
|
+
The --ground-truth parameter in batch conversion supports both CSV and JSON formats.
|
|
127
134
|
|
|
128
135
|
#### CSV Format
|
|
129
|
-
Assumes the first column contains the image identifier/filename, and the subsequent columns represent binary indicator classes (where
|
|
130
|
-
Example
|
|
136
|
+
Assumes the first column contains the image identifier/filename, and the subsequent columns represent binary indicator classes (where 1 indicates class presence).
|
|
137
|
+
Example GroundTruth.csv:
|
|
131
138
|
```csv
|
|
132
139
|
image,MEL,NV,BCC,AKIEC,BKL,DF,VASC
|
|
133
140
|
ISIC_0024306,0,1,0,0,0,0,0
|
|
@@ -164,11 +171,11 @@ Supports three distinct schemas:
|
|
|
164
171
|
]
|
|
165
172
|
```
|
|
166
173
|
|
|
167
|
-
*Note: Class name strings (like
|
|
174
|
+
*Note: Class name strings (like "MEL", "NV") are automatically mapped to standard ISIC IDs (AKIEC=0, BCC=1, BKL=2, DF=3, MEL=4, NV=5, VASC=6). Custom column names default to index-based IDs.*
|
|
168
175
|
|
|
169
176
|
---
|
|
170
177
|
|
|
171
|
-
|
|
178
|
+
## Python API
|
|
172
179
|
|
|
173
180
|
Import classes directly into your code to programmatically build custom pipelines:
|
|
174
181
|
|
|
@@ -195,23 +202,23 @@ yolo_conv.convert_dataset(
|
|
|
195
202
|
|
|
196
203
|
---
|
|
197
204
|
|
|
198
|
-
##
|
|
205
|
+
## Technical Details
|
|
199
206
|
|
|
200
207
|
### Coordinate Conversion Math
|
|
201
208
|
|
|
202
209
|
#### Bounding Box Center Calculation (Pixel Space)
|
|
203
|
-
For standard bounding boxes, the pixel coordinates from
|
|
210
|
+
For standard bounding boxes, the pixel coordinates from boundingRect are (xmin, ymin, w_pixel, h_pixel).
|
|
204
211
|
$$\text{Center } X \quad x_{center} = x_{min} + \frac{w_{pixel}}{2.0}$$
|
|
205
212
|
$$\text{Center } Y \quad y_{center} = y_{min} + \frac{h_{pixel}}{2.0}$$
|
|
206
213
|
|
|
207
214
|
#### Coordinate Normalization (YOLO Format)
|
|
208
|
-
All coordinates are normalized to the range
|
|
215
|
+
All coordinates are normalized to the range [0.0, 1.0]:
|
|
209
216
|
$$x_{norm} = \frac{x_{center}}{img\_width}, \quad y_{norm} = \frac{y_{center}}{img\_height}$$
|
|
210
217
|
$$w_{norm} = \frac{w_{pixel}}{img\_width}, \quad h_{norm} = \frac{h_{pixel}}{img\_height}$$
|
|
211
218
|
|
|
212
219
|
---
|
|
213
220
|
|
|
214
|
-
##
|
|
221
|
+
## Author
|
|
215
222
|
**Zakria Gamal**
|
|
216
|
-
- Computer Vision
|
|
217
|
-
-
|
|
223
|
+
- Computer Vision and AI Engineer
|
|
224
|
+
- LinkedIn: [Zakria Gamal](https://www.linkedin.com/in/zkaria-gamal-82b486267/)
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Main execution entry point for segment_toolkit.
|
|
3
|
+
Enables running the package directly via `python3 -m segment_toolkit` or `python3 segment_toolkit`.
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
import sys
|
|
7
|
+
import os
|
|
8
|
+
|
|
9
|
+
# Add the parent folder of segment_toolkit to sys.path to resolve absolute imports
|
|
10
|
+
parent_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
|
11
|
+
if parent_dir not in sys.path:
|
|
12
|
+
sys.path.insert(0, parent_dir)
|
|
13
|
+
|
|
14
|
+
from segment_toolkit.cli import main
|
|
15
|
+
|
|
16
|
+
if __name__ == "__main__":
|
|
17
|
+
sys.exit(main())
|
|
@@ -1,46 +1,79 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: segment_toolkit
|
|
3
|
+
Version: 1.0.2
|
|
4
|
+
Summary: A Python toolkit to convert between binary segmentation masks and YOLO labels
|
|
5
|
+
Home-page: https://github.com/zkzkGamal/mask-to-yolo-toolkit
|
|
6
|
+
Author: Zakria Gamal
|
|
7
|
+
Author-email: zekogml11@gmail.com
|
|
8
|
+
Project-URL: Source Code, https://github.com/zkzkGamal/mask-to-yolo-toolkit
|
|
9
|
+
Project-URL: Bug Tracker, https://github.com/zkzkGamal/mask-to-yolo-toolkit/issues
|
|
10
|
+
Requires-Python: >=3.6
|
|
11
|
+
Description-Content-Type: text/markdown
|
|
12
|
+
Requires-Dist: numpy
|
|
13
|
+
Requires-Dist: opencv-python
|
|
14
|
+
Requires-Dist: pillow
|
|
15
|
+
Requires-Dist: pandas
|
|
16
|
+
Requires-Dist: matplotlib
|
|
17
|
+
Dynamic: author
|
|
18
|
+
Dynamic: author-email
|
|
19
|
+
Dynamic: description
|
|
20
|
+
Dynamic: description-content-type
|
|
21
|
+
Dynamic: home-page
|
|
22
|
+
Dynamic: project-url
|
|
23
|
+
Dynamic: requires-dist
|
|
24
|
+
Dynamic: requires-python
|
|
25
|
+
Dynamic: summary
|
|
26
|
+
|
|
27
|
+
# Segment Toolkit
|
|
28
|
+
|
|
29
|
+
A modern, robust, and premium Python package designed to bridge the gap between pixel-level binary segmentation masks and YOLO bounding box labels. It provides a bidirectional pipeline with exception handling, extensive logging, a command-line interface (CLI), and a Python API.
|
|
4
30
|
|
|
5
31
|
---
|
|
6
32
|
|
|
7
|
-
##
|
|
33
|
+
## Features
|
|
8
34
|
|
|
9
35
|
- **Bidirectional Conversion**:
|
|
10
36
|
- **Forward Pipeline**: Convert binary masks to YOLO format labels (supports standard axis-aligned or advanced minimum area rotated bounding boxes).
|
|
11
37
|
- **Reverse Pipeline**: Reconstruct binary masks from YOLO labels.
|
|
12
|
-
- **Automatic Dependency Installer**: Missing required packages (
|
|
38
|
+
- **Automatic Dependency Installer**: Missing required packages (numpy, opencv-python, pillow, pandas, matplotlib) are automatically detected and installed via pip upon package import or script execution.
|
|
13
39
|
- **Robust Exception Handling**: Try-catch blocks wrapped around file I/O, contour finding, and resizing to prevent application crashes on corrupted or missing files.
|
|
14
|
-
- **Dynamic Dataset Matching**: Read classification mappings (in
|
|
15
|
-
- **YOLO Dataset Splitting**: Automatically shuffles and partitions images
|
|
40
|
+
- **Dynamic Dataset Matching**: Read classification mappings (in CSV or JSON format) to automatically assign multi-class IDs matching standard dataset schemas (like the ISIC dataset).
|
|
41
|
+
- **YOLO Dataset Splitting**: Automatically shuffles and partitions images and labels into training and testing sets with customizable split ratios, creating standard data.yaml configs.
|
|
16
42
|
- **Overlay Visualizer**: Overlay bounding boxes and class indicators directly onto source images for annotation inspection.
|
|
17
|
-
- **Dual Interface**: Use as a command-line application (
|
|
43
|
+
- **Dual Interface**: Use as a command-line application (segment-toolkit) or import as a Python library (import segment_toolkit).
|
|
18
44
|
|
|
19
45
|
---
|
|
20
46
|
|
|
21
|
-
##
|
|
47
|
+
## Installation
|
|
22
48
|
|
|
23
|
-
|
|
49
|
+
### 1. Standard Installation (via PyPI)
|
|
50
|
+
To install the latest stable version of the package directly from PyPI:
|
|
24
51
|
|
|
25
52
|
```bash
|
|
26
|
-
pip install -
|
|
53
|
+
pip install segment-toolkit
|
|
27
54
|
```
|
|
28
55
|
|
|
29
|
-
###
|
|
30
|
-
If you
|
|
56
|
+
### 2. Local Installation (via Git Clone)
|
|
57
|
+
If you want to clone the repository for local development, run:
|
|
31
58
|
|
|
32
59
|
```bash
|
|
33
|
-
|
|
34
|
-
|
|
60
|
+
# Clone the repository
|
|
61
|
+
git clone https://github.com/zkzkGamal/mask-to-yolo-toolkit.git
|
|
62
|
+
|
|
63
|
+
# Navigate into the project folder
|
|
64
|
+
cd LabelFile-for-yoloModel
|
|
65
|
+
|
|
66
|
+
# Install in editable mode
|
|
67
|
+
pip install -e .
|
|
35
68
|
```
|
|
36
69
|
|
|
37
70
|
---
|
|
38
71
|
|
|
39
|
-
##
|
|
72
|
+
## Usage
|
|
40
73
|
|
|
41
74
|
### 1. Command Line Interface (CLI)
|
|
42
75
|
|
|
43
|
-
The package installs a console script called
|
|
76
|
+
The package installs a console script called segment-toolkit.
|
|
44
77
|
|
|
45
78
|
#### Convert Masks to YOLO Labels
|
|
46
79
|
- **Single File Conversion**:
|
|
@@ -62,8 +95,8 @@ The package installs a console script called `segment-toolkit`.
|
|
|
62
95
|
```
|
|
63
96
|
|
|
64
97
|
- **Options**:
|
|
65
|
-
- `--rotated`: Use rotated minimum area rectangles (
|
|
66
|
-
- `--resize WIDTH HEIGHT`: Set target size for image and mask resizing (default:
|
|
98
|
+
- `--rotated`: Use rotated minimum area rectangles (cv2.minAreaRect) instead of standard axis-aligned rectangles.
|
|
99
|
+
- `--resize WIDTH HEIGHT`: Set target size for image and mask resizing (default: 640 640).
|
|
67
100
|
|
|
68
101
|
#### Convert YOLO Labels to Masks
|
|
69
102
|
- **Single File Conversion**:
|
|
@@ -90,7 +123,7 @@ segment-toolkit visualize \
|
|
|
90
123
|
```
|
|
91
124
|
|
|
92
125
|
#### Split Dataset
|
|
93
|
-
Organize folders into YOLO-compliant structure (
|
|
126
|
+
Organize folders into YOLO-compliant structure (dataset/train and dataset/test splits) and output data.yaml:
|
|
94
127
|
```bash
|
|
95
128
|
segment-toolkit split \
|
|
96
129
|
--images images/ \
|
|
@@ -102,13 +135,32 @@ segment-toolkit split \
|
|
|
102
135
|
|
|
103
136
|
---
|
|
104
137
|
|
|
105
|
-
|
|
138
|
+
## Validation and Demonstration Outputs
|
|
139
|
+
|
|
140
|
+
To verify the library, we run automated validation on sample datasets. All validation output files (YOLO coordinates, reconstructed masks, and drawing overlays) are stored in the [validate_data/](file:///home/aloha-zkaria/LabelFile-for-yoloModel/validate_data) folder.
|
|
141
|
+
|
|
142
|
+
### Validation Overlays
|
|
143
|
+
|
|
144
|
+
Here are the bounding box overlays generated by the toolkit visualizer:
|
|
145
|
+
|
|
146
|
+
#### ISIC Melanoma Skin Lesion Validation
|
|
147
|
+

|
|
148
|
+
|
|
149
|
+
#### Plant Leaf Disease Validation
|
|
150
|
+

|
|
151
|
+
|
|
152
|
+
### Video Demonstration
|
|
153
|
+
A video demonstrating installation, CLI commands, and programming API pipelines can be placed in the [demo/](file:///home/aloha-zkaria/LabelFile-for-yoloModel/demo) directory.
|
|
154
|
+
|
|
155
|
+
---
|
|
156
|
+
|
|
157
|
+
## Ground Truth Formats
|
|
106
158
|
|
|
107
|
-
The
|
|
159
|
+
The --ground-truth parameter in batch conversion supports both CSV and JSON formats.
|
|
108
160
|
|
|
109
161
|
#### CSV Format
|
|
110
|
-
Assumes the first column contains the image identifier/filename, and the subsequent columns represent binary indicator classes (where
|
|
111
|
-
Example
|
|
162
|
+
Assumes the first column contains the image identifier/filename, and the subsequent columns represent binary indicator classes (where 1 indicates class presence).
|
|
163
|
+
Example GroundTruth.csv:
|
|
112
164
|
```csv
|
|
113
165
|
image,MEL,NV,BCC,AKIEC,BKL,DF,VASC
|
|
114
166
|
ISIC_0024306,0,1,0,0,0,0,0
|
|
@@ -145,11 +197,11 @@ Supports three distinct schemas:
|
|
|
145
197
|
]
|
|
146
198
|
```
|
|
147
199
|
|
|
148
|
-
*Note: Class name strings (like
|
|
200
|
+
*Note: Class name strings (like "MEL", "NV") are automatically mapped to standard ISIC IDs (AKIEC=0, BCC=1, BKL=2, DF=3, MEL=4, NV=5, VASC=6). Custom column names default to index-based IDs.*
|
|
149
201
|
|
|
150
202
|
---
|
|
151
203
|
|
|
152
|
-
|
|
204
|
+
## Python API
|
|
153
205
|
|
|
154
206
|
Import classes directly into your code to programmatically build custom pipelines:
|
|
155
207
|
|
|
@@ -176,23 +228,23 @@ yolo_conv.convert_dataset(
|
|
|
176
228
|
|
|
177
229
|
---
|
|
178
230
|
|
|
179
|
-
##
|
|
231
|
+
## Technical Details
|
|
180
232
|
|
|
181
233
|
### Coordinate Conversion Math
|
|
182
234
|
|
|
183
235
|
#### Bounding Box Center Calculation (Pixel Space)
|
|
184
|
-
For standard bounding boxes, the pixel coordinates from
|
|
236
|
+
For standard bounding boxes, the pixel coordinates from boundingRect are (xmin, ymin, w_pixel, h_pixel).
|
|
185
237
|
$$\text{Center } X \quad x_{center} = x_{min} + \frac{w_{pixel}}{2.0}$$
|
|
186
238
|
$$\text{Center } Y \quad y_{center} = y_{min} + \frac{h_{pixel}}{2.0}$$
|
|
187
239
|
|
|
188
240
|
#### Coordinate Normalization (YOLO Format)
|
|
189
|
-
All coordinates are normalized to the range
|
|
241
|
+
All coordinates are normalized to the range [0.0, 1.0]:
|
|
190
242
|
$$x_{norm} = \frac{x_{center}}{img\_width}, \quad y_{norm} = \frac{y_{center}}{img\_height}$$
|
|
191
243
|
$$w_{norm} = \frac{w_{pixel}}{img\_width}, \quad h_{norm} = \frac{h_{pixel}}{img\_height}$$
|
|
192
244
|
|
|
193
245
|
---
|
|
194
246
|
|
|
195
|
-
##
|
|
247
|
+
## Author
|
|
196
248
|
**Zakria Gamal**
|
|
197
|
-
- Computer Vision
|
|
198
|
-
-
|
|
249
|
+
- Computer Vision and AI Engineer
|
|
250
|
+
- LinkedIn: [Zakria Gamal](https://www.linkedin.com/in/zkaria-gamal-82b486267/)
|
|
@@ -10,11 +10,17 @@ except FileNotFoundError:
|
|
|
10
10
|
|
|
11
11
|
setup(
|
|
12
12
|
name="segment_toolkit",
|
|
13
|
-
version="1.0.
|
|
13
|
+
version="1.0.2",
|
|
14
14
|
description="A Python toolkit to convert between binary segmentation masks and YOLO labels",
|
|
15
15
|
long_description=long_description,
|
|
16
16
|
long_description_content_type="text/markdown",
|
|
17
|
-
author="
|
|
17
|
+
author="Zakria Gamal",
|
|
18
|
+
author_email="zekogml11@gmail.com",
|
|
19
|
+
url="https://github.com/zkzkGamal/mask-to-yolo-toolkit",
|
|
20
|
+
project_urls={
|
|
21
|
+
"Source Code": "https://github.com/zkzkGamal/mask-to-yolo-toolkit",
|
|
22
|
+
"Bug Tracker": "https://github.com/zkzkGamal/mask-to-yolo-toolkit/issues",
|
|
23
|
+
},
|
|
18
24
|
packages=find_packages(),
|
|
19
25
|
install_requires=[
|
|
20
26
|
"numpy",
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{segment_toolkit-1.0.0 → segment_toolkit-1.0.2}/segment_toolkit.egg-info/dependency_links.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|