File size: 8,509 Bytes
bcf93e2
 
74465f4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b1d9477
 
 
 
74465f4
 
 
 
 
 
b1d9477
74465f4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c8090a0
74465f4
 
b1d9477
c8090a0
b1d9477
 
c8090a0
b1d9477
c8090a0
 
 
 
b1d9477
 
 
 
 
c8090a0
b1d9477
 
 
 
74465f4
b1d9477
74465f4
 
 
 
c8090a0
74465f4
 
c8090a0
 
 
 
74465f4
c8090a0
74465f4
b1d9477
74465f4
 
 
c8090a0
74465f4
 
 
c8090a0
b1d9477
 
 
 
74465f4
b1d9477
c8090a0
 
 
 
 
74465f4
 
c8090a0
74465f4
c8090a0
 
 
b1d9477
 
74465f4
 
b1d9477
 
 
74465f4
 
c8090a0
b1d9477
 
c8090a0
 
 
 
 
74465f4
b1d9477
 
74465f4
 
c8090a0
74465f4
 
 
 
b1d9477
 
c8090a0
b1d9477
c8090a0
 
 
 
 
 
 
 
b1d9477
 
74465f4
b1d9477
74465f4
b1d9477
 
c8090a0
b1d9477
74465f4
 
 
 
 
 
 
 
 
 
b1d9477
 
74465f4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
---
license: apache-2.0
language:
- en
tags:
- LAB Cluster
- Satellite Images
- ESRI Wayback Imagery
- Color clustered images
- Mosaicing
- satellite
- remote-sensing
- earth-observation
- color-clustering
- LAB-colorspace 
- mosaic
- geospatial
- zoom-15
- arcgis
- texture
- image-retrieval
- perceptual-hash`
  
pretty_name: Satellite Images in LAB Color Clusters
size_categories:
- 10K<n<100K
---

# πŸ›°οΈ Mosaic Library β€” LAB-Clustered Satellite Tile Dataset
 
A curated collection of **satellite image tiles** harvested from ArcGIS World Imagery and organized into perceptually-uniform **LAB color-space clusters**. Each tile is a 256Γ—256 PNG snapshot of Earth's surface at zoom level 15 (~4.8 m/pixel), deduplicated and routed into one of **5,000 color buckets** using K-Means centroids in CIE LAB space.
The dataset currently contains tiles covering **786 out of 5,000 color clusters**, with up to 100 unique images per bucket.
 
---

## πŸ“ Dataset Structure
 
```
mosaic_library/
β”œβ”€β”€ tiles.db               # SQLite index of all tiles (id, bucket, path, phash, LAB values)
β”œβ”€β”€ centroids.npy          # NumPy array of 5,000 LAB cluster centroids (shape: 5000 Γ— 3)
β”œβ”€β”€ temp/                  # Ephemeral download scratch space (empty at rest)
β”œβ”€β”€ bucket_0000/           # Up to 100 PNG tiles whose mean LAB color maps to centroid 0
β”œβ”€β”€ bucket_0001/
β”‚   └── <uuid>.png
...
└── bucket_4999/
```
 
Each bucket folder holds images whose dominant color, expressed in CIE LAB space, is nearest to that bucket's centroid. Folder names are zero-padded to four digits (`bucket_0786`).
 
---

## SQLite Schema (tiles.db)
 
The database provides fast metadata lookups without loading any images.

Column definitions:

```
| Column | Type | Description |
|-------|-----|------------|
| `id` | TEXT (PK) | UUID v4 β€” matches the PNG filename |
| `bucket_id` | INTEGER | Cluster index, 0 to 4999 |
| `filepath` | TEXT | Relative path to the PNG file |
| `phash` | TEXT | 64-bit perceptual hash (hash_size=8) |
| `mean_l` | REAL | Mean L channel of the tile in CIE LAB |
| `mean_a` | REAL | Mean a channel |
| `mean_b` | REAL | Mean b channel |
```

Indexes: `idx_bucket` on `bucket_id`; `idx_phash` on `(bucket_id, phash)` for fast duplicate checks.

---

### Quick queries:
 
```python
import sqlite3
 
conn = sqlite3.connect("mosaic_library/tiles.db")
 
# Total tile count
conn.execute("SELECT COUNT(*) FROM tiles").fetchone()
 
# Buckets fully populated at 100 images
conn.execute(
    "SELECT bucket_id, COUNT(*) as n FROM tiles GROUP BY bucket_id HAVING n >= 100"
).fetchall()
 
# All tiles in bucket 42
conn.execute("SELECT * FROM tiles WHERE bucket_id = 42").fetchall()
```
 
---
 
## Color Clustering Design
 
### Why CIE LAB?
 
RGB is not perceptually uniform β€” equal numeric distances do not correspond to equal perceptual differences. CIE LAB is specifically designed so that Euclidean distance in LAB space closely matches human color perception. This makes the clusters visually meaningful: each bucket represents a genuinely distinct visual texture-color region of Earth's surface.

---

### How Clusters Were Generated:
 
```python
import numpy as np
from skimage.color import rgb2lab
from sklearn.cluster import MiniBatchKMeans
 
random_rgb = np.random.randint(0, 255, (500000, 1, 3), dtype=np.uint8)
random_lab = rgb2lab(random_rgb).reshape(-1, 3)
 
kmeans = MiniBatchKMeans(n_clusters=5000, batch_size=10000, n_init=3)
kmeans.fit(random_lab)
 
