Image quilting
Synthesises a larger texture from a small exemplar by stitching overlapping patches along minimum-error seams. Preserves structure such as bricks and strokes that pixel-based synthesis blurs.
In the family Materials, BRDFs & texturing, texture synthesis
Where it runs
Built inOfficial add-onPluginNone foundNot researched
| Engine | Support | How |
|---|---|---|
| three.js r187 | None found | |
| Babylon.js 9.38.0 | None found | |
| Godot 4.7 | None found | No built-in texture image-quilting synthesizer. |
| Unity | None found | |
| Unreal 5.7 | None found | |
| Blender 5.2 | None found | |
| WebGPU W3C | None found | |
| Metal | None found |
How it works
Efros and Freeman tile the output in raster order with square blocks taken from the exemplar. For each new block, candidates are scored by how well their overlap region matches the already-placed neighbours (sum of squared differences), and one is picked at random from those within a tolerance of the best, which adds variety. The overlap is not blended; instead a minimum-cost path through the overlap error surface, found by dynamic programming, chooses the cut that hides the seam along pixels already similar. A variant adds a correspondence map for texture transfer: blocks must also match a target image's luminance, so a photograph is re-rendered in the texture's style. Block size controls the scale of structure that survives; larger blocks reduce visible repetition less.
When to choose it
Reach for it when
- need a large texture from a tiny sample
- tiled textures show obvious repetition
- brick or stone patterns blur when synthesised pixel by pixel
- stitch patches into seamless structured texture
- transfer texture style onto another image
Choose it for offline generation of large, structured, seamless textures (brick, stone walls, foliage) from a single scan, or for texture transfer stylisation. Prefer Histogram-preserving blending (stochastic texturing) or Hex-tiling for real-time, runtime anti-tiling of stochastic textures. Prefer procedural noise (Procedural noise for texturing) when no exemplar exists.
Field marks
- Verbatim copying of recognisable chunks reveals the exemplar as visible repetition
- Fails on globally structured or semantic textures (faces, text, long straight lines crossing blocks)
- Block size trade-off: too small loses structure, too large repeats
- Seam cuts can leave staircase artefacts on smooth gradients
Presets
Image quilting — straight patch seams vs minimum-error boundary-cut synthesis
{
"P_PATCH_SCALE": 3.6,
"P_CUT_WIGGLE": 1,
"P_SEAM_VIS": 0.65,
"P_SPLIT": 0.38
}Show GLSL (146 lines)
const float P_PATCH_SCALE = 3.6; // P Patch Grid [2.0, 7.0, 0.2]
const float P_CUT_WIGGLE = 1.0; // P Min-Error Cut [0.0, 1.8, 0.05]
const float P_SEAM_VIS = 0.65; // P Seam Highlight [0.0, 1.5, 0.05]
const float P_SPLIT = 0.38; // P Naive/Quilt Split [0.0, 1.0, 0.02]
vec2 hash22(vec2 p) {
p = vec2(dot(p, vec2(127.1, 311.7)), dot(p, vec2(269.5, 183.3)));
return fract(sin(p) * 43758.5453);
}
// Rich procedural cobblestone & terracotta mosaic exemplar texture (returns vec4(color, mortarMask))
vec4 sampleExemplar(vec2 p) {
vec2 n = floor(p);
vec2 f = fract(p);
float d1 = 8.0, d2 = 8.0;
vec2 bestId = vec2(0.0);
vec2 bestR = vec2(0.0);
for (int j = -1; j <= 1; j++) {
for (int i = -1; i <= 1; i++) {
vec2 g = vec2(float(i), float(j));
vec2 o = 0.16 + 0.68 * hash22(n + g);
vec2 r = g + o - f;
float d = dot(r, r);
if (d < d1) { d2 = d1; d1 = d; bestId = n + g; bestR = r; }
else if (d < d2) { d2 = d; }
}
}
float edge = sqrt(d2) - sqrt(d1);
vec2 h = hash22(bestId * 1.7 + 3.1);
// Warm Mediterranean limestone, slate & terracotta stone palette
vec3 stoneA = vec3(0.68, 0.56, 0.44);
vec3 stoneB = vec3(0.46, 0.49, 0.54);
vec3 stoneC = vec3(0.76, 0.41, 0.28);
vec3 baseCol = mix(stoneA, stoneB, h.x);
baseCol = mix(baseCol, stoneC, smoothstep(0.68, 0.92, h.y));
// Stone micro-grain + directional bevel lighting
float grain = 0.88 + 0.24 * sin(p.x * 19.0 + h.x * 6.0) * cos(p.y * 17.0 - h.y * 6.0);
float bevel = smoothstep(0.04, 0.22, edge);
float tilt = clamp(0.65 + 0.55 * dot(normalize(bestR + 1e-4), normalize(vec2(-0.6, 0.8))), 0.25, 1.35);
vec3 stoneCol = baseCol * grain * tilt * (0.62 + 0.42 * bevel);
// Dark sandy mortar groove
float mortar = smoothstep(0.11, 0.045, edge);
vec3 mortarCol = vec3(0.14, 0.13, 0.12) * (0.85 + 0.3 * sin(p.x * 45.0) * cos(p.y * 45.0));
vec3 col = mix(stoneCol, mortarCol, mortar);
return vec4(col, mortar);
}
// Compute minimum-error cut energy between two overlapping patches A and B
float overlapError(vec2 uvA, vec2 uvB) {
vec4 a = sampleExemplar(uvA);
vec4 b = sampleExemplar(uvB);
vec3 d = a.rgb - b.rgb;
// Strongly prefer cuts passing through low-contrast mortar valleys
float valleyBonus = 1.0 - 0.55 * max(a.a, b.a);
return (dot(d, d) + 0.04) * valleyBonus;
}
vec3 aces(vec3 x) {
x = max(x, 0.0);
return (x * (2.51 * x + 0.03)) / (x * (2.43 * x + 0.59) + 0.14);
}
void mainImage(out vec4 fragColor, in vec2 fragCoord) {
vec2 uv = (fragCoord - 0.5 * iResolution.xy) / iResolution.y;
vec2 screenUV = fragCoord / iResolution.xy;
float patchScale = clamp(P_PATCH_SCALE, 1.8, 8.0);
float cutWig = clamp(P_CUT_WIGGLE, 0.0, 2.0);
float seamVis = clamp(P_SEAM_VIS, 0.0, 1.8);
float splitX = clamp(P_SPLIT, 0.0, 1.0);
vec2 pan = vec2(iTime * 0.16, iTime * 0.09);
vec2 gp = uv * patchScale + pan;
vec2 cell = floor(gp);
vec2 f = fract(gp);
float texFreq = 3.2;
// Each synthesized patch selects a random exemplar offset
vec2 offC = hash22(cell) * 14.0;
vec2 offR = hash22(cell + vec2(1.0, 0.0)) * 14.0;
vec2 offU = hash22(cell + vec2(0.0, 1.0)) * 14.0;
vec2 offUR = hash22(cell + vec2(1.0, 1.0)) * 14.0;
vec2 pC = gp * texFreq + offC;
vec2 pR = gp * texFreq + offR;
vec2 pU = gp * texFreq + offU;
vec2 pUR = gp * texFreq + offUR;
vec3 col;
float seamGlow = 0.0;
if (screenUV.x < splitX) {
// Left side: naive unquilted square patch tiling with abrupt visible seams
col = sampleExemplar(pC).rgb;
float edge = min(min(f.x, 1.0 - f.x), min(f.y, 1.0 - f.y));
seamGlow = smoothstep(0.032, 0.005, edge) * seamVis;
col = mix(col, vec3(1.0, 0.32, 0.22), seamGlow * 0.78);
} else {
// Right side: Efros-Freeman minimum-error boundary cut across 28% overlap strips
// Sample error energy across horizontal & vertical overlap bands to find lowest-error cut position
float bestX = 0.84;
float minEX = 1e6;
float bestY = 0.84;
float minEY = 1e6;
for (int k = 0; k < 5; k++) {
float s = 0.72 + float(k) * 0.065;
// Add subtle smooth path continuity along perpendicular axis
vec2 probeX = vec2(cell.x + s, gp.y) * texFreq;
float ex = overlapError(probeX + offC, probeX + offR);
if (ex < minEX) { minEX = ex; bestX = s; }
vec2 probeY = vec2(gp.x, cell.y + s) * texFreq;
float ey = overlapError(probeY + offC, probeY + offU);
if (ey < minEY) { minEY = ey; bestY = s; }
}
// Smooth organic boundary curve modulated by P_CUT_WIGGLE
float cutX = mix(0.85, bestX + 0.045 * sin(gp.y * 9.0 + cell.x * 2.3), clamp(cutWig, 0.0, 1.5));
float cutY = mix(0.85, bestY + 0.045 * cos(gp.x * 9.0 + cell.y * 2.7), clamp(cutWig, 0.0, 1.5));
float wx = smoothstep(cutX - 0.025, cutX + 0.025, f.x);
float wy = smoothstep(cutY - 0.025, cutY + 0.025, f.y);
vec3 c00 = sampleExemplar(pC).rgb;
vec3 c10 = sampleExemplar(pR).rgb;
vec3 c01 = sampleExemplar(pU).rgb;
vec3 c11 = sampleExemplar(pUR).rgb;
col = mix(mix(c00, c10, wx), mix(c01, c11, wx), wy);
// Highlight the jagged minimum-error cut path in glowing turquoise-gold
float dCutX = abs(f.x - cutX);
float dCutY = abs(f.y - cutY);
seamGlow = max(smoothstep(0.028, 0.004, dCutX), smoothstep(0.028, 0.004, dCutY)) * seamVis;
col = mix(col, vec3(0.28, 0.96, 0.88), seamGlow * 0.72);
}
if (splitX > 0.01 && splitX < 0.99 && abs(screenUV.x - splitX) < 0.004) {
col = vec3(1.0, 0.86, 0.42);
}
fragColor = vec4(pow(clamp(aces(col * 1.15), 0.0, 1.0), vec3(1.0 / 2.2)), 1.0);
}Attribution: Original interactive WebGL2 fragment shader written for Texel Atlas (MIT).
Measured GPU weight & timing
| Preset | GPU | Weight / p50 / p95 | Method |
|---|---|---|---|
| image-quilting-live | Tesla T4 1920x1080 | 105× baseline (extreme) · 3.44 ms / 3.56 ms | opengl-timer-query · 40 frames · GPU Weight Atlas · Colab T4 sweep |
| image-quilting-live | NVIDIA L4 1920x1080 | 91.0× baseline (extreme) · 1.45 ms / 1.45 ms · 2.4× faster on L4 | opengl-timer-query · Cross-architecture validation |
| image-quilting-live | NVIDIA A100-SXM4-40GB 1920x1080 | 62.0× baseline (extreme) · 1.79 ms / 1.79 ms · 1.9× faster on A100 | opengl-timer-query · Cross-architecture validation |
Lineage
From the citation graph (Crossref reference lists): its primary source cites Computer-generated watercolor (fluid simulation); cited by Histogram-preserving blending (stochastic texturing), Model Synthesis, Wang Tiles (Aperiodic Tile Synthesis).
Crosses
- One phone photo, a whole floor: A flash photo of a small material patch becomes a PBR material that covers a large area without visible repetition. Every map is quilted with the same seams and tiled with the same hex offsets, so albedo, normal and roughness stay registered.
Sources
- primaryAlexei A. Efros, William T. Freeman (2001). Image quilting for texture synthesis and transfer. Proceedings of the 28th annual conference on Computer graphics and interactive techniques.Verified via crossref · 2026-11-29doi:10.1145/383259.383296