Algorithm Search⌘K

Algorithmcore

Photometric stereo

Also called Woodham photometric stereo, calibrated Lambertian photometric stereo.

Recover a surface normal and albedo at each pixel from three or more images under known distant lights, by least squares on the Lambertian model.

Time
Θ(N W H) worst · average · best
Space
Θ(W H) extra
Where
H = the image height in pixels; N = the number of images; W = the image width in pixels
Properties
deterministicexactofflineiterative
Origin
Robert J. Woodham, 1980

Photometric stereo finds the direction a surface faces, and how much light it reflects, at every pixel of a fixed camera. The camera and the object do not move; only the light changes, and each image is taken with one known, distant light. For a matte (Lambertian) surface, each image gives one linear equation for the vector g=ρng = \rho n, the albedo times the unit normal. Three lights in general position give three equations and fix gg, and more lights give a least squares solution. Unlike two-view stereo, no pixel matching is needed, since every image shows the same point at the same pixel. Unlike shape from shading, which has one image and is ill-posed, the problem at each pixel is a small linear system with a unique solution.

In plain words

Hold a matte object under a lamp. A part that faces the lamp is bright, and a part that turns away is darker. One photo cannot tell you if a patch is dark because it turns away or because its paint is dark. Now take three photos with the lamp in three different places, without moving the camera or the object. Each patch now has three brightness values, and only one direction and one paint shade explain all three. Solving a small set of equations at every pixel gives the direction the surface faces there and how bright its paint is. Joining the directions gives the shape.

The problem

Frame. This page uses the height-field frame of Horn: xx and yy lie in the image plane, and zz points toward the viewer. This differs from the camera frame of the area, where ZZ points away from the camera. A surface z(x,y)z(x, y) with slopes p=zxp = z_x and q=zyq = z_y has the unit normal n=(−p,−q,1)/1+p2+q2n = (-p, -q, 1) / \sqrt{1 + p^2 + q^2}.

Input.

  • N≥3N \ge 3 images I1,…,INI_1, \dots, I_N of size W×HW \times H from one fixed camera, with a linear response.
  • A light vector sks_k for each image: its direction points toward a distant light, and its length is the strength of the light.
  • A threshold below which a reading counts as shadow.

Model. At each pixel, Ik=max⁡(0,ρ n⊤sk)I_k = \max(0, \rho\, n^\top s_k) (Lambertian reflectance with attached shadows), with the albedo ρ>0\rho > 0 and the unit normal nn. The camera is orthographic, or far enough that the viewing direction is about the same at all pixels. There are no cast shadows, interreflections or highlights in the readings that are kept.

Output. The albedo ρ\rho and the normal nn at each pixel, or "unknown" where fewer than three lights in general position light the point.

The algorithm

  1. PHOTOMETRIC-STEREO(I_1..I_N, s_1..s_N, threshold)
  2. 1for each pixel p do
  3. 2A ← {k : I_k(p) > threshold} ▷ drop shadowed readings
  4. 3if |A| < 3 then mark p unknown; continue
  5. 4M ← Σ_{k ∈ A} s_k s_k^T; b ← Σ_{k ∈ A} I_k(p) s_k
  6. 5solve M g = b; if M is singular then mark p unknown; continue
  7. 6ρ(p) ← |g|; n(p) ← g / |g|
  8. 7return ρ, n

Line L4, the normal equations. With the light matrix LL whose rows are sk⊤s_k^\top for k∈Ak \in A, M=L⊤LM = L^\top L and b=L⊤Ib = L^\top I. These are the normal equations of the overdetermined system Lg=IL g = I. For exactly three lights, Mg=bM g = b has the same solution as Lg=IL g = I.

Line L5, the solve. The code uses Gaussian elimination with partial pivoting on the 3×33 \times 3 system. If all pixels use all lights, MM is the same for every pixel, so one inverse, or one pseudo-inverse of LL, serves the whole image.

Line L6, albedo and normal. The length of gg is the albedo because nn has length 1. The slopes follow as p=−nx/nzp = -n_x / n_z and q=−ny/nzq = -n_y / n_z.

