import numpy as np
import matplotlib.pyplot as plt
from scipy.ndimage import distance_transform_edt
n = 160
y, x = np.mgrid[-1.5:1.5:complex(n), -1.5:1.5:complex(n)]
mask = ((x**2 / 0.85**2 + y**2 / 0.55**2) <= 1)
mask &= ~((x > 0.15) & (x < 0.65) & (np.abs(y) < 0.18))
outside = distance_transform_edt(~mask)
inside = distance_transform_edt(mask)
phi = outside - inside # negative inside, positive outside
plt.figure(figsize=(6, 5))
plt.imshow(phi, extent=[-1.5, 1.5, -1.5, 1.5], origin="lower", cmap="coolwarm")
plt.contour(x, y, phi, levels=[0], colors="black", linewidths=2)
plt.contour(x, y, phi, levels=[-20, -10, 10, 20], colors="gray", linewidths=1)
plt.colorbar(label="signed distance")
plt.title("Signed distance function and zero contour")
plt.show()11 Curves, Surfaces, and Level Sets
Chapter goal. This chapter develops the geometry and analysis of curves, surfaces, contours, signed distance functions, active contours, and level-set methods. The emphasis is on clean mathematical definitions and on the way boundary geometry connects classical variational computer vision with modern segmentation, detection, tracking, medical imaging, and neural implicit representations.
Many computer vision problems ask for more than a label. They ask for a geometric object: the boundary of a tumor, the outline of a road, the surface of a face, the contour of a handwritten digit, the interface between foreground and background, or the zero level set of a neural implicit field.
This chapter studies the mathematics of such objects. The central transition is
\[ \text{pixels} \quad \longrightarrow \quad \text{curves and surfaces} \quad \longrightarrow \quad \text{evolving geometric objects}. \]
The chapter connects four viewpoints:
- Differential geometry: boundaries have tangent vectors, normal vectors, curvature, and length.
- Variational methods: boundaries are estimated by minimizing energies.
- Partial differential equations: curves evolve by normal velocity laws.
- Statistical learning: a boundary may be the prediction of a probabilistic or neural model.
For MA Applied Mathematics and MS Statistics students, this chapter is important because it shows how geometric modeling, optimization, and inference meet inside segmentation and shape analysis.
11.1 Learning objectives
After studying this chapter, you should be able to:
- represent image boundaries as parametric curves, implicit curves, or level sets;
- compute tangent vectors, normal vectors, length, area, and curvature;
- define signed distance functions and explain why they are useful in segmentation;
- formulate active contours as energy-minimization problems;
- derive the basic idea of level-set evolution;
- connect curvature regularization with smoothness priors;
- describe numerical discretizations of geometric PDEs;
- explain how modern neural segmentation, neural implicit surfaces, and differentiable rendering reuse these geometric ideas.
11.2 10.1 Why curves and surfaces appear in vision
A segmentation mask can be represented as a binary image,
\[ M: \Omega_h \to \{0,1\}. \]
But the object of interest is often the boundary
\[ \partial A, \]
where \(A\subset \Omega\) is a foreground region. The boundary is a geometric object. In two dimensions, \(\partial A\) is usually a curve. In three dimensions, \(\partial A\) is usually a surface.
Examples:
| Vision task | Geometric output |
|---|---|
| edge detection | curves of large intensity change |
| object segmentation | closed object boundary |
| medical image segmentation | organ/tumor contour or surface |
| stereo and depth | visible surface geometry |
| shape reconstruction | 3D surface or implicit level set |
| video tracking | evolving contour over time |
| neural rendering | learned implicit surface or density field |
A key idea is that geometry gives structure to an otherwise high-dimensional pixel problem. Instead of estimating every pixel independently, one estimates a boundary that is smooth, coherent, and compatible with image evidence.
11.3 10.2 Parametric curves
A parametric plane curve is a map
\[ \gamma:[a,b]\to \mathbb{R}^2, \qquad s\mapsto \gamma(s)=(x(s),y(s)). \]
If the curve is closed, one often uses a periodic parameterization
\[ \gamma:S^1\to \mathbb{R}^2. \]
For example, a circle of radius \(r\) centered at \(c=(c_1,c_2)\) is
\[ \gamma(\theta)=c+r(\cos\theta,\sin\theta), \qquad 0\le \theta <2\pi. \]
The derivative is
\[ \gamma'(s)=\left(x'(s),y'(s)\right), \]
and the speed is
\[ \|\gamma'(s)\|_2. \]
A curve is regular if
\[ \gamma'(s)\neq 0 \]
for all \(s\). Regularity means that the curve has a well-defined tangent direction.
11.3.1 Arc length
The length of a parametric curve is
\[ L(\gamma)=\int_a^b \|\gamma'(s)\|_2\,ds. \]
If \(\gamma\) is sampled at points \(\gamma_0,\gamma_1,\ldots,\gamma_N\), a discrete approximation is
\[ L_h(\gamma)=\sum_{i=0}^{N-1}\|\gamma_{i+1}-\gamma_i\|_2. \]
For a closed curve, use \(\gamma_N=\gamma_0\).
11.3.2 Tangent and normal
The unit tangent vector is
\[ T(s)=\frac{\gamma'(s)}{\|\gamma'(s)\|_2}. \]
A unit normal can be obtained by rotating \(T\) by \(90^\circ\):
\[ N(s)=(-T_2(s),T_1(s)). \]
The sign convention depends on the orientation of the curve.
11.3.3 Curvature
Curvature measures how quickly the tangent direction changes. If the curve is parameterized by arc length \(\ell\), then
\[ \kappa(\ell)=\left\|\frac{dT}{d\ell}\right\|_2. \]
For a general parameter \(s\), the signed curvature of a plane curve is
\[ \kappa(s)= \frac{x'(s)y''(s)-y'(s)x''(s)}{ \left(x'(s)^2+y'(s)^2\right)^{3/2}}. \]
For a circle of radius \(r\), the curvature is constant:
\[ \kappa=\frac{1}{r}. \]
Thus small circles have high curvature and large circles have low curvature.
Curvature is a mathematical way to penalize jagged boundaries. A segmentation method that penalizes boundary length or curvature is saying: among explanations that match the image evidence, prefer smoother shapes.
11.4 10.3 Interactive: parametric curves and curvature
The following interactive compares several parametric curves and their curvature behavior. The cardioid and ellipse show how curvature changes along a contour.
Parametric curves and curvature
Select a curve and inspect the tangent/normal geometry visually.
11.5 10.4 Implicit curves
A different way to describe a curve is as the zero set of a scalar function:
\[ C=\{(x,y)\in\Omega: \phi(x,y)=0\}. \]
This is called an implicit representation. For example, the circle centered at \(c=(c_1,c_2)\) with radius \(r\) can be written as
\[ \phi(x,y)=(x-c_1)^2+(y-c_2)^2-r^2. \]
Then
\[ \phi(x,y)=0 \]
is the circle,
\[ \phi(x,y)<0 \]
is the inside, and
\[ \phi(x,y)>0 \]
is the outside.
11.5.1 Regular level sets
If
\[ \nabla \phi(x,y)\neq 0 \]
on the set \(\phi(x,y)=0\), then the implicit function theorem says that the zero set is locally a smooth curve.
The gradient
\[ \nabla \phi=(\phi_x,\phi_y) \]
is perpendicular to the level sets of \(\phi\). Therefore, a unit normal is
\[ n=\frac{\nabla \phi}{\|\nabla \phi\|_2}. \]
This fact is central in level-set methods: the boundary does not need an explicit parameterization. Its normal direction can be computed from the implicit function.
11.5.2 Curvature of an implicit curve
For a level set \(\phi=0\), the curvature can be written as
\[ \kappa=\nabla\cdot\left(\frac{\nabla \phi}{\|\nabla \phi\|_2}\right). \]
In coordinates,
\[ \kappa = \frac{ \phi_{xx}\phi_y^2-2\phi_x\phi_y\phi_{xy}+\phi_{yy}\phi_x^2 }{ (\phi_x^2+\phi_y^2)^{3/2} }. \]
This formula is important because it lets us compute curvature directly on an image grid.
11.6 10.5 Signed distance functions
A signed distance function for a region \(A\subset\mathbb{R}^2\) is a function \(d_A^s\) such that
\[ d_A^s(x)= \begin{cases} -d(x,\partial A), & x\in A,\\ 0, & x\in \partial A,\\ d(x,\partial A), & x\notin A. \end{cases} \]
A common convention uses negative values inside the object and positive values outside. Some communities use the opposite sign.
The signed distance function satisfies the Eikonal equation almost everywhere:
\[ \|\nabla d_A^s(x)\|_2=1. \]
This property makes signed distance functions numerically stable for representing moving boundaries.
11.6.1 Why signed distance functions are useful
Signed distance functions are useful because they encode both topology and geometry:
| Quantity | Read from signed distance function |
|---|---|
| boundary | zero level set \(\phi=0\) |
| inside/outside | sign of \(\phi\) |
| normal direction | \(\nabla \phi/\|\nabla \phi\|\) |
| distance to boundary | \(|\phi|\) |
| curvature | \(\nabla\cdot(\nabla\phi/\|\nabla\phi\|)\) |
In modern vision, signed distance functions appear in classical level-set segmentation, 3D reconstruction, neural implicit representations, neural radiance fields, and differentiable rendering.
11.7 10.6 Interactive: signed distance and level sets
This interactive visualizes a signed distance function for a circle. The boundary is the zero contour.
Signed distance function and level sets
Change the radius. The zero contour is the object boundary; other contours are offset curves.
11.8 10.7 Boundary length and area from level sets
Let \(H\) be the Heaviside step function:
\[ H(z)= \begin{cases} 1, & z\ge 0,\\ 0, & z<0. \end{cases} \]
If \(\phi\) is negative inside a region \(A\), then
\[ \mathbf{1}_A(x)=1-H(\phi(x)). \]
The area of \(A\) can be expressed as
\[ \operatorname{Area}(A)=\int_\Omega \left(1-H(\phi(x))\right)\,dx. \]
The boundary length can be written using the Dirac delta distribution:
\[ \operatorname{Length}(\partial A) = \int_\Omega \delta(\phi(x))\|\nabla \phi(x)\|_2\,dx. \]
These formulas transform geometric quantities into integrals over the image domain. This is one reason level sets are powerful: geometric optimization can be written in terms of functions on a fixed grid.
For numerical work, one uses smooth approximations such as
\[ H_\epsilon(z)=\frac{1}{2}\left(1+\frac{2}{\pi}\arctan\left(\frac{z}{\epsilon}\right)\right), \]
and
\[ \delta_\epsilon(z)=H_\epsilon'(z) =\frac{1}{\pi}\frac{\epsilon}{\epsilon^2+z^2}. \]
11.9 10.8 Active contours: snakes
An active contour is a curve that moves to minimize an energy functional. The classical snake model represents a contour as a parametric curve \(\gamma(s)\) and minimizes an energy of the form (Kass et al. 1988)
\[ E(\gamma) = \int_0^1 \left[ \frac{\alpha}{2}\|\gamma'(s)\|_2^2 + \frac{\beta}{2}\|\gamma''(s)\|_2^2 +P(\gamma(s)) \right]ds. \]
The terms have clear meanings:
| Term | Meaning |
|---|---|
| \(\|\gamma'(s)\|^2\) | elasticity, discourages stretching |
| \(\|\gamma''(s)\|^2\) | bending penalty, encourages smoothness |
| \(P(\gamma(s))\) | image potential, attracts curve to edges |
A common image potential is
\[ P(x,y)=-\|\nabla (G_\sigma * I)(x,y)\|_2^2, \]
so the curve is attracted to locations with large smoothed gradient magnitude.
11.9.1 Euler–Lagrange intuition
Ignoring boundary conditions, the variation of the internal energy gives terms like
\[ -\alpha\gamma''(s)+\beta\gamma''''(s). \]
The image potential contributes
\[ \nabla P(\gamma(s)). \]
Thus a gradient-flow version of the active contour has the schematic form
\[ \frac{\partial \gamma}{\partial t} = \alpha\gamma''- \beta\gamma''''-\nabla P(\gamma). \]
The curve evolves under a balance of smoothness forces and image forces.
11.9.2 Strengths and weaknesses
Active contours are interpretable and geometrically meaningful. However, parametric curves have difficulties with topological changes. If a curve should split into two objects or merge with another curve, the parameterization becomes awkward. Level-set methods solve this by representing the curve implicitly.
11.10 10.9 Region-based active contours
Edge-based active contours are sensitive to weak or noisy edges. Region-based methods use statistics inside and outside the contour.
A famous model is the Chan–Vese model (Chan and Vese 2001), which is related to the Mumford–Shah functional (Mumford and Shah 1989). For a region \(A\) with boundary \(C=\partial A\), define
\[ E(A,c_1,c_2) = \mu\operatorname{Length}(\partial A) +\nu\operatorname{Area}(A) +\lambda_1\int_A (I(x)-c_1)^2\,dx +\lambda_2\int_{\Omega\setminus A}(I(x)-c_2)^2\,dx. \]
Here \(c_1\) is the mean intensity inside the object and \(c_2\) is the mean intensity outside.
For fixed \(A\), the optimal constants are
\[ c_1=\frac{1}{|A|}\int_A I(x)\,dx, \qquad c_2=\frac{1}{|\Omega\setminus A|}\int_{\Omega\setminus A} I(x)\,dx. \]
The contour is encouraged to separate the image into two statistically homogeneous regions while maintaining a short and smooth boundary.
11.10.1 Statistical interpretation
Assume the image intensities are generated by
\[ I(x)= \begin{cases} c_1+\varepsilon_x, & x\in A,\\ c_2+\varepsilon_x, & x\notin A, \end{cases} \]
where
\[ \varepsilon_x\sim N(0,\sigma^2). \]
Then the squared-error terms correspond to a Gaussian negative log-likelihood, while the boundary-length term acts as a geometric prior.
Thus the variational model can be read as a MAP estimator:
\[ \widehat A = \arg\max_A p(I\mid A)p(A). \]
11.11 10.10 Level-set evolution
In a level-set method, the evolving curve \(C(t)\) is represented as
\[ C(t)=\{x\in\Omega: \phi(x,t)=0\}. \]
Suppose the curve moves with normal velocity \(F\). That means a point on the curve satisfies
\[ \frac{dX}{dt}=F n. \]
Since \(X(t)\) stays on the zero level set,
\[ \phi(X(t),t)=0. \]
Differentiate with respect to \(t\):
\[ \phi_t + \nabla\phi\cdot X_t=0. \]
Using
\[ X_t=F\frac{\nabla\phi}{\|\nabla\phi\|}, \]
we obtain the fundamental level-set equation
\[ \phi_t+F\|\nabla\phi\|=0. \]
This equation was developed as a way to track moving fronts and interfaces (Osher and Sethian 1988; Sethian 1999).
11.11.1 Examples of velocity laws
Different choices of \(F\) produce different geometric motions.
| Velocity \(F\) | Effect |
|---|---|
| constant | expands or shrinks the curve |
| \(F=\kappa\) | curvature flow, smooths the curve |
| \(F=g(I)(\kappa+c)\) | image-dependent geodesic active contour |
| learned \(F_\theta(I,x)\) | neural or data-driven evolution |
11.11.2 Curvature flow
If
\[ F=\kappa, \]
then the level-set equation becomes
\[ \phi_t+\kappa\|\nabla\phi\|=0. \]
Depending on sign convention, this produces motion by curvature. High-curvature parts move faster, so small bumps disappear quickly. This is a geometric version of smoothing.
11.12 10.11 Interactive: curvature flow intuition
This interactive shows a noisy closed curve evolving toward a smoother shape. It is not a production-level PDE solver; it is a visual finite-difference illustration of curvature-based smoothing.
Curvature flow intuition
Increase the number of smoothing steps to see high-frequency boundary oscillations disappear.
11.13 10.12 Geodesic active contours
An edge-based level-set model often uses an edge indicator function
\[ g(x)=\frac{1}{1+\|\nabla(G_\sigma*I)(x)\|_2^2}. \]
This function is small near strong edges and close to one in flat regions. A geodesic active contour energy has the schematic form
\[ E(C)=\int_C g(x)\,ds. \]
This is a weighted curve length. The contour prefers to be short, but it also likes to pass through image edges where \(g\) is small.
The corresponding evolution has the schematic form
\[ \phi_t = g\kappa\|\nabla\phi\|+ \nabla g\cdot\nabla\phi. \]
The first term smooths the contour, while the second attracts it toward edges.
Edge-based contours can leak through weak boundaries. Region-based or learned terms are often needed when edges are missing, noisy, or misleading.
11.14 10.13 Interactive: energy terms for a contour
This interactive illustrates a simple energy trade-off. A curve is encouraged to be short, but also attracted toward image evidence. This is the essence of active-contour modeling.
Active-contour energy trade-off
The total energy is a combination of boundary regularity and image evidence.
11.15 10.14 Numerical discretization
Level-set and active-contour methods are continuous models, but images live on grids. We need discrete approximations.
Let
\[ \phi_{i,j}^n \approx \phi(ih,jh,n\Delta t). \]
Finite differences approximate derivatives:
\[ D_x^+\phi_{i,j}=\frac{\phi_{i+1,j}-\phi_{i,j}}{h}, \qquad D_x^-\phi_{i,j}=\frac{\phi_{i,j}-\phi_{i-1,j}}{h}. \]
Similarly for \(y\). A central-difference gradient is
\[ \nabla_h\phi_{i,j} = \left( \frac{\phi_{i+1,j}-\phi_{i-1,j}}{2h}, \frac{\phi_{i,j+1}-\phi_{i,j-1}}{2h} \right). \]
Curvature can be approximated by
\[ \kappa_{i,j} \approx \nabla_h\cdot \left( \frac{\nabla_h\phi_{i,j}}{\sqrt{\|\nabla_h\phi_{i,j}\|^2+\epsilon^2}} \right). \]
The small \(\epsilon\) prevents division by zero.
11.15.1 Time stepping
A simple explicit scheme for
\[ \phi_t+F\|\nabla\phi\|=0 \]
is
\[ \phi^{n+1}_{i,j} = \phi^n_{i,j} - \Delta t F^n_{i,j}\|\nabla_h\phi^n_{i,j}\|. \]
Explicit schemes are simple but require a stability condition. For hyperbolic motion, a typical condition has the form
\[ \Delta t \le C\frac{h}{\max |F|}. \]
Curvature terms impose stricter restrictions because they behave like diffusion.
11.15.2 Reinitialization
During evolution, \(\phi\) may stop being a signed distance function. One can reinitialize it by solving
\[ \phi_\tau+ \operatorname{sign}(\phi_0)(\|\nabla\phi\|-1)=0 \]
until steady state. The zero level set should remain fixed while the function becomes distance-like again.
11.16 10.15 Surfaces in three dimensions
In 3D vision, boundaries are surfaces. A parametric surface is a map
\[ X:U\subset\mathbb{R}^2\to\mathbb{R}^3, \qquad (u,v)\mapsto X(u,v). \]
The tangent vectors are
\[ X_u=\frac{\partial X}{\partial u}, \qquad X_v=\frac{\partial X}{\partial v}. \]
The surface normal is
\[ n=\frac{X_u\times X_v}{\|X_u\times X_v\|_2}. \]
Surface area is
\[ \operatorname{Area}(X) = \int_U \|X_u\times X_v\|_2\,du\,dv. \]
An implicit surface is a level set
\[ S=\{x\in\mathbb{R}^3: \phi(x)=0\}. \]
The normal is again
\[ n=\frac{\nabla\phi}{\|\nabla\phi\|_2}. \]
This same formula appears in 2D and 3D, which is one of the main advantages of implicit geometry.
11.17 10.16 Neural implicit surfaces
Modern computer vision often represents geometry with a neural network
\[ f_\theta:\mathbb{R}^3\to\mathbb{R}. \]
The surface is the zero level set
\[ S_\theta=\{x\in\mathbb{R}^3:f_\theta(x)=0\}. \]
If \(f_\theta\) is trained to approximate a signed distance function, one often includes an Eikonal loss:
\[ \mathcal{L}_{\text{eikonal}}(\theta) = \mathbb{E}_{x}\left(\|\nabla_x f_\theta(x)\|_2-1\right)^2. \]
This encourages \(f_\theta\) to behave like a signed distance field.
11.17.1 Relation to segmentation networks
A semantic segmentation network outputs a probability field
\[ p_\theta(x)=P_\theta(Y(x)=1\mid I). \]
The predicted boundary can be viewed as a level set
\[ \{x:p_\theta(x)=\tau\}. \]
Thus even modern pixelwise neural networks implicitly define contours and surfaces.
11.18 10.17 Curves and surfaces as random objects
For statistical modeling, a boundary may be uncertain. Instead of estimating a single curve \(C\), one may model a random curve
\[ C\sim \Pi. \]
In practice, uncertainty may be represented by a probability field
\[ p(x)=P(x\in A\mid I), \]
or by an ensemble of predicted masks
\[ A^{(1)},A^{(2)},\ldots,A^{(B)}. \]
Boundary uncertainty can be summarized using signed distance functions:
\[ \phi^{(b)}(x)=d_{A^{(b)}}^s(x). \]
Then one may compute
\[ \overline{\phi}(x)=\frac{1}{B}\sum_{b=1}^B \phi^{(b)}(x), \]
and pointwise uncertainty
\[ \widehat{\operatorname{Var}}(\phi(x)) = \frac{1}{B-1}\sum_{b=1}^B \left(\phi^{(b)}(x)-\overline{\phi}(x)\right)^2. \]
This is useful in medical imaging, where a segmentation boundary is often not exactly determined by the image data.
11.19 10.18 Python example: signed distance and contours
The following example constructs a binary mask, computes an approximate signed distance function, and plots level sets.
11.20 10.19 Python example: curvature from an implicit function
This example computes curvature from an implicit level-set function.
import numpy as np
import matplotlib.pyplot as plt
n = 180
y, x = np.mgrid[-2:2:complex(n), -2:2:complex(n)]
phi = np.sqrt(x**2 + y**2) - 1.0
dy, dx = np.gradient(phi)
grad_norm = np.sqrt(dx**2 + dy**2 + 1e-8)
nx = dx / grad_norm
ny = dy / grad_norm
kappa_y, _ = np.gradient(ny)
_, kappa_x = np.gradient(nx)
kappa = kappa_x + kappa_y
plt.figure(figsize=(6, 5))
plt.imshow(kappa, extent=[-2, 2, -2, 2], origin="lower", cmap="viridis")
plt.contour(x, y, phi, levels=[0], colors="white", linewidths=2)
plt.colorbar(label="estimated curvature")
plt.title("Curvature from div(grad phi / |grad phi|)")
plt.show()For a unit circle, the curvature near the zero level set should be close to \(1\), up to discretization error and sign convention.
11.21 10.20 Python example: simple active-contour intuition
The next code builds a synthetic image potential and shows how a circular contour can be selected by minimizing a simple one-parameter energy.
import numpy as np
import matplotlib.pyplot as plt
r_grid = np.linspace(0.2, 1.8, 300)
r_true = 1.0
length_penalty = 2 * np.pi * r_grid
image_attraction = -np.exp(-0.5 * ((r_grid - r_true) / 0.08)**2)
for lam in [0.2, 0.8, 1.5, 2.5]:
energy = 0.35 * length_penalty + lam * image_attraction
r_hat = r_grid[np.argmin(energy)]
plt.plot(r_grid, energy, label=f"lambda={lam}, r_hat={r_hat:.2f}")
plt.axvline(r_true, color="black", linestyle="--", label="true edge radius")
plt.xlabel("contour radius")
plt.ylabel("energy")
plt.title("Length regularization versus image attraction")
plt.legend()
plt.show()11.22 10.21 TensorFlow example: Eikonal loss for a neural implicit field
The following example shows the structure of an Eikonal regularization term. It is included to connect classical signed distance functions with modern AI geometry.
import tensorflow as tf
class ImplicitMLP(tf.keras.Model):
def __init__(self, width=64, depth=4):
super().__init__()
self.layers_list = []
for _ in range(depth):
self.layers_list.append(tf.keras.layers.Dense(width, activation="relu"))
self.out = tf.keras.layers.Dense(1)
def call(self, x):
z = x
for layer in self.layers_list:
z = layer(z)
return self.out(z)
model = ImplicitMLP()
# sample 3D points
x = tf.random.uniform((1024, 3), minval=-1.5, maxval=1.5)
with tf.GradientTape() as tape:
tape.watch(x)
f = model(x)
grad_f = tape.gradient(f, x)
eikonal_loss = tf.reduce_mean((tf.norm(grad_f, axis=1) - 1.0)**2)
print("Eikonal loss:", float(eikonal_loss))This code does not train a full reconstruction system. Its purpose is to show the mathematical regularizer
\[ \left(\|\nabla_x f_\theta(x)\|_2-1\right)^2. \]
11.23 10.22 AI-assisted study components
Large language models and multimodal AI systems can be helpful in this chapter, but they should be used with mathematical verification.
11.23.1 Prompt 1: Curve representation comparison
Ask an AI assistant:
Compare parametric, implicit, and level-set representations of a closed contour. Give one advantage and one disadvantage of each for image segmentation.
Then verify that the answer correctly distinguishes:
- explicit parameterization;
- implicit zero set;
- topology changes;
- numerical grid representation.
11.23.2 Prompt 2: Derivation check
Ask:
Derive the level-set equation \(\phi_t+F|\nabla\phi|=0\) from the constraint \(\phi(X(t),t)=0\).
Check every chain-rule step. Make sure the normal direction and sign convention are stated clearly.
11.23.3 Prompt 3: Segmentation model critique
Give an AI assistant an image segmentation problem and ask:
Should I use an edge-based contour, a region-based contour, or a neural segmentation model? State the assumptions behind each choice.
A good answer should mention image contrast, boundary strength, available training data, noise, and shape prior.
11.23.4 Prompt 4: Debugging numerical PDE code
Ask:
My level-set evolution is unstable. What mathematical and numerical issues should I check?
The answer should mention time step size, gradient approximation, curvature discretization, reinitialization, boundary conditions, and sign convention.
11.24 10.23 Common pitfalls
- Confusing a contour with a mask. A mask is a region indicator; a contour is a boundary.
- Ignoring sign conventions. Some authors use negative inside; others use positive inside.
- Assuming curvature is always positive. Signed curvature depends on orientation.
- Using central differences for all terms. Hamilton–Jacobi equations often need upwind schemes.
- Forgetting boundary conditions. PDE behavior near the image boundary depends on how derivatives are extended.
- Interpreting neural masks as purely discrete. A probability map defines level sets and therefore implicit contours.
- Assuming smoothness is always good. Thin structures, corners, and sharp anatomical boundaries may be destroyed by too much regularization.
11.25 10.24 Chapter summary
This chapter introduced curves, surfaces, and level sets as geometric objects in computer vision. The main ideas are:
- a curve can be represented parametrically or implicitly;
- tangent, normal, curvature, length, and area provide geometric measurements;
- signed distance functions encode boundary, inside/outside, distance, normal, and curvature;
- active contours estimate boundaries by minimizing energy functionals;
- level-set methods evolve curves and surfaces through PDEs on a fixed grid;
- curvature regularization is a geometric smoothness prior;
- statistical interpretations connect region-based active contours to likelihoods and priors;
- modern AI models still use level-set ideas through probability maps, neural implicit functions, and Eikonal losses.
The next chapter studies motion. There, curves and image structures no longer remain static: they evolve across frames, leading to optical flow, motion fields, and temporal inference.
11.26 Exercises
11.26.1 Conceptual exercises
- Explain the difference between a parametric curve and an implicit curve.
- Why is the gradient of an implicit function perpendicular to its level sets?
- What information is stored in a signed distance function?
- Why can level-set methods naturally handle topological changes?
- Give one situation where an edge-based active contour may fail.
- Give one situation where a region-based active contour may fail.
- Explain how a neural segmentation probability map defines a family of contours.
11.26.2 Mathematical exercises
For the circle \[ \gamma(\theta)=(r\cos\theta,r\sin\theta), \] compute its speed, tangent vector, and curvature.
Let \[ \phi(x,y)=x^2+y^2-r^2. \] Show that \(\phi=0\) is a circle. Compute \(\nabla\phi\) and the unit normal on the boundary.
For a signed distance function \(\phi\), explain why \(\|\nabla\phi\|=1\) should hold away from singularities.
Starting from \[ \phi(X(t),t)=0, \] derive the level-set equation \[ \phi_t+F\|\nabla\phi\|=0. \]
For fixed region \(A\), derive the optimal constants \(c_1\) and \(c_2\) in the Chan–Vese energy.
Show that the length of a level-set boundary can be written formally as \[ \int_\Omega \delta(\phi)\|\nabla\phi\|\,dx. \]
Let \(f_\theta:\mathbb{R}^3\to\mathbb{R}\) approximate a signed distance function. Explain why the Eikonal regularizer penalizes deviations from distance-function behavior.
11.26.3 Python exercises
- Generate a binary mask of an ellipse and compute its signed distance function.
- Extract the zero contour using
matplotlib.contour. - Estimate curvature from a signed distance function using finite differences.
- Simulate smoothing of a noisy closed curve by repeatedly averaging neighboring points.
- Implement a simple Chan–Vese-like iteration on a synthetic image.
- Compare boundary length before and after morphological smoothing.
- Train a small neural network to approximate the signed distance function of a circle.
11.26.4 AI-assisted exercises
- Ask an AI assistant to explain the difference between snakes and level-set methods. Verify the explanation mathematically.
- Ask an AI assistant to derive the curvature formula for implicit curves. Identify any missing assumptions.
- Ask an AI assistant to write Python code for signed distance functions. Test the code on a circle and an ellipse.
- Ask an AI assistant to critique a segmentation energy for weak-edge images.
- Ask an AI assistant to propose a neural implicit model for a 3D surface. Translate the model into mathematical notation.
11.27 Notes and references
Classical active contours were introduced by Kass, Witkin, and Terzopoulos (Kass et al. 1988). Level-set methods for moving fronts were developed by Osher and Sethian (Osher and Sethian 1988) and are presented systematically in Sethian’s monograph (Sethian 1999). Region-based active contours are closely related to the Mumford–Shah functional (Mumford and Shah 1989) and the Chan–Vese model (Chan and Vese 2001). For a broad computer vision perspective, see Szeliski (Szeliski 2022).