spacial 0.1.0__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.
- spacial-0.1.0/PKG-INFO +545 -0
- spacial-0.1.0/docs.md +519 -0
- spacial-0.1.0/pyproject.toml +56 -0
- spacial-0.1.0/setup.cfg +4 -0
- spacial-0.1.0/spacial/__init__.py +669 -0
- spacial-0.1.0/spacial.egg-info/PKG-INFO +545 -0
- spacial-0.1.0/spacial.egg-info/SOURCES.txt +8 -0
- spacial-0.1.0/spacial.egg-info/dependency_links.txt +1 -0
- spacial-0.1.0/spacial.egg-info/requires.txt +2 -0
- spacial-0.1.0/spacial.egg-info/top_level.txt +1 -0
spacial-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,545 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: spacial
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A lightweight synthetic dataset image generation library built on top of Pillow.
|
|
5
|
+
Author: Spacial Contributors
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/your-org/spacial
|
|
8
|
+
Project-URL: Documentation, https://github.com/your-org/spacial/blob/main/docs.md
|
|
9
|
+
Project-URL: Issues, https://github.com/your-org/spacial/issues
|
|
10
|
+
Keywords: synthetic data,image generation,dataset,bounding box,segmentation,pillow
|
|
11
|
+
Classifier: Development Status :: 3 - Alpha
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: Intended Audience :: Science/Research
|
|
14
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
20
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
21
|
+
Classifier: Topic :: Scientific/Engineering :: Image Processing
|
|
22
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
23
|
+
Requires-Python: >=3.9
|
|
24
|
+
Description-Content-Type: text/markdown
|
|
25
|
+
Provides-Extra: dev
|
|
26
|
+
|
|
27
|
+
# Spacial
|
|
28
|
+
|
|
29
|
+
> Lightweight synthetic dataset image generation — powered by Pillow.
|
|
30
|
+
|
|
31
|
+
[](https://www.python.org/)
|
|
32
|
+
[](LICENSE)
|
|
33
|
+
[]()
|
|
34
|
+
|
|
35
|
+
Spacial is a small, focused library for generating synthetic training images and their annotations. You describe what to put on a canvas — backgrounds, shapes, images — and Spacial gives you back pixel-perfect bounding boxes and segmentation masks in plain Python data structures. No frameworks. No hidden config files. No magic.
|
|
36
|
+
|
|
37
|
+
---
|
|
38
|
+
|
|
39
|
+
## Contents
|
|
40
|
+
|
|
41
|
+
- [Installation](#installation)
|
|
42
|
+
- [Quick Start](#quick-start)
|
|
43
|
+
- [Design Philosophy](#design-philosophy)
|
|
44
|
+
- [API Reference](#api-reference)
|
|
45
|
+
- [init](#init)
|
|
46
|
+
- [background](#background)
|
|
47
|
+
- [shape / shape_add](#shape--shape_add)
|
|
48
|
+
- [append](#append)
|
|
49
|
+
- [bbox](#bbox)
|
|
50
|
+
- [seg](#seg)
|
|
51
|
+
- [save](#save)
|
|
52
|
+
- [rm](#rm)
|
|
53
|
+
- [Fill System](#fill-system)
|
|
54
|
+
- [Examples](#examples)
|
|
55
|
+
- [Exporting Annotations](#exporting-annotations)
|
|
56
|
+
- [Future Roadmap](#future-roadmap)
|
|
57
|
+
|
|
58
|
+
---
|
|
59
|
+
|
|
60
|
+
## Installation
|
|
61
|
+
|
|
62
|
+
```bash
|
|
63
|
+
pip install spacial
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
Spacial requires **Python 3.9+** and **Pillow ≥ 10.0**.
|
|
67
|
+
|
|
68
|
+
---
|
|
69
|
+
|
|
70
|
+
## Quick Start
|
|
71
|
+
|
|
72
|
+
```python
|
|
73
|
+
import spacial
|
|
74
|
+
|
|
75
|
+
# 1. Set up a 640×480 canvas
|
|
76
|
+
spacial.init(w=640, h=480)
|
|
77
|
+
|
|
78
|
+
# 2. Dark gradient background
|
|
79
|
+
spacial.background("gradient", fill={
|
|
80
|
+
"type": "gradient",
|
|
81
|
+
"start": "#1A1A2E",
|
|
82
|
+
"end": "#16213E",
|
|
83
|
+
"direction": "vertical",
|
|
84
|
+
})
|
|
85
|
+
|
|
86
|
+
# 3. Define a reusable shape template
|
|
87
|
+
spacial.shape("car", w=120, h=60)
|
|
88
|
+
spacial.shape_add("car", "rectangle", fill="#E63946", x0=0, y0=10, x1=120, y1=60)
|
|
89
|
+
spacial.shape_add("car", "rectangle", fill="#222222", x0=20, y0=0, x1=100, y1=20)
|
|
90
|
+
|
|
91
|
+
# 4. Place two cars on the canvas
|
|
92
|
+
spacial.append("car_001", "car", x=50, y=200)
|
|
93
|
+
spacial.append("car_002", "car", x=350, y=300)
|
|
94
|
+
|
|
95
|
+
# 5. Get annotations
|
|
96
|
+
print(spacial.bbox())
|
|
97
|
+
# [
|
|
98
|
+
# {"id": "car_001", "class": "car", "bbox": [50, 200, 170, 260]},
|
|
99
|
+
# {"id": "car_002", "class": "car", "bbox": [350, 300, 470, 360]},
|
|
100
|
+
# ]
|
|
101
|
+
|
|
102
|
+
# 6. Save and reset
|
|
103
|
+
spacial.save("frame_001.png")
|
|
104
|
+
spacial.rm()
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
---
|
|
108
|
+
|
|
109
|
+
## Design Philosophy
|
|
110
|
+
|
|
111
|
+
Spacial is deliberately narrow. It does exactly three things:
|
|
112
|
+
|
|
113
|
+
1. **Generate images** — backgrounds, shapes, composited objects.
|
|
114
|
+
2. **Generate bounding box annotations** — pixel-aligned `[x1, y1, x2, y2]`.
|
|
115
|
+
3. **Generate segmentation annotations** — per-pixel binary masks.
|
|
116
|
+
|
|
117
|
+
Everything else — writing COCO JSON, YOLO `.txt` files, Pascal VOC XML, training loops, data augmentation — is intentionally left to you. Spacial integrates cleanly with whatever export or training pipeline you already have, because it only returns standard Python lists and dicts.
|
|
118
|
+
|
|
119
|
+
**Guiding principles:**
|
|
120
|
+
|
|
121
|
+
- **Flat API.** Everything is a module-level function. No classes to instantiate, no context managers to juggle.
|
|
122
|
+
- **Minimal dependencies.** Only Pillow. No NumPy required (though masks are trivial to convert).
|
|
123
|
+
- **Beginner friendly.** If you can write `spacial.append(...)` and `spacial.save(...)`, you have a dataset.
|
|
124
|
+
- **Standard types.** Returns `list`, `dict`, and `tuple` — no custom objects to unwrap.
|
|
125
|
+
- **Both colour notations.** RGB tuples `(255, 0, 0)` and hex strings `"#FF0000"` work everywhere a colour is expected.
|
|
126
|
+
|
|
127
|
+
---
|
|
128
|
+
|
|
129
|
+
## API Reference
|
|
130
|
+
|
|
131
|
+
### `init`
|
|
132
|
+
|
|
133
|
+
```python
|
|
134
|
+
spacial.init(device="cpu", w=1024, h=1024)
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
Initialise Spacial and create a blank canvas.
|
|
138
|
+
|
|
139
|
+
| Parameter | Type | Default | Description |
|
|
140
|
+
|-----------|-------|---------|------------------------------------------------------|
|
|
141
|
+
| `device` | `str` | `"cpu"` | Compute device: `"cpu"`, `"cuda"`, or `"mps"`. `cuda` and `mps` are reserved for future GPU acceleration and currently behave identically to `cpu`. |
|
|
142
|
+
| `w` | `int` | `1024` | Canvas width in pixels. |
|
|
143
|
+
| `h` | `int` | `1024` | Canvas height in pixels. |
|
|
144
|
+
|
|
145
|
+
---
|
|
146
|
+
|
|
147
|
+
### `background`
|
|
148
|
+
|
|
149
|
+
```python
|
|
150
|
+
spacial.background(bg_type, *, fill=..., path=None, seed=None)
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
Fill the entire canvas with a background.
|
|
154
|
+
|
|
155
|
+
| Parameter | Type | Description |
|
|
156
|
+
|-----------|------------------|----------------------------------------------------------|
|
|
157
|
+
| `bg_type` | `str` | `"color"`, `"gradient"`, `"noise"`, `"perlin"`, `"img"` |
|
|
158
|
+
| `fill` | colour or `dict` | Colour value or fill spec (see [Fill System](#fill-system)) |
|
|
159
|
+
| `path` | `str \| None` | Path to source image — required for `bg_type="img"`. |
|
|
160
|
+
| `seed` | `int \| None` | Random seed for reproducible noise/perlin backgrounds. |
|
|
161
|
+
|
|
162
|
+
**Examples:**
|
|
163
|
+
|
|
164
|
+
```python
|
|
165
|
+
# Solid colour
|
|
166
|
+
spacial.background("color", fill=(30, 30, 30))
|
|
167
|
+
spacial.background("color", fill="#1A1A2E")
|
|
168
|
+
|
|
169
|
+
# Horizontal gradient
|
|
170
|
+
spacial.background("gradient", fill={
|
|
171
|
+
"type": "gradient",
|
|
172
|
+
"start": "#FF6B6B",
|
|
173
|
+
"end": "#4ECDC4",
|
|
174
|
+
"direction": "horizontal",
|
|
175
|
+
})
|
|
176
|
+
|
|
177
|
+
# Seeded noise
|
|
178
|
+
spacial.background("noise", fill={
|
|
179
|
+
"type": "noise",
|
|
180
|
+
"base": (100, 100, 100),
|
|
181
|
+
"scale": 0.4,
|
|
182
|
+
}, seed=42)
|
|
183
|
+
|
|
184
|
+
# Perlin-like noise
|
|
185
|
+
spacial.background("perlin", fill={
|
|
186
|
+
"type": "perlin",
|
|
187
|
+
"base": "#2C3E50",
|
|
188
|
+
"scale": 0.6,
|
|
189
|
+
"octaves": 5,
|
|
190
|
+
}, seed=7)
|
|
191
|
+
|
|
192
|
+
# From an existing image file
|
|
193
|
+
spacial.background("img", path="sky.jpg")
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
---
|
|
197
|
+
|
|
198
|
+
### `shape` / `shape_add`
|
|
199
|
+
|
|
200
|
+
```python
|
|
201
|
+
spacial.shape(name, *, w, h)
|
|
202
|
+
spacial.shape_add(name, primitive, *, fill=..., **params)
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
Define a reusable shape template by stacking primitives.
|
|
206
|
+
|
|
207
|
+
**`shape`**
|
|
208
|
+
|
|
209
|
+
| Parameter | Type | Description |
|
|
210
|
+
|-----------|-------|--------------------------------|
|
|
211
|
+
| `name` | `str` | Unique template name. |
|
|
212
|
+
| `w` | `int` | Template width in pixels. |
|
|
213
|
+
| `h` | `int` | Template height in pixels. |
|
|
214
|
+
|
|
215
|
+
**`shape_add` — primitives**
|
|
216
|
+
|
|
217
|
+
| Primitive | Required params | Description |
|
|
218
|
+
|---------------|-----------------------------------------|-------------------------------------|
|
|
219
|
+
| `"circle"` | `cx`, `cy`, `r` | Circle with centre and radius. |
|
|
220
|
+
| `"rectangle"` | `x0`, `y0`, `x1`, `y1` | Axis-aligned rectangle. |
|
|
221
|
+
| `"img"` | `path`, optionally `x`, `y` | Paste an image at an offset. |
|
|
222
|
+
|
|
223
|
+
All primitives accept a `fill` parameter (colour or fill spec).
|
|
224
|
+
|
|
225
|
+
**Example:**
|
|
226
|
+
|
|
227
|
+
```python
|
|
228
|
+
spacial.shape("traffic_light", w=40, h=100)
|
|
229
|
+
spacial.shape_add("traffic_light", "rectangle", fill="#222222", x0=0, y0=0, x1=40, y1=100)
|
|
230
|
+
spacial.shape_add("traffic_light", "circle", fill="#FF0000", cx=20, cy=20, r=14)
|
|
231
|
+
spacial.shape_add("traffic_light", "circle", fill="#FFA500", cx=20, cy=50, r=14)
|
|
232
|
+
spacial.shape_add("traffic_light", "circle", fill="#00CC00", cx=20, cy=80, r=14)
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
---
|
|
236
|
+
|
|
237
|
+
### `append`
|
|
238
|
+
|
|
239
|
+
```python
|
|
240
|
+
spacial.append(obj_id, obj_class, *, x=0, y=0, **kwargs)
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
Place an object on the canvas and record its annotation.
|
|
244
|
+
|
|
245
|
+
| Parameter | Type | Description |
|
|
246
|
+
|-------------|-------|-----------------------------------------------------------------------------|
|
|
247
|
+
| `obj_id` | `str` | Unique instance ID used in annotation output. |
|
|
248
|
+
| `obj_class` | `str` | A registered shape name, `"img"`, or any free-form label. |
|
|
249
|
+
| `x` | `int` | Left edge of the object in canvas pixels. |
|
|
250
|
+
| `y` | `int` | Top edge of the object in canvas pixels. |
|
|
251
|
+
| `**kwargs` | | Forwarded to the renderer: `path`, `w`, `h`, `fill`, etc. |
|
|
252
|
+
|
|
253
|
+
**Class resolution order:**
|
|
254
|
+
|
|
255
|
+
1. If `obj_class` matches a registered shape name → render that template.
|
|
256
|
+
2. If `obj_class == "img"` → load the image at `path=`.
|
|
257
|
+
3. Otherwise → render a placeholder rectangle using `fill=`, `w=`, `h=`.
|
|
258
|
+
|
|
259
|
+
**Examples:**
|
|
260
|
+
|
|
261
|
+
```python
|
|
262
|
+
# Named shape
|
|
263
|
+
spacial.append("tl_north", "traffic_light", x=100, y=50)
|
|
264
|
+
|
|
265
|
+
# Inline image
|
|
266
|
+
spacial.append("sponsor_logo", "img", path="logo.png", x=20, y=20)
|
|
267
|
+
|
|
268
|
+
# Placeholder (useful for layout testing)
|
|
269
|
+
spacial.append("unknown_001", "unknown", x=300, y=150, fill="#AAAAAA", w=80, h=80)
|
|
270
|
+
```
|
|
271
|
+
|
|
272
|
+
---
|
|
273
|
+
|
|
274
|
+
### `bbox`
|
|
275
|
+
|
|
276
|
+
```python
|
|
277
|
+
spacial.bbox(obj_id=None) -> list[dict]
|
|
278
|
+
```
|
|
279
|
+
|
|
280
|
+
Return bounding-box annotations.
|
|
281
|
+
|
|
282
|
+
```python
|
|
283
|
+
[
|
|
284
|
+
{
|
|
285
|
+
"id": "car_001",
|
|
286
|
+
"class": "car",
|
|
287
|
+
"bbox": [x1, y1, x2, y2] # pixel coordinates, inclusive corners
|
|
288
|
+
},
|
|
289
|
+
...
|
|
290
|
+
]
|
|
291
|
+
```
|
|
292
|
+
|
|
293
|
+
Pass `obj_id="car_001"` to retrieve a single object's annotation.
|
|
294
|
+
|
|
295
|
+
---
|
|
296
|
+
|
|
297
|
+
### `seg`
|
|
298
|
+
|
|
299
|
+
```python
|
|
300
|
+
spacial.seg(obj_id=None) -> list[dict]
|
|
301
|
+
```
|
|
302
|
+
|
|
303
|
+
Return segmentation annotations.
|
|
304
|
+
|
|
305
|
+
```python
|
|
306
|
+
[
|
|
307
|
+
{
|
|
308
|
+
"id": "car_001",
|
|
309
|
+
"class": "car",
|
|
310
|
+
"bbox": [x1, y1, x2, y2],
|
|
311
|
+
"mask": [...], # flat list, len == w * h, values 0 or 255
|
|
312
|
+
"mask_size": (w, h)
|
|
313
|
+
},
|
|
314
|
+
...
|
|
315
|
+
]
|
|
316
|
+
```
|
|
317
|
+
|
|
318
|
+
**Converting the mask to a NumPy array** (NumPy is not a Spacial dependency, but it is easy to integrate):
|
|
319
|
+
|
|
320
|
+
```python
|
|
321
|
+
import numpy as np
|
|
322
|
+
|
|
323
|
+
entries = spacial.seg()
|
|
324
|
+
w, h = entries[0]["mask_size"]
|
|
325
|
+
mask = np.array(entries[0]["mask"], dtype=np.uint8).reshape(h, w)
|
|
326
|
+
```
|
|
327
|
+
|
|
328
|
+
---
|
|
329
|
+
|
|
330
|
+
### `save`
|
|
331
|
+
|
|
332
|
+
```python
|
|
333
|
+
spacial.save(path)
|
|
334
|
+
```
|
|
335
|
+
|
|
336
|
+
Save the current canvas to disk. The file format is inferred from the extension by Pillow (`.png`, `.jpg`, `.bmp`, `.webp`, etc.).
|
|
337
|
+
|
|
338
|
+
```python
|
|
339
|
+
spacial.save("output/frame_042.png")
|
|
340
|
+
```
|
|
341
|
+
|
|
342
|
+
---
|
|
343
|
+
|
|
344
|
+
### `rm`
|
|
345
|
+
|
|
346
|
+
```python
|
|
347
|
+
spacial.rm()
|
|
348
|
+
```
|
|
349
|
+
|
|
350
|
+
Clear the canvas to black and remove all placed objects. Shape templates are kept so you can reuse them in the next frame.
|
|
351
|
+
|
|
352
|
+
---
|
|
353
|
+
|
|
354
|
+
## Fill System
|
|
355
|
+
|
|
356
|
+
Wherever a `fill` parameter is accepted, Spacial understands two notations:
|
|
357
|
+
|
|
358
|
+
**Solid colour**
|
|
359
|
+
|
|
360
|
+
```python
|
|
361
|
+
fill=(255, 99, 71) # RGB tuple
|
|
362
|
+
fill="#FF6347" # hex string (with or without #)
|
|
363
|
+
```
|
|
364
|
+
|
|
365
|
+
**Gradient**
|
|
366
|
+
|
|
367
|
+
```python
|
|
368
|
+
fill={
|
|
369
|
+
"type": "gradient",
|
|
370
|
+
"start": "#FF6B6B", # any colour value
|
|
371
|
+
"end": "#4ECDC4",
|
|
372
|
+
"direction": "horizontal", # or "vertical"
|
|
373
|
+
}
|
|
374
|
+
```
|
|
375
|
+
|
|
376
|
+
**Noise** (uniform random per-pixel offsets from a base colour)
|
|
377
|
+
|
|
378
|
+
```python
|
|
379
|
+
fill={
|
|
380
|
+
"type": "noise",
|
|
381
|
+
"base": (128, 128, 128),
|
|
382
|
+
"scale": 0.5, # 0.0 → no noise, 1.0 → maximum noise
|
|
383
|
+
}
|
|
384
|
+
```
|
|
385
|
+
|
|
386
|
+
**Perlin** (layered smooth noise — good for terrain-like backgrounds)
|
|
387
|
+
|
|
388
|
+
```python
|
|
389
|
+
fill={
|
|
390
|
+
"type": "perlin",
|
|
391
|
+
"base": "#2C3E50",
|
|
392
|
+
"scale": 0.6,
|
|
393
|
+
"octaves": 4, # more octaves → more detail
|
|
394
|
+
}
|
|
395
|
+
```
|
|
396
|
+
|
|
397
|
+
---
|
|
398
|
+
|
|
399
|
+
## Examples
|
|
400
|
+
|
|
401
|
+
### Minimal YOLO-style loop
|
|
402
|
+
|
|
403
|
+
```python
|
|
404
|
+
import json
|
|
405
|
+
import spacial
|
|
406
|
+
|
|
407
|
+
spacial.init(w=416, h=416)
|
|
408
|
+
|
|
409
|
+
dataset = []
|
|
410
|
+
for i in range(100):
|
|
411
|
+
spacial.rm()
|
|
412
|
+
spacial.background("noise", fill={"type": "noise", "base": (80, 80, 80), "scale": 0.3}, seed=i)
|
|
413
|
+
|
|
414
|
+
spacial.shape("ball", w=32, h=32)
|
|
415
|
+
spacial.shape_add("ball", "circle", fill="#F72585", cx=16, cy=16, r=15)
|
|
416
|
+
|
|
417
|
+
x, y = i * 3 % 380, i * 7 % 380
|
|
418
|
+
spacial.append(f"ball_{i:04d}", "ball", x=x, y=y)
|
|
419
|
+
|
|
420
|
+
boxes = spacial.bbox()
|
|
421
|
+
spacial.save(f"images/frame_{i:04d}.png")
|
|
422
|
+
dataset.append({"frame": i, "annotations": boxes})
|
|
423
|
+
|
|
424
|
+
with open("annotations.json", "w") as f:
|
|
425
|
+
json.dump(dataset, f, indent=2)
|
|
426
|
+
```
|
|
427
|
+
|
|
428
|
+
### Multi-class scene
|
|
429
|
+
|
|
430
|
+
```python
|
|
431
|
+
import spacial
|
|
432
|
+
|
|
433
|
+
spacial.init(w=800, h=600)
|
|
434
|
+
spacial.background("perlin", fill={
|
|
435
|
+
"type": "perlin",
|
|
436
|
+
"base": (34, 85, 34),
|
|
437
|
+
"scale": 0.5,
|
|
438
|
+
"octaves": 5,
|
|
439
|
+
}, seed=99)
|
|
440
|
+
|
|
441
|
+
# Define classes
|
|
442
|
+
spacial.shape("vehicle", w=100, h=50)
|
|
443
|
+
spacial.shape_add("vehicle", "rectangle", fill="#264653", x0=0, y0=10, x1=100, y1=50)
|
|
444
|
+
spacial.shape_add("vehicle", "rectangle", fill="#2A9D8F", x0=15, y0=0, x1=85, y1=20)
|
|
445
|
+
|
|
446
|
+
spacial.shape("pedestrian", w=20, h=50)
|
|
447
|
+
spacial.shape_add("pedestrian", "rectangle", fill="#E9C46A", x0=6, y0=0, x1=14, y1=12) # head
|
|
448
|
+
spacial.shape_add("pedestrian", "rectangle", fill="#F4A261", x0=4, y0=12, x1=16, y1=50) # body
|
|
449
|
+
|
|
450
|
+
# Populate scene
|
|
451
|
+
spacial.append("v_001", "vehicle", x=50, y=280)
|
|
452
|
+
spacial.append("v_002", "vehicle", x=400, y=320)
|
|
453
|
+
spacial.append("p_001", "pedestrian", x=250, y=260)
|
|
454
|
+
spacial.append("p_002", "pedestrian", x=310, y=270)
|
|
455
|
+
spacial.append("p_003", "pedestrian", x=600, y=290)
|
|
456
|
+
|
|
457
|
+
print(spacial.bbox())
|
|
458
|
+
spacial.save("scene.png")
|
|
459
|
+
```
|
|
460
|
+
|
|
461
|
+
### Pasting real images with segmentation
|
|
462
|
+
|
|
463
|
+
```python
|
|
464
|
+
import spacial
|
|
465
|
+
|
|
466
|
+
spacial.init(w=512, h=512)
|
|
467
|
+
spacial.background("color", fill="#F0F0F0")
|
|
468
|
+
|
|
469
|
+
spacial.append("product_01", "img", path="product.png", x=128, y=128)
|
|
470
|
+
|
|
471
|
+
for entry in spacial.seg():
|
|
472
|
+
w, h = entry["mask_size"]
|
|
473
|
+
total = w * h
|
|
474
|
+
hit = sum(1 for v in entry["mask"] if v > 0)
|
|
475
|
+
print(f'{entry["id"]} covers {hit/total:.1%} of the canvas')
|
|
476
|
+
|
|
477
|
+
spacial.save("product_scene.png")
|
|
478
|
+
```
|
|
479
|
+
|
|
480
|
+
---
|
|
481
|
+
|
|
482
|
+
## Exporting Annotations
|
|
483
|
+
|
|
484
|
+
Spacial returns plain Python dicts so you can convert to any format you need:
|
|
485
|
+
|
|
486
|
+
**YOLO `.txt`**
|
|
487
|
+
|
|
488
|
+
```python
|
|
489
|
+
boxes = spacial.bbox()
|
|
490
|
+
W, H = 640, 480
|
|
491
|
+
|
|
492
|
+
with open("labels/frame_001.txt", "w") as f:
|
|
493
|
+
class_map = {"car": 0, "pedestrian": 1}
|
|
494
|
+
for obj in boxes:
|
|
495
|
+
x1, y1, x2, y2 = obj["bbox"]
|
|
496
|
+
cx = ((x1 + x2) / 2) / W
|
|
497
|
+
cy = ((y1 + y2) / 2) / H
|
|
498
|
+
bw = (x2 - x1) / W
|
|
499
|
+
bh = (y2 - y1) / H
|
|
500
|
+
cls = class_map.get(obj["class"], 0)
|
|
501
|
+
f.write(f"{cls} {cx:.6f} {cy:.6f} {bw:.6f} {bh:.6f}\n")
|
|
502
|
+
```
|
|
503
|
+
|
|
504
|
+
**COCO-style JSON snippet**
|
|
505
|
+
|
|
506
|
+
```python
|
|
507
|
+
boxes = spacial.bbox()
|
|
508
|
+
coco_annotations = [
|
|
509
|
+
{
|
|
510
|
+
"id": i,
|
|
511
|
+
"image_id": 42,
|
|
512
|
+
"category_id": 1,
|
|
513
|
+
"bbox": [b["bbox"][0], b["bbox"][1],
|
|
514
|
+
b["bbox"][2] - b["bbox"][0],
|
|
515
|
+
b["bbox"][3] - b["bbox"][1]],
|
|
516
|
+
"area": (b["bbox"][2] - b["bbox"][0]) * (b["bbox"][3] - b["bbox"][1]),
|
|
517
|
+
"iscrowd": 0,
|
|
518
|
+
}
|
|
519
|
+
for i, b in enumerate(boxes)
|
|
520
|
+
]
|
|
521
|
+
```
|
|
522
|
+
|
|
523
|
+
---
|
|
524
|
+
|
|
525
|
+
## Future Roadmap
|
|
526
|
+
|
|
527
|
+
Spacial is intentionally minimal today. Planned additions in future releases:
|
|
528
|
+
|
|
529
|
+
- **Shape nesting** — embed one named shape inside another to build hierarchical objects.
|
|
530
|
+
- **Transforms** — per-object rotation, scaling, and opacity.
|
|
531
|
+
- **GPU acceleration** — real CUDA/MPS paths for faster noise generation at high resolutions.
|
|
532
|
+
- **Z-ordering** — explicit depth control for overlapping objects.
|
|
533
|
+
- **Polygon segmentation** — return polygon contours in addition to binary masks.
|
|
534
|
+
- **Single-object annotation queries** — `spacial.bbox("car_001")` already supported; will expand.
|
|
535
|
+
- **Text primitive** — render text labels directly onto shapes.
|
|
536
|
+
- **Physics-based placement** — non-overlapping random placement helpers.
|
|
537
|
+
- **Built-in augmentations** — optional blur, brightness jitter, and crop directly in Spacial.
|
|
538
|
+
|
|
539
|
+
Spacial will never grow into a training framework or annotation exporter. Those concerns belong in your pipeline, not ours.
|
|
540
|
+
|
|
541
|
+
---
|
|
542
|
+
|
|
543
|
+
## License
|
|
544
|
+
|
|
545
|
+
MIT © Spacial Contributors
|