Integration. The algorithm gives normals, not depths. A height map comes from integrating the slope field (p,q)(p, q). Noise makes the field slightly non-integrable, so methods find the surface whose slopes are closest to it: Frankot and Chellappa project the field onto integrable surfaces with the fast Fourier transform, and least squares methods solve a Poisson equation ∇2z=px+qy\nabla^2 z = p_x + q_y.

Example

Three lights. Take s1=(0,0,1)s_1 = (0, 0, 1), s2=(0.6,0,0.8)s_2 = (0.6, 0, 0.8) and s3=(0,0.6,0.8)s_3 = (0, 0.6, 0.8), all of length 1, and the readings I=(0.6,0.84,0.66)I = (0.6, 0.84, 0.66) at one pixel. The equations are

gz=0.6,0.6gx+0.8gz=0.84,0.6gy+0.8gz=0.66,g_z = 0.6, \quad 0.6 g_x + 0.8 g_z = 0.84, \quad 0.6 g_y + 0.8 g_z = 0.66,

so g=(0.6,0.3,0.6)g = (0.6, 0.3, 0.6). Then ρ=0.36+0.09+0.36=0.9\rho = \sqrt{0.36 + 0.09 + 0.36} = 0.9 and n=(2/3,1/3,2/3)n = (2/3, 1/3, 2/3). The slopes are p=−1p = -1 and q=−0.5q = -0.5: the surface goes down toward +x+x and, less steeply, toward +y+y.

A sphere with shadows. The test file renders a cap of a unit sphere with random albedo under five lights, four of them at about 50 degrees from the view direction. Near the edge of the cap some lights do not reach the surface, and 68 of the 845 readings are 0. Dropping these readings recovers every albedo and normal to 9 decimal places, since every pixel still has three lit readings. Keeping them gives albedo errors larger than 0.01, because a 0 reading does not fit the linear model.

Correctness

The full proof is in proofs/correctness.md.

  1. Shadows. With threshold 0, a reading is kept if and only if sk⊤g>0s_k^\top g > 0, and then it equals sk⊤gs_k^\top g.
  2. Exact recovery. M=∑sksk⊤M = \sum s_k s_k^\top is invertible if and only if the kept lights span 3D space, which needs at least three lights that are not in one plane through the origin. Then b=Mgb = M g, so line L5 returns gg itself.
  3. Least squares. With noise, M−1bM^{-1} b is the unique minimizer of ∑(Ik−sk⊤g)2\sum (I_k - s_k^\top g)^2. For independent noise with equal variance it is the best linear unbiased estimate of gg by the Gauss-Markov theorem.
  4. Necessity. If the lit lights lie in one plane through the origin, a vector orthogonal to that plane can be added to gg without changing any reading.
Proof: Photometric stereo recovers the albedo and normal exactly when the lit lights span space, and the least squares estimate otherwisefull

We use the pseudocode of the page and exact real arithmetic. At one pixel the surface has albedo ρ>0\rho > 0 and unit normal nn, and we write g=ρng = \rho n. Image kk has a known light vector sk∈R3s_k \in \mathbb{R}^3. The image formation model is the Lambertian model with attached shadows,

Ik=max⁡(0,sk⊤g).I_k = \max(0, s_k^\top g).

Lemma 1 (the shadow test). With threshold 0, line L2 keeps reading kk if and only if sk⊤g>0s_k^\top g > 0, and then Ik=sk⊤gI_k = s_k^\top g.

Proof. If sk⊤g>0s_k^\top g > 0 then Ik=sk⊤g>0I_k = s_k^\top g > 0. Otherwise Ik=0I_k = 0, which is not greater than the threshold. □\square

Lemma 2 (normal equations). Let AA be the set of kept readings and M=∑k∈Asksk⊤M = \sum_{k \in A} s_k s_k^\top. Then MM is invertible if and only if the vectors sks_k, k∈Ak \in A, span R3\mathbb{R}^3.

