--- 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.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.