{
 "id": "multi-view-stereo-patchmatch",
 "title": "Multi-View Stereo (PatchMatch, COLMAP)",
 "aliases": [
  "MVS",
  "patch-match stereo"
 ],
 "domain": "capture",
 "subdomain": "photogrammetry",
 "stage": "capture",
 "realtime": "offline",
 "platforms": [
  "cuda"
 ],
 "year_introduced": 2016,
 "inputs": [
  "photos",
  "camera-poses"
 ],
 "outputs": [
  "depth",
  "normals",
  "point-cloud"
 ],
 "style": "photoreal",
 "dynamic": "static",
 "summary": "Computes a dense depth and normal map per image from posed photos using PatchMatch propagation with pixelwise view selection, then fuses them into a dense point cloud.",
 "how_it_works": "Given calibrated cameras, each pixel in a reference image carries a hypothesised depth and surface normal. PatchMatch initialises these randomly and iterates: neighbouring pixels propagate good hypotheses along scanlines, and random perturbation refines them. Each hypothesis is scored by photometric consistency (normalised cross-correlation of a slanted patch) against a subset of source images. The key idea is that the subset is chosen per pixel, using a probabilistic occlusion model estimated jointly with depth, so occluded views stop poisoning the cost. Geometric consistency across neighbouring views is added in later passes. Resulting depth maps are filtered for consistency and fused into a point cloud, which can be meshed with Poisson or Delaunay methods.",
 "when_to_use": "Choose it when you need an explicit dense surface from a photo set with known poses, e.g. for meshing and baking. Prefer `neuralangelo` or `neus` when surfaces are thin, glossy or textureless and you can afford neural optimisation. Prefer `2d-gaussian-splatting` when you also want fast novel-view rendering from the same capture.",
 "cost": {
  "class": "offline",
  "notes": "GPU-bound; minutes to hours depending on resolution and image count."
 },
 "failure_modes": [
  "Textureless walls and sky give noisy or missing depth because photometric cost is flat",
  "Specular and transparent surfaces violate photo-consistency and produce holes or floating points",
  "Thin structures and foliage are smoothed away or fused into blobs",
  "Fused clouds carry view-dependent colour seams unless colours are blended carefully"
 ],
 "sources": [
  {
   "role": "primary",
   "key": "doi:10.1007/978-3-319-46487-9_31",
   "type": "chapter",
   "title": "Pixelwise View Selection for Unstructured Multi-View Stereo",
   "authors": [
    "Johannes L. Schönberger",
    "Enliang Zheng",
    "Jan-Michael Frahm",
    "Marc Pollefeys"
   ],
   "year": 2016,
   "venue": "Lecture Notes in Computer Science",
   "url": "https://doi.org/10.1007/978-3-319-46487-9_31",
   "ids": {
    "doi": "10.1007/978-3-319-46487-9_31"
   },
   "license": null,
   "extra": {
    "csl_type": "book-chapter"
   },
   "provenance": {
    "title": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1007/978-3-319-46487-9_31",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "authors": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1007/978-3-319-46487-9_31",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "year": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1007/978-3-319-46487-9_31",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "venue": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1007/978-3-319-46487-9_31",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "url": {
     "authority": "crossref",
     "endpoint": "https://api.crossref.org/works/10.1007/978-3-319-46487-9_31",
     "checked_at": "2026-11-29T15:51:27.588Z"
    }
   },
   "status": "verified",
   "checked_at": "2026-11-29T15:51:27.588Z",
   "title_sim": 1,
   "__bib": "schnberger2016pixelwise"
  },
  {
   "role": "implementation",
   "key": "gh:colmap/colmap",
   "type": "code",
   "title": "colmap/colmap",
   "description": "COLMAP - Structure-from-Motion and Multi-View Stereo",
   "authors": [
    "colmap"
   ],
   "year": 2014,
   "venue": "GitHub",
   "url": "https://github.com/colmap/colmap",
   "ids": {
    "repo": "colmap/colmap"
   },
   "license": "NOASSERTION",
   "extra": {
    "stars": 13324,
    "stars_checked": "2026-11-29",
    "archived": false,
    "fork": false,
    "pushed_at": "2026-11-28T21:48:00Z",
    "language": "C++",
    "homepage": "https://colmap.github.io/",
    "license_name": "Other"
   },
   "provenance": {
    "title": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/colmap/colmap",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "authors": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/colmap/colmap",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "year": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/colmap/colmap",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "venue": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/colmap/colmap",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "url": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/colmap/colmap",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "license": {
     "authority": "github",
     "endpoint": "https://api.github.com/repos/colmap/colmap",
     "checked_at": "2026-11-29T15:51:27.588Z"
    }
   },
   "status": "verified",
   "checked_at": "2026-11-29T15:51:27.588Z",
   "title_sim": null,
   "__bib": "colmap2014colmap"
  }
 ],
 "presets": [
  {
   "id": "multi-view-stereo-patchmatch-live",
   "title": "Multi-View Stereo (PatchMatch) — epipolar disparity & cost planes (left) vs recovered dense depth (right)",
   "runtime": "glsl-fragment",
   "params": {
    "P_BASELINE": 0.35,
    "P_COST_BANDS": 10,
    "P_CAM_SWEEP": 0.7,
    "P_SPLIT": 0.48
   },
   "basis": "original",
   "license_note": "MIT — written for this index.",
   "code": "const float P_BASELINE = 0.35; // P Stereo Baseline [0.10, 0.75, 0.02]\nconst float P_COST_BANDS = 10.0; // P Sweep Planes [4.0, 20.0, 1.0]\nconst float P_CAM_SWEEP = 0.70; // P View Motion [0.0, 2.0, 0.05]\nconst float P_SPLIT = 0.48; // P Stereo / Depth Split [0.0, 1.0, 0.02]\n\nfloat sdBox(vec3 p, vec3 b) {\n  vec3 q = abs(p) - b;\n  return length(max(q, 0.0)) + min(max(q.x, max(q.y, q.z)), 0.0);\n}\n\n// Multi-depth architectural scene with rich foreground, midground, and background parallax layers\nvec2 mapScene(vec3 p) {\n  vec2 res = vec2(p.y + 0.72, 1.0);\n  float dBack = p.z + 2.4; if (dBack < res.x) res = vec2(dBack, 2.0);\n  float dArch1 = sdBox(p - vec3(-0.62, -0.15, -0.35), vec3(0.28, 0.56, 0.24)) - 0.02;\n  if (dArch1 < res.x) res = vec2(dArch1, 3.0);\n  float dSph = length(p - vec3(0.06, -0.24, -0.75)) - 0.44;\n  if (dSph < res.x) res = vec2(dSph, 4.0);\n  float dArch2 = sdBox(p - vec3(0.76, -0.22, -1.25), vec3(0.32, 0.50, 0.26)) - 0.02;\n  if (dArch2 < res.x) res = vec2(dArch2, 5.0);\n  return res;\n}\n\nvec3 calcNormal(vec3 p) {\n  vec2 e = vec2(0.0025, 0.0);\n  return normalize(vec3(\n    mapScene(p + e.xyy).x - mapScene(p - e.xyy).x,\n    mapScene(p + e.yxy).x - mapScene(p - e.yxy).x,\n    mapScene(p + e.yyx).x - mapScene(p - e.yyx).x\n  ));\n}\n\n// High-frequency surface texture required for PatchMatch NCC photometric matching\nvec3 surfaceTexture(vec3 p, float matId) {\n  float pat = sin(p.x * 16.0) * sin(p.y * 16.0) * sin(p.z * 16.0);\n  float brick = smoothstep(0.05, 0.12, abs(fract(p.x * 4.0) - 0.5)) * smoothstep(0.05, 0.12, abs(fract(p.y * 6.0) - 0.5));\n  vec3 base = vec3(0.58, 0.62, 0.68);\n  if (matId > 2.5 && matId < 3.5) base = vec3(0.84, 0.50, 0.32);\n  if (matId > 3.5 && matId < 4.5) base = vec3(0.28, 0.66, 0.78);\n  if (matId > 4.5) base = vec3(0.76, 0.72, 0.42);\n  return base * (0.76 + 0.24 * brick) * (0.88 + 0.12 * pat);\n}\n\n// Trace camera view and return (depth, matId, shadedRGB)\nvoid renderView(vec3 ro, vec3 rd, out float depth, out vec3 col, out vec3 nOut) {\n  float t = 0.0;\n  float matId = 0.0;\n  bool hit = false;\n  for (int i = 0; i < 60; i++) {\n    vec2 h = mapScene(ro + rd * t);\n    if (h.x < 0.0025) { hit = true; matId = h.y; break; }\n    t += h.x;\n    if (t > 9.0) break;\n  }\n  depth = hit ? t : 9.0;\n  nOut = vec3(0.0, 0.0, 1.0);\n  if (!hit) {\n    col = vec3(0.04, 0.06, 0.10);\n    return;\n  }\n  vec3 p = ro + rd * t;\n  nOut = calcNormal(p);\n  vec3 lDir = normalize(vec3(0.55, 0.80, 0.48));\n  float diff = max(dot(nOut, lDir), 0.0);\n  col = surfaceTexture(p, matId) * (0.28 + 0.82 * diff);\n}\n\nvec3 turboDepth(float d) {\n  float t = clamp(d, 0.0, 1.0);\n  vec3 c0 = vec3(0.10, 0.14, 0.48);\n  vec3 c1 = vec3(0.10, 0.78, 0.86);\n  vec3 c2 = vec3(0.96, 0.84, 0.22);\n  vec3 c3 = vec3(0.96, 0.26, 0.18);\n  if (t < 0.33) return mix(c0, c1, t * 3.0);\n  if (t < 0.66) return mix(c1, c2, (t - 0.33) * 3.0);\n  return mix(c2, c3, (t - 0.66) * 3.0);\n}\n\nvec3 aces(vec3 x) {\n  x = max(x, 0.0);\n  return (x * (2.51 * x + 0.03)) / (x * (2.43 * x + 0.59) + 0.14);\n}\n\nvoid mainImage(out vec4 fragColor, in vec2 fragCoord) {\n  vec2 uv = (fragCoord - 0.5 * iResolution.xy) / iResolution.y;\n  float screenX = fragCoord.x / max(iResolution.x, 1.0);\n  float split = clamp(P_SPLIT, 0.0, 1.0);\n  bool isDepth = screenX >= split;\n  float base = clamp(P_BASELINE, 0.08, 0.80);\n  float nBands = clamp(floor(P_COST_BANDS + 0.5), 4.0, 22.0);\n  float sway = sin(iTime * max(P_CAM_SWEEP, 0.0) * 0.75) * 0.28;\n\n  // Reference camera (center) and stereo source camera (offset along epipolar baseline X)\n  vec3 roRef = vec3(sway, 0.12, 2.25);\n  vec3 roSrc = vec3(sway + base, 0.12, 2.25);\n  vec3 rd = normalize(vec3(uv, -1.52));\n\n  float dRef, dSrc;\n  vec3 cRef, cSrc, nRef, nSrc;\n  renderView(roRef, rd, dRef, cRef, nRef);\n\n  vec3 col;\n  if (!isDepth) {\n    // Left: Epipolar stereo anaglyph parallax (Red=ref cam, Cyan=source cam) + horizontal epipolar scanlines\n    renderView(roSrc, rd, dSrc, cSrc, nSrc);\n    float lRef = dot(cRef, vec3(0.299, 0.587, 0.114));\n    float lSrc = dot(cSrc, vec3(0.299, 0.587, 0.114));\n    col = vec3(lRef * 1.15, lSrc * 0.95, lSrc * 1.10);\n    // Horizontal epipolar lines showing 1D stereo disparity search rows\n    float epiLine = smoothstep(0.055, 0.012, abs(fract(uv.y * 12.0) - 0.5));\n    col = mix(col, vec3(0.95, 0.88, 0.34), epiLine * 0.24);\n  } else {\n    // Right: PatchMatch MVS recovered inverse-depth map (1 / z) + plane-sweep iso-cost bands & normal shading\n    float invZ = clamp((1.0 / max(dRef, 1.0) - 0.16) * 2.2, 0.0, 1.0);\n    vec3 dCol = turboDepth(invZ);\n    // Animated active plane-sweep hypothesis slice passing through the cost volume\n    float activeSweep = fract(iTime * 0.25);\n    float sweepHit = smoothstep(0.045, 0.008, abs(invZ - activeSweep));\n    float planeBands = smoothstep(0.06, 0.015, abs(fract(invZ * nBands) - 0.5));\n\n    float nShade = 0.65 + 0.35 * max(dot(nRef, normalize(vec3(0.5, 0.8, 0.5))), 0.0);\n    col = dCol * nShade;\n    col = mix(col, vec3(0.04, 0.07, 0.12), planeBands * 0.34);\n    col = mix(col, vec3(1.0, 0.98, 0.90), sweepHit * 0.85);\n  }\n\n  float sep = smoothstep(0.0035, 0.0008, abs(screenX - split));\n  col = mix(col, vec3(0.95, 0.97, 1.0), sep);\n\n  fragColor = vec4(pow(clamp(aces(col), 0.0, 1.0), vec3(1.0 / 2.2)), 1.0);\n}",
   "execution_fidelity": "conceptual-diagram",
   "proof": {
    "kind": "rendered",
    "label": "rendered 2026-11-30",
    "ok": true,
    "proof": {
     "ok": true,
     "technique": "multi-view-stereo-patchmatch",
     "runtime": "glsl-fragment",
     "checked_at": "2026-11-30T19:53:31.000Z",
     "renderer": "Headless EGL Tesla T4/PCIe/SSE2, OpenGL 3.30 Core, 512×512, iTime=1.5",
     "stats": {
      "mean": 0.6959,
      "std": 0.0858,
      "min": 0.3014,
      "max": 0.9014
     },
     "image": "/specimens/multi-view-stereo-patchmatch-live.webp",
     "reason": null
    }
   }
  }
 ],
 "related": [
  "structure-from-motion-colmap",
  "neus",
  "neuralangelo",
  "visual-hull"
 ],
 "extends": [],
 "supersedes": [],
 "combines_with": [
  {
   "id": "structure-from-motion-colmap",
   "why": "SfM provides the calibrated cameras that MVS needs to compare views."
  }
 ],
 "provenance": {
  "prose": "original text written for this index (research draft, editorially reviewed)",
  "sources_verified_at": "2026-11-29T15:51:27.588Z",
  "draft": "data/drafts/capture/multi-view-stereo-patchmatch.json"
 },
 "solves": [
  "need dense point cloud from photos with known cameras",
  "turn posed photos into depth maps",
  "build a mesh for baking from a photo set",
  "sparse reconstruction is too thin for detail",
  "photogrammetry dense reconstruction step"
 ],
 "authority": "Schönberger et al., 2016",
 "url": "https://texelatlas.vercel.app/t/multi-view-stereo-patchmatch/",
 "execution_fidelity": "conceptual-diagram",
 "fidelity_label": "Visual Diagram",
 "benchmark_eligible": false,
 "gpu_weight": {
  "weight_x": 25.74,
  "tier": "heavy",
  "p50_ms": 0.7979,
  "p95_ms": 0.8223,
  "baseline_p50_ms": 0.0329,
  "gpu": "Tesla T4/PCIe/SSE2",
  "resolution": "1920x1080",
  "method": "opengl-timer-query",
  "frames": 36,
  "preset_id": "multi-view-stereo-patchmatch-live",
  "execution_fidelity": "conceptual-diagram",
  "fidelity_label": "Visual Diagram",
  "benchmark_eligible": false,
  "generated_at": "2026-11-30T21:07:47Z",
  "l4": {
   "weight_x": 25.38,
   "tier": "heavy",
   "p50_ms": 0.4035,
   "p95_ms": 0.4116,
   "speedup_x": 1.98,
   "gpu": "NVIDIA L4/PCIe/SSE2",
   "resolution": "1920x1080",
   "baseline_p50_ms": 0.0159
  },
  "a100": {
   "weight_x": 16.35,
   "tier": "moderate",
   "p50_ms": 0.471,
   "p95_ms": 0.4766,
   "speedup_x": 1.69,
   "gpu": "NVIDIA A100-SXM4-40GB/PCIe/SSE2",
   "resolution": "1920x1080",
   "baseline_p50_ms": 0.0288
  }
 }
}