Proof. For any xx, x⊤Mx=∑k∈A(sk⊤x)2≥0x^\top M x = \sum_{k \in A} (s_k^\top x)^2 \ge 0, so MM is positive semidefinite, and Mx=0M x = 0 implies x⊤Mx=0x^\top M x = 0, which holds if and only if xx is orthogonal to every sks_k with k∈Ak \in A. Such an x≠0x \ne 0 exists if and only if the sks_k do not span R3\mathbb{R}^3. □\square

Theorem 1 (exact recovery). If the lights with sk⊤g>0s_k^\top g > 0 span R3\mathbb{R}^3, the algorithm returns ρ\rho and nn exactly at the pixel.

Proof. By Lemma 1, A={k:sk⊤g>0}A = \{k : s_k^\top g > 0\}, and Ik=sk⊤gI_k = s_k^\top g for k∈Ak \in A. Spanning needs at least three vectors, so line L3 does not skip the pixel. Line L4 computes b=∑k∈AIksk=∑k∈Asksk⊤g=Mgb = \sum_{k \in A} I_k s_k = \sum_{k \in A} s_k s_k^\top g = M g. By Lemma 2, MM is invertible, so line L5 returns gg. Then ∣g∣=ρ∣n∣=ρ>0|g| = \rho |n| = \rho > 0, and line L6 returns ρ\rho and g/ρ=ng / \rho = n. ■\blacksquare

Theorem 2 (least squares). If MM is invertible, line L5 returns the unique minimizer of E(g)=∑k∈A(Ik−sk⊤g)2E(g) = \sum_{k \in A} (I_k - s_k^\top g)^2, for any readings.

Proof. EE is a convex quadratic with gradient 2(Mg−b)2 (M g - b) and Hessian 2M2 M, which is positive definite by Lemma 2. Its only stationary point is M−1bM^{-1} b, and it is the minimum. □\square

If the readings are sk⊤gs_k^\top g plus independent noise with mean 0 and equal variance, this is the ordinary least squares estimate, which the Gauss-Markov theorem shows to be the best linear unbiased estimate of gg. The albedo ∣g∣|g| and the normal g/∣g∣g / |g| are nonlinear functions of gg, so the theorem does not make them unbiased.

Theorem 3 (the condition is needed). Suppose the lit lights do not span R3\mathbb{R}^3 and sk⊤g≠0s_k^\top g \ne 0 for every kk. Then other vectors g′≠gg' \ne g give exactly the same images.

Proof. Take x≠0x \ne 0 orthogonal to every sks_k with k∈Ak \in A, and let g′=g+txg' = g + t x. For k∈Ak \in A, sk⊤g′=sk⊤g>0s_k^\top g' = s_k^\top g > 0. For k∉Ak \notin A, sk⊤g<0s_k^\top g < 0, and for ∣t∣|t| small enough sk⊤g′<0s_k^\top g' < 0 too, so the reading stays 0. So gg and g′g' give the same value in every image. □\square

Lemma 3 (unknown lights). Let GG be any invertible 3×33 \times 3 matrix. The pair gˉ=G−⊤g\bar g = G^{-\top} g, sˉk=Gsk\bar s_k = G s_k gives the same images, attached shadows included.

Proof. gˉ⊤sˉk=g⊤G−1Gsk=g⊤sk\bar g^\top \bar s_k = g^\top G^{-1} G s_k = g^\top s_k, so both max⁡(0,⋅)\max(0, \cdot) values agree. □\square

So if the lights are not known, images alone determine gg only up to an invertible matrix. If gg comes from a smooth height field, g∝(−p,−q,1)g \propto (-p, -q, 1) with p=zxp = z_x and q=zyq = z_y. For the generalized bas-relief matrix

G=(100010μνλ),λ≠0,G = \begin{pmatrix} 1 & 0 & 0 \\ 0 & 1 & 0 \\ \mu & \nu & \lambda \end{pmatrix}, \quad \lambda \ne 0,

