Order-aware complexity scoring for Perler and fuse-bead patterns.
BADI v2 measures the information needed to reconstruct an exact bead layout. A large checkerboard can be described by a short rule; an irregular portrait needs many more pattern-specific instructions. The algorithm captures that difference while reporting color confusion and physical placement workload separately.
Use it to compare exact patterns, study repetition and irregularity, or add explainable complexity metrics to a bead-pattern application. Evaluation runs locally, with no API keys or network service required.
Experimental model. Scores are reproducible, but have not been calibrated against human ratings, assembly time, or error rates.
All four original patterns below contain 100 × 100 cells and 10,000 beads. The captions show approximate structural_score values out of 10,000, computed from their exact color-code matrices. White backgrounds count as beads too.
| Checkerboard · ≈43 | Repeating flower tile · ≈101 |
|---|---|
![]() |
![]() |
| A short alternation rule describes the whole layout. | A small motif and its repetition describe the layout. |
| Original mountain lake · ≈471 | Same landscape, shuffled · ≈1,431 |
|---|---|
![]() |
![]() |
| Regions, edges, and details need more instructions. | The same 13 colors and their counts, with much less regularity. |
The landscape and shuffled version have identical bead counts and color histograms. Their arrangement changes the score. A higher score means more information to describe under this model; it does not mean better artwork or a measured increase in human effort. The 10,000 anchor is a larger 500 × 500 random pattern, so this gallery covers only part of the scale.
These illustrations and their original layouts are CC0 / public domain, created for this repository without external artwork. Exact CSVs, recorded scores, and reproduction instructions are included. Runtime/compressor differences can move scores slightly.
| Output | Meaning |
|---|---|
structural_score |
A 1–10,000 score based on the shortest tested lossless description. Regularity reduces the information needed to specify a pattern. |
craft_adjusted_complexity_score |
A separately normalized score that also accounts for ambiguity between similar palette colors. |
occupied_beads_N |
The number of physical bead placements. Empty cells are excluded. |
description |
Bit count, selected encoding, orientation, information density, and decoder round-trip status. |
workload_v1 |
Optional placement-weighted effort metrics from the earlier BADI model. |
The two complexity scores use different normalization denominators. Compare patterns within the same score column; subtracting one score from the other does not measure a difficulty increment. Both use a fixed, seeded 500 × 500 random reference as the 10,000 anchor, rather than a theoretical maximum.
The encoder tests solid fills, checkerboards, periodic tiles with exact exceptions, run lengths, packed symbols, and DEFLATE across eight rotations/reflections. Each candidate pays for its dimensions, palette dictionary, rules, and payload. The selected binary description is decoded and checked against the exact input layout.
These bundled examples share the same 4,753 occupied positions. The portrait and shuffled portrait also have identical color counts and frequencies.
| Pattern | Beads | Colors | Description bits | Structural score |
|---|---|---|---|---|
| Checkerboard within the portrait silhouette | 4,753 | 2 | 2,090 | 326 |
| Repeating 24-color tile within the silhouette | 4,753 | 24 | 3,218 | 405 |
| Original portrait | 4,753 | 24 | 13,974 | 844 |
| Shuffled portrait, preserving silhouette and color histogram | 4,753 | 24 | 23,168 | 1,087 |
The tile control preserves the color set, while the shuffled control preserves the full color histogram. See all comparisons and the model specification for assumptions and equations. Recorded values can vary with compressor and library versions; each result includes runtime metadata.
Requires Python 3.10 or newer and NumPy, SciPy, and scikit-image.
git clone https://github.com/unwatcher/bead-complexity.git
cd bead-complexity
python -m venv .venvActivate the environment with .venv\Scripts\Activate.ps1 in Windows PowerShell, or source .venv/bin/activate on macOS/Linux. Then install dependencies and score a sample:
python -m pip install -r requirements.txt
python bead_complexity.py --grid example_inputs/seated_girl_latest.csv --out generated/seated.jsonInclude placement workload and save a reversible binary description:
python bead_complexity.py --grid example_inputs/seated_girl_latest.csv --include-workload --description-out generated/seated.bpc --out generated/seated.jsonUse --config config_v2.json to specify the model settings and --palette MARD_221_palette.json to select the supplied palette explicitly. The first score for a model instance also computes its reference pattern.
Input is a rectangular CSV matrix of exact palette codes. Both plain matrices and CSVs with consecutive one-based row/column labels are supported:
row,1,2,3
1,H7,H2,
2,H2,H7,H2- The bundled palette contains 221 MARD codes. Unknown codes raise an error; they are not approximately remapped.
- Blank cells,
.,-,EMPTY, andTRANSPARENTrepresent empty positions.H7is black and counts as a bead. - Outer empty margins are cropped. Internal empty cells and the silhouette remain part of the pattern.
- Supply the final code matrix. A screenshot, photograph, or rendered worksheet must first be converted into exact palette codes outside this tool.
import json
from pathlib import Path
from bead_complexity import ComplexityModel, read_code_matrix
palette = json.loads(Path("MARD_221_palette.json").read_text())
model = ComplexityModel(palette)
grid = read_code_matrix("example_inputs/seated_girl_latest.csv")
result = model.score(grid, include_v1_workload=True)
print(result["structural_score"])
print(result["occupied_beads_N"])Decode a saved description using the identical palette definition:
grid_ids, bits_consumed = model.decode(Path("generated/seated.bpc").read_bytes())
# ID 0 is empty; IDs 1..221 follow model.base.codes.A .bpc file stores the tightly cropped code layout, including its original orientation. It does not preserve unused outer margins and is not an image or worksheet. Scoring uses consumed bits rather than the byte-padded file size.
python run_examples.pyThis regenerates the comparison table, JSON results, binary descriptions, matched controls, benchmark, and tests.json. The 25 checks cover normalization anchors, exact decoder round trips, all eight orientation invariances, empty-padding and palette-label invariance, preserved inputs, and selected regularity/shuffle comparisons. They test these computational properties and examples, not a universal ranking of artwork or human performance.
Changing the palette, grammar, reference, or scoring parameters creates a different scoring convention. Record those changes before comparing results across versions.
| File or directory | Purpose |
|---|---|
| bead_complexity.py | BADI v2 evaluator, lossless encoder/decoder, and CLI |
| bead_workload_v1.py | Earlier workload model, retained for separate comparisons |
| MODEL_V2.md | Mathematical definitions, coding grammar, limitations, and research references |
| config_v2.json | Default settings |
| example_inputs/ | Exact source patterns and controlled comparisons |
| results/ | Recorded scores and binary descriptions |
| docs/gallery/ | Original CC0 illustrations, exact layouts, and measured gallery scores |
| docs/generate_gallery.py | Recreate the artwork and verify its score comparisons |
| benchmark.json, tests.json | Reference values and recorded computational checks |
| SHA256.json | SHA-256 file manifest for this repository snapshot |
Description length is a restricted-model proxy for structural complexity, not exact Kolmogorov complexity or a direct measure of artistic quality. Semantic meaning, maker experience, tools, lighting, and physical bead variation are outside this model. Palette RGB values are screen references rather than measurements of physical beads.
The bundled palette is derived from pixel-to-beads. Its source, transformations, and GPL-3.0 license copy are documented in THIRD_PARTY_NOTICES.md. No project-wide license has been selected for the original algorithm source.