centroids = kmeans.cluster_centers_
np.save("mosaic_library/centroids.npy", centroids)
```
---
 
At inference time, a KD-Tree (`scipy.spatial.cKDTree`) provides O(log n) nearest-centroid lookup for each incoming tile.

---

### Tile Assignment Pipeline
 
Each downloaded tile goes through this pipeline before being saved:

```
1. Resize to 64x64 pixels for fast color computation.
2. Compute mean RGB across all pixels and convert to LAB.
3. Query the KD-Tree to find the nearest centroid and assign `bucket_id`.
4. If the bucket already holds 100 images, discard the tile.
5. Compute perceptual hash (`imagehash.phash`, hash_size=8) and discard if a matching hash exists in the same bucket.
6. Atomically move the file into `bucket_XXXX/` and insert a row into `tiles.db`.
```

---
 
## Geographic Coverage
 
Tiles were sampled across two harvesting phases with different biome weightings.
 
### Phase 1 β€” General Biomes

```
| Biome | lon_min | lat_min | lon_max | lat_max | Weight |
|------|--------|--------|--------|--------|------|
| Desert (Sahara) | -10 | 15 | 30 | 30 | 15% |
| Forest (Amazon/Congo) | -70 | -15 | -50 | 5 | 15% |
| Urban (Europe/US) | -5 | 40 | 20 | 55 | 20% |
| Arctic (Greenland) | -50 | 65 | -30 | 80 | 10% |
| Grassland (US Midwest) | -105 | 35 | -90 | 45 | 15% |
| Shallow Water (Caribbean) | -80 | 15 | -65 | 25 | 10% |
| Deep Ocean (Pacific) | -150 | -20 | -110 | 20 | 5% |
| Agriculture (India) | 73 | 20 | 80 | 30 | 10% |
```

### Phase 2 β€” Spectral Anomalies (Rare Colors)

Phase 2 targeted visually extreme locations to populate underrepresented LAB clusters:

```
| Location | Visual Signature | Weight |
|---------|-----------------|------|
| Australian Outback | Rust red | 20 |
| Salar de Uyuni, Bolivia | Bright white salt flat | 20 |
| Lake Natron, Tanzania | Pink/red alkaline water | 15 |
| Dallol, Ethiopia | Neon yellow-green hydrothermal | 15 |
| Yellowstone Hot Springs | Cyan and orange rings | 15 |
| Bahamas Shallows | Aqua/teal shallow water | 15 |
| Lava Fields, Hawaii | Pitch black basalt | 10 |
| Atacama Desert, Chile | Ochre/orange arid | 10 |
| Dense Urban Tokyo | Concrete grays | 10 |
| Greenland Glaciers | Ice blue/white | 10 |
```

---
 
## πŸ”§ Data Collection Parameters
 
| Parameter | Value |
|---|---|
| Tile source | ArcGIS World Imagery (`MapServer/tile/{z}/{y}/{x}`) |
| Zoom level | 15 (~4.8 m/pixel ground resolution) |
| Tile size | 256 Γ— 256 px (ArcGIS default) |
| Format | PNG (RGB) |
| Total color buckets | 5,000 |
| Max tiles per bucket | 100 |
| Buckets populated (current) | **786 / 5,000** |
| Deduplication method | Perceptual hash (pHash, 64-bit) per bucket |
| Download concurrency | 20 threads |
| Batch size per iteration | 100 tiles |
 
---
 
## 🐍 Loading the Dataset
 
### Load all tile metadata
 
```python
import sqlite3
import numpy as np
 
conn = sqlite3.connect("mosaic_library/tiles.db")
rows = conn.execute("SELECT id, bucket_id, filepath, mean_l, mean_a, mean_b FROM tiles").fetchall()
print(f"Total tiles: {len(rows)}")
```
 
### Load tiles from a specific bucket as NumPy arrays
 
```python
from PIL import Image
import numpy as np
import sqlite3, os
 
def load_bucket(base_dir, bucket_id, db_path="mosaic_library/tiles.db"):
    conn = sqlite3.connect(db_path)
    rows = conn.execute(
        "SELECT filepath FROM tiles WHERE bucket_id = ?", (bucket_id,)
    ).fetchall()
    images = []
    for (fp,) in rows:
        img = Image.open(os.path.join(base_dir, fp)).convert("RGB")
        images.append(np.array(img))
    return np.stack(images)   # shape: (N, 256, 256, 3)
 
imgs = load_bucket(".", bucket_id=42)
print(imgs.shape)
```
 
### Query by LAB color proximity
 
```python
from scipy.spatial import cKDTree
import numpy as np
 
centroids = np.load("mosaic_library/centroids.npy")
tree = cKDTree(centroids)
 
# Find the bucket closest to a target LAB color
target_lab = np.array([60.0, -20.0, 30.0])  # e.g. greenish mid-tone
dist, bucket_id = tree.query(target_lab)
print(f"Nearest bucket: {bucket_id}  (distance: {dist:.2f})")
```
 
---
 
## ⚠️ Limitations & Notes
 
- **786 of 5,000 buckets** are currently populated. Many LAB colors are extremely rare in nature (e.g. pure magenta terrain) and may never fill without targeted synthetic augmentation.
- Tiles derive from **ArcGIS World Imagery** (ESRI). Usage is subject to [ESRI's terms of service](https://www.esri.com/en-us/legal/terms/master-agreement). This dataset is intended for **non-commercial research purposes**.
- Ocean and cloud tiles may appear in general biome samples; they are not explicitly filtered beyond color-bucket routing.
- Perceptual hash deduplication is per-bucket only β€” the same geographic location could theoretically appear in two different buckets if its color shifts (e.g. seasonal change), though this is rare at zoom 15.
- The `centroids.npy` file is required to correctly interpret bucket assignments. Do not regenerate it, as this would invalidate all existing bucket assignments.