we get G−⊤(−p,−q,1)⊤=(−p−μ/λ,−q−ν/λ,1/λ)⊤G^{-\top} (-p, -q, 1)^\top = (-p - \mu / \lambda, -q - \nu / \lambda, 1 / \lambda)^\top, which is proportional to (−(λp+μ),−(λq+ν),1)(-(\lambda p + \mu), -(\lambda q + \nu), 1). This is the normal of the height field zˉ=λz+μx+νy\bar z = \lambda z + \mu x + \nu y. So the transformed normals again come from a surface, and the images cannot tell the two surfaces apart. Belhumeur, Kriegman and Yuille show that these are the only such matrices that keep every surface integrable, and that cast shadows are also preserved; we do not prove those parts here.

Complexity

The model is the real RAM. Each pixel reads its NN values and builds MM and bb in O(N)O(N), then solves a 3×33 \times 3 system in O(1)O(1). The total is Θ(NWH)\Theta(N W H) in every case, and the output takes Θ(WH)\Theta(W H). When every pixel uses all lights, the 3×N3 \times N pseudo-inverse of LL is computed once, and each pixel costs 3N3 N multiplications.

Properties

  • Local. Each pixel is solved on its own. There is no smoothness term and no matching.
  • Exact under the model. Noise-free Lambertian readings from three or more lit, non-coplanar lights give the exact albedo and normal.
  • Gives normals, not depth. The depth comes from integration and is known only up to an additive constant.
  • High detail. The normals have the full resolution of the camera, which shows fine surface detail that triangulation methods miss.
  • Needs the light vectors. The light directions and strengths must be calibrated, for example with a mirror sphere and a matte sphere.

Variants and improvements

  • Unknown lights. The images, stacked as a matrix of NN rows and WHW H columns, have rank 3 under the model. The singular value decomposition factors it into normals and lights up to an invertible 3×33 \times 3 matrix. Requiring an integrable surface reduces this to the generalized bas-relief ambiguity of Belhumeur, Kriegman and Yuille: zˉ=λz+μx+νy\bar z = \lambda z + \mu x + \nu y, which gives the same images, shadows included.
  • Robust estimation. Highlights and cast shadows are outliers to the linear model. Dropping the brightest and darkest readings, or a robust fit over many lights, handles them.
  • Non-Lambertian surfaces. Methods with a general BRDF, or with a table of reference objects of the same material, replace the dot product with a measured response.
  • Color. With color images and white light, the normal is shared by the three channels, and each channel has its own albedo.
  • Near lights and perspective. Lights close to the object change direction and strength across the surface, which makes the problem nonlinear but still solvable.

When to use it

Use photometric stereo when you control the lighting and want fine surface detail of a mostly matte object, for example in industrial inspection, scanning of coins, documents, skin or relief. It needs a fixed camera and object while the light moves, so it does not suit moving scenes without special multiplexed lights. For absolute depth, combine it with a triangulation method, such as structured light scanning, whose depths fix the low frequencies that integration gets wrong.

Pitfalls

  • Nonlinear camera response. The model needs readings proportional to the light. Gamma-corrected images must be made linear first.
  • Shadows and highlights. A 0 reading or a specular peak used as a Lambertian reading pulls the normal toward or away from that light. Drop them, as line L2 does for shadows.
  • Lights in one plane. If all light directions lie in one plane through the surface point, for example lamps placed along one straight line, MM is singular. Three lamps at the same height around the camera are fine.
  • Integration drift. Small biases in the normals add up over the integration and bend the surface, so the low-frequency shape can be wrong while the detail is right.
  • Mixed frames. Normals in the height-field frame have nz>0n_z > 0 toward the viewer. In the camera frame of the area, a surface that faces the camera has a negative ZZ component. Convert before you combine with other methods.

Implementations

Each implementation follows the pseudocode above. A comment @line links a line of code to a line of the pseudocode. Point at a line of the pseudocode to see the matching code. The build runs the native tests of each language.

photometric_stereo.pyI0RawGitHub
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/photometric-stereo/. The authors are listed in prov/QKJF6P.jsonl.

"""Lambertian photometric stereo with known distant lights (Woodham).

Vectors are in the height-field frame: x right, y in the image plane, z toward
the viewer. Image k has a light s_k (a 3-vector whose length is the light
strength), and a Lambertian point with albedo rho and unit normal n has the
brightness I_k = max(0, rho n . s_k). The unknown per pixel is g = rho n.
Images are lists of rows, img[v][u].
"""

import math


def solve3(M, b):
    """Solve the 3 x 3 system M x = b by Gaussian elimination with partial pivoting.
    Returns None if M is singular (relative to its size)."""
    A = [list(M[r]) + [b[r]] for r in range(3)]
    scale = max(abs(A[r][c]) for r in range(3) for c in range(3))
    if scale == 0.0:
        return None
    for c in range(3):
        piv = max(range(c, 3), key=lambda r: abs(A[r][c]))
        if abs(A[piv][c]) <= 1e-12 * scale:
            return None
        A[c], A[piv] = A[piv], A[c]
        for r in range(c + 1, 3):
            m = A[r][c] / A[c][c]
            for k in range(c, 4):
                A[r][k] -= m * A[c][k]
    x = [0.0, 0.0, 0.0]
    for r in (2, 1, 0):
        x[r] = (A[r][3] - sum(A[r][k] * x[k] for k in range(r + 1, 3))) / A[r][r]
    return x


def photometric_stereo(images, lights, threshold=0.0):
    """Per pixel least squares for g = rho n. Readings with I <= threshold are
    treated as shadow and dropped. Returns (albedo, normals) as images; a pixel
    with fewer than three usable readings, or with lights that do not span 3D,
    gets None in both."""
    height, width = len(images[0]), len(images[0][0])
    albedo = [[None] * width for _ in range(height)]
    normals = [[None] * width for _ in range(height)]
    for v in range(height):  # @line L1
        for u in range(width):
            use = [k for k in range(len(images)) if images[k][v][u] > threshold]  # @line L2
            if len(use) < 3:  # @line L3
                continue
            M = [[sum(lights[k][r] * lights[k][c] for k in use) for c in range(3)] for r in range(3)]  # @line L4
            b = [sum(images[k][v][u] * lights[k][r] for k in use) for r in range(3)]
            g = solve3(M, b)  # @line L5
            if g is None:
                continue
            rho = math.sqrt(g[0] ** 2 + g[1] ** 2 + g[2] ** 2)  # @line L6
            if rho == 0.0:
                continue
            albedo[v][u] = rho
            normals[v][u] = [g[0] / rho, g[1] / rho, g[2] / rho]
    return albedo, normals  # @line L7


def render(albedo, normals, lights):
    """Lambertian images with attached shadows: I = max(0, rho n . s)."""
    images = []
    for s in lights:
        img = []
        for arow, nrow in zip(albedo, normals):
            img.append([max(0.0, a * (n[0] * s[0] + n[1] * s[1] + n[2] * s[2]))
                        for a, n in zip(arow, nrow)])
        images.append(img)
    return images


def gradients(normal):
    """Surface slopes p = dz/dx and q = dz/dy from a normal (-p, -q, 1) / |.|."""
    nx, ny, nz = normal
    return -nx / nz, -ny / nz
test_photometric_stereo.py 130 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/photometric-stereo/. The authors are listed in prov/QKJF6P.jsonl.

import math
import random
import unittest

from photometric_stereo import gradients, photometric_stereo, render, solve3


def unit(x, y, z):
    n = math.sqrt(x * x + y * y + z * z)
    return [x / n, y / n, z / n]


def sphere_cap(size, extent, rng):
    """Normals and albedo of the cap z = sqrt(1 - x^2 - y^2) seen from +z."""
    albedo, normals = [], []
    for v in range(size):
        y = -extent + 2.0 * extent * v / (size - 1)
        arow, nrow = [], []
        for u in range(size):
            x = -extent + 2.0 * extent * u / (size - 1)
            nrow.append([x, y, math.sqrt(1.0 - x * x - y * y)])
            arow.append(rng.uniform(0.3, 1.0))
        albedo.append(arow)
        normals.append(nrow)
    return albedo, normals


def mat_vec(M, x):
    return [sum(M[r][c] * x[c] for c in range(3)) for r in range(3)]


class PhotometricStereoTest(unittest.TestCase):
    def test_worked_example(self):
        lights = [[0.0, 0.0, 1.0], [0.6, 0.0, 0.8], [0.0, 0.6, 0.8]]
        images = [[[0.6]], [[0.84]], [[0.66]]]
        albedo, normals = photometric_stereo(images, lights)
        self.assertAlmostEqual(albedo[0][0], 0.9, places=12)
        for got, want in zip(normals[0][0], (2.0 / 3.0, 1.0 / 3.0, 2.0 / 3.0)):
            self.assertAlmostEqual(got, want, places=12)
        p, q = gradients(normals[0][0])
        self.assertAlmostEqual(p, -1.0, places=12)
        self.assertAlmostEqual(q, -0.5, places=12)

    def test_exact_recovery_without_shadows(self):
        rng = random.Random(1)
        albedo, normals = sphere_cap(15, 0.6, rng)
        lights = [unit(0.0, 0.0, 1.0), unit(0.3, 0.1, 1.0), unit(-0.2, 0.3, 1.0),
                  unit(0.1, -0.35, 1.0), [0.4, 0.4, 1.5]]
        images = render(albedo, normals, lights)
        self.assertTrue(all(x > 0.0 for img in images for row in img for x in row))
        est_a, est_n = photometric_stereo(images, lights)
        for v in range(15):
            for u in range(15):
                self.assertAlmostEqual(est_a[v][u], albedo[v][u], places=9)
                for a, b in zip(est_n[v][u], normals[v][u]):
                    self.assertAlmostEqual(a, b, places=9)

    def test_three_lights_invert_the_light_matrix(self):
        rng = random.Random(2)
        lights = [unit(0.5, 0.0, 1.0), unit(-0.3, 0.4, 1.0), unit(0.0, -0.5, 1.0)]
        for _ in range(20):
            g = [rng.uniform(-0.3, 0.3), rng.uniform(-0.3, 0.3), rng.uniform(0.5, 1.0)]
            I = [sum(s[r] * g[r] for r in range(3)) for s in lights]
            if min(I) <= 0.0:
                continue
            albedo, normals = photometric_stereo([[[x]] for x in I], lights)
            got = [albedo[0][0] * c for c in normals[0][0]]
            want = solve3(lights, I)
            for a, b, c in zip(got, want, g):
                self.assertAlmostEqual(a, b, places=12)
                self.assertAlmostEqual(a, c, places=12)

    def test_shadowed_readings_are_dropped(self):
        rng = random.Random(3)
        albedo, normals = sphere_cap(13, 0.68, rng)
        lights = [unit(0.0, 0.0, 1.0), unit(1.2, 0.0, 1.0), unit(-1.2, 0.0, 1.0),
                  unit(0.0, 1.2, 1.0), unit(0.0, -1.2, 1.0)]
        images = render(albedo, normals, lights)
        shadowed = sum(1 for img in images for row in img for x in row if x == 0.0)
        self.assertGreater(shadowed, 0)
        est_a, est_n = photometric_stereo(images, lights, threshold=0.0)
        naive_a, _ = photometric_stereo(images, lights, threshold=-1.0)
        worst_naive = 0.0
        for v in range(13):
            for u in range(13):
                self.assertAlmostEqual(est_a[v][u], albedo[v][u], places=9)
                worst_naive = max(worst_naive, abs(naive_a[v][u] - albedo[v][u]))
        self.assertGreater(worst_naive, 0.01)

    def test_coplanar_lights_give_no_answer(self):
        lights = [unit(1.0, 0.0, 1.0), unit(-1.0, 0.0, 1.0), unit(0.0, 0.0, 1.0)]
        albedo, normals = photometric_stereo([[[0.5]], [[0.4]], [[0.7]]], lights)
        self.assertIsNone(albedo[0][0])
        self.assertIsNone(normals[0][0])

    def test_generalized_bas_relief_gives_the_same_images(self):
        rng = random.Random(4)
        albedo, normals = sphere_cap(9, 0.68, rng)
        lights = [unit(0.0, 0.0, 1.0), unit(0.9, 0.2, 1.0), unit(-0.7, 0.6, 1.0), unit(0.1, -0.9, 1.0)]
        mu, nu, lam = 0.4, -0.3, 1.7
        G = [[1.0, 0.0, 0.0], [0.0, 1.0, 0.0], [mu, nu, lam]]
        G_inv_T = [[1.0, 0.0, -mu / lam], [0.0, 1.0, -nu / lam], [0.0, 0.0, 1.0 / lam]]
        new_lights = [mat_vec(G, s) for s in lights]
        new_albedo, new_normals = [], []
        for arow, nrow in zip(albedo, normals):
            ar, nr = [], []
            for a, n in zip(arow, nrow):
                b = mat_vec(G_inv_T, [a * c for c in n])
                r = math.sqrt(sum(c * c for c in b))
                ar.append(r)
                nr.append([c / r for c in b])
            new_albedo.append(ar)
            new_normals.append(nr)
        first = render(albedo, normals, lights)
        second = render(new_albedo, new_normals, new_lights)
        for img_a, img_b in zip(first, second):
            for row_a, row_b in zip(img_a, img_b):
                for x, y in zip(row_a, row_b):
                    self.assertAlmostEqual(x, y, places=12)
        self.assertTrue(any(x == 0.0 for img in first for row in img for x in row))
        est_a, _ = photometric_stereo(second, new_lights)
        self.assertAlmostEqual(est_a[4][4], new_albedo[4][4], places=9)
        self.assertGreater(abs(new_albedo[4][4] - albedo[4][4]), 0.1)


if __name__ == "__main__":
    unittest.main()

History

Woodham (1980) introduced photometric stereo: with the camera fixed and the light moved between images, each image constrains the orientation of the surface through the reflectance map of its light, and together the images fix the orientation at each pixel. Horn's book Robot Vision (1986) treats it next to shape from shading. Frankot and Chellappa (1988) gave a fast way to integrate the normals into a surface. Belhumeur, Kriegman and Yuille (1999) showed that with unknown lights the shape can only be found up to the generalized bas-relief transformation, which explains why relief sculptures look right under many lights.

References

  1. Robert J. Woodham, Photometric method for determining surface orientation from multiple images, Optical Engineering 19(1), 1980, pages 139 to 144, the whole paper (the reflectance map for several light sources and the solution for the surface orientation and albedo)
  2. Peter N. Belhumeur, David J. Kriegman and Alan L. Yuille, The bas-relief ambiguity, International Journal of Computer Vision 35(1), 1999, pages 33 to 44, the generalized bas-relief transformation and the proof that it preserves shading and shadows
  3. Robert T. Frankot and Rama Chellappa, A method for enforcing integrability in shape from shading algorithms, IEEE Transactions on Pattern Analysis and Machine Intelligence 10(4), 1988, pages 439 to 451, the projection of a gradient field onto integrable surfaces in the Fourier domain
  4. Berthold K. P. Horn, Robot Vision, MIT Press, 1986, the chapters on reflectance maps and photometric stereo
  5. Richard Szeliski, Computer Vision, Algorithms and Applications, second edition, Springer, 2022, Section 13.1.1, Shape from shading and photometric stereo

About this page

The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.

LadderLevelWhat the next level needs
Human proofH1 sketch
  • a full proof of time.average
  • a full proof of time.best
  • a full proof of time.worst
  • a full proof of space.extra
LeanL0 no Lean part
  • name a Lean module in the lean field (07)
Code (python)I0 not checked yet
  • the tests did not run in this build
VisualV0 none
  • add viz/scene.ts or a figure (10)
WritingW2 basic
  • a scene preset for the example