Frontiers/Vision and Perception

Lesson 6.14,195 words

Vision and Perception

Perception connects an agent to the physical world. We follow one modality — vision — from the physics of image formation (the pinhole camera, perspective projection, lenses, shading, color) through the early operations that turn a pixel array into edges, texture, and motion, and into recognition by appearance.

╌╌╌╌

Perception gives an agent information about the world it inhabits by interpreting the response of sensors. A sensor measures some aspect of the environment in a form the agent program can use as input — a switch reporting one bit, or an eye reporting millions. Artificial agents share vision, hearing, and touch with humans, and add modalities the unaided human lacks: radar, infrared, GPS. This lesson covers one modality in depth, the richest one: vision.

A decision-theoretic agent in a partially observable world already carries a sensor model — a distribution over the evidence its sensors produce given a world state . For vision that model factors into two parts. An object model describes the things that inhabit the visual world (people, buildings, cars) — perhaps a precise CAD mesh, perhaps a vague constraint like human eyes sit 5 to 7 cm apart. A rendering model describes the physical and statistical process that turns a scene into a stimulus. Rendering is ambiguous: a white object in dim light can match a black object in bright light; a small nearby object can match a large distant one. Without further evidence you cannot tell a toy Godzilla filling the frame from a real monster far away. Prior knowledge resolves some of it (Godzilla is not real, so the image must be a toy); an agent can also just choose to ignore ambiguity it need not resolve, since it is unlikely to crash into an object miles away.

The problem for a vision-capable agent is a question of relevance: a video camera can produce ten gigabytes a minute, and which aspects of that torrent should shape the agent's action choices, and which should be ignored? Vision, like all perception, serves the agent's goals; it is not an end in itself. Three broad approaches carve up the work. Feature extraction applies simple local computations directly to the sensor readings — the reflex path a fly uses to land on a wall. Recognition draws category distinctions among the objects encountered (is this Grandma's face?). Reconstruction builds a geometric model of the world from one image or many. The rest of the lesson runs through the physics that makes all three possible and then through each in turn.

Image formation

Imaging distorts appearance. A photograph down a straight railway suggests the rails converge and meet; a hand held at arm's length blocks out the moon, which is not smaller than the hand; tilt the hand and it seems to shrink in the image without changing size in the world. Modelling these effects is the precondition for both recognition and reconstruction, so we start with the geometry of how light becomes a picture.

The pinhole camera and perspective projection

Image sensors gather light scattered from objects in a scene and form a two-dimensional image. In the eye the image lands on the retina; in a camera it lands on an image plane — a grid of a few million photosensitive pixels, each a CMOS or CCD element that reports a weighted average of the light arriving at it. To get a focused image, all the photons from one spot in the scene must arrive at approximately one spot in the plane. The simplest device that achieves this for stationary objects is a pinhole camera: a small opening at the front of a box and an image plane at the back. Because every photon that reaches the plane must pass through the pinhole, if the hole is small enough then nearby scene points map to nearby image points, and the image is in focus.

The pinhole camera. A scene point projects along the ray through the pinhole to the image point a distance behind it; the ray crossing at inverts the image left-right and up-down.

Put the origin of a 3-D coordinate frame at the pinhole, with the -axis along the optical axis. A scene point has coordinates and projects to a point with coordinates on the image plane a distance (the focal length) behind the hole. Similar triangles give the projection equations

These define perspective projection. Two facts follow directly. The in the denominator means the farther away an object is, the smaller its image — this is why a hand can cover the moon. And the minus signs mean the image is inverted, both left-right and up-down, relative to the scene.

Perspective explains why parallel lines appear to converge. Take a line in the scene through with direction , i.e. the points as ranges over the reals. Its projection is

As this tends to , provided — a limit that depends only on the direction , not on the starting point . So all lines sharing a direction converge to the same vanishing point . Railway tracks meet on the horizon because every parallel family collapses to a single point.

Take the limit apart to see why the starting point drops out. Divide numerator and denominator of each image coordinate by :

because and . The tail of the line — the part far from its anchor point — dominates, and the tail of every line with direction heads to the same image point. A family of rails, all pointing the same way, therefore converges to one dot. Two families pointing in two directions give two vanishing points; the line joining them, the locus of all directions parallel to the ground, is the horizon.

Worked example: projecting one point

Carry a single scene point through the equations with real numbers. Put a lamp post tip at — half a meter right of the optical axis, m up, four meters ahead — and use a -millimeter lens, m. The projection equations give

The signs flip both coordinates: a point up and to the right lands down and to the left, the inversion the pinhole forces. To turn millimeters on the sensor into pixel addresses, divide by the pixel pitch, the center-to-center spacing of the photosites — take five micrometers, mm. Then and , so relative to the image center the tip lands pixels left and pixels down.

Now halve the depth: walk the camera to m. Both image coordinates double, mm px and mm px. The whole image of the post grows by the same factor because and scale as : approaching an object makes its image grow hyperbolically.

The worked projection. A scene point m through a -mm lens lands at mm on the sensor (about pixels at a -micrometer pitch); halving to m doubles the image coordinates to mm. The point moves along its ray, image size scales as .

Lenses and focus

The pinhole forces a tradeoff. A small hole keeps the image sharp but lets in few photons, so the image is dark; worse, over a long exposure any moving object smears across the plane as motion blur. Widen the hole for more light and a single scene patch now spreads over a patch of image — blur again, this time spatial. Lens systems in vertebrate eyes and modern cameras resolve the dilemma: a large opening is covered by a lens that steers the light leaving a scene point, from a whole range of directions, back to a single point in the image plane.

A lens collects light leaving one scene point over a range of directions and focuses it to a single image point. Only points within the depth of field, around the focal plane, are in focus; the eye refocuses by reshaping the lens, a camera by moving it.

A lens has a limited depth of field: it can focus only points lying within some range of depths, centred on a focal plane. Objects outside that range blur. To move the focal plane, the camera slides its lens back and forth; the eye instead reshapes its lens with specialized muscles.

When perspective effects are mild, the full projection can be simplified. Spots on a distant leopard all sit at nearly the same depth with , so the scaling factor is nearly a constant , and the projection collapses to scaled orthographic projection, and . It is a good model for a shallow, distant patch — the face of a far building — and a poor one when the scene has serious internal depth.

Light and shading

The brightness of an image pixel is a function of the brightness of the scene patch that projects to it. Assuming a linear sensor (real ones saturate at the extremes but are linear in the middle), image brightness is a strong, if ambiguous, cue to an object's shape, and from shape to identity. Three causes of varying brightness are worth separating.

The first is the overall intensity of the light. Even though a white object in shadow may reflect less than a black object in sunlight, people perceive the white one as white — the visual system discounts illumination. The second is that different surface points reflect more or less of the incident light, which reads as texture or markings. The third is shading: patches facing the light are brighter than patches tilted away, an effect that comes from the object's geometry.

Most surfaces reflect by diffuse reflection, scattering light evenly in all outgoing directions, so a diffuse surface looks equally bright from any viewpoint — cloth, matte paint, rough wood, vegetation. A perfect mirror is the opposite, specular reflection, where what you see depends on viewing angle. Brushed metal, plastic, and wet floors show small bright specularities where specular reflection dominates. For most purposes it suffices to model every surface as diffuse with a few specularities.

The dominant outdoor light source is the sun, whose rays are effectively parallel: a distant point light source. The energy a surface patch collects then depends on the angle between the illumination direction and the surface normal.

Two patches under a distant point source. Patch A is tilted away (angle to the normal near 90 degrees) and cuts few rays per unit area, so it is dark; patch B faces the source (angle near 0) and collects more, so it is bright. Lambert's cosine law: brightness is proportional to the cosine of that angle.

A diffuse patch reflects a fraction of what it collects, its diffuse albedo — about for snow or white paper, about for charcoal or black velvet. Lambert's cosine law states that the brightness of a diffuse patch is

where is the source intensity and the angle between the light direction and the surface normal. Bright pixels come from patches facing the light; dark pixels from patches seeing it only tangentially — so shading carries shape, a cue we exploit later. A patch the light never reaches is in shadow, seldom uniformly black because scattered light (the sky outdoors, other surfaces indoors) still reaches it. These interreflections are often folded into a constant ambient illumination term added to the predicted intensity.

Worked example: albedo, angle, and the shadow crossover

Fix the source intensity at (a normalized unit) and tabulate for the two extreme albedos as the surface tilts away from the light.

snow, charcoal,

Head-on the snow is times brighter than the charcoal ( versus ), exactly the albedo ratio . But brightness is the product of albedo and geometry, and the two can trade off. Ask when snow tilted steeply matches charcoal facing the sun: set , so and . A snowbank turned almost edge-on to the sun sends the camera the same brightness as a lump of charcoal pointed straight at it. Measured pixel brightness alone therefore cannot separate a white surface in near-shadow from a black one in full sun. The visual system discounts illumination to recover albedo, and shape-from-shading algorithms make the opposite bet: hold albedo fixed and read the variation as surface tilt.

Color

Light arriving at the eye carries different energy at different wavelengths, a spectral energy density. Human eyes respond across roughly the 380–750 nm band with three types of color receptor, peaking near 420 nm (blue), 540 nm (green), and 570 nm (red) — the eye captures only a coarse three-number summary of the full spectrum, enough to tell a ripe fruit from an unripe one. The principle of trichromacy states that for any spectral energy density, however complicated, one can construct a mixture of just three primaries (usually red, green, blue) that a human cannot distinguish from it. This is why displays get by with R/G/B elements, and why vision algorithms model each surface with three albedos and each source with three intensities, applying Lambert's law to each channel.

The same surface produces different image colors under differently colored light, yet human observers largely discount this and estimate the surface's color under white light — color constancy. Reasonable color-constancy algorithms now exist; a simple version is the auto white balance in a camera.

Early image-processing operations

Light reflecting off scene surfaces yields an image of, say, five million 3-byte pixels, corrupted by sensor noise and highly redundant. The first operations in the vision pipeline are early or low-level: they act locally (using only a few nearby pixels) and without knowledge of what objects might be present. That locality makes them good candidates for parallel hardware — a GPU, or an eye. We cover three local operations — edge detection, texture, and optical flow — and one mid-level operation, segmentation.

Edge detection

Edges are lines or curves in the image plane across which image brightness changes sharply. Detecting them abstracts the messy multi-megabyte array toward a compact representation, because edge contours in the image tend to correspond to important contours in the scene. Not all edges have the same physical cause: they arise at depth discontinuities (an object boundary against a farther background), surface-orientation discontinuities (a crease), reflectance discontinuities (a painted marking), and illumination discontinuities (a shadow's edge). Edge detection does not distinguish these; later processing must.

The four kinds of scene discontinuity that produce edges: (1) depth, where an object boundary sits in front of a farther surface; (2) surface orientation, a crease; (3) reflectance, a painted marking; (4) illumination, the boundary of a cast shadow.

How do we find edges? An edge is a location where brightness changes fast, so a naive plan is to differentiate the image and flag places where the magnitude of the derivative is large. Consider the brightness profile along a one-dimensional cross-section cutting across an edge — say the boundary between a desk and the wall behind it. It shows a step, but a noisy one, and its raw derivative peaks at the true edge yet also spikes at spurious noise locations.

An edge profile. Top: intensity across an edge near , a noisy step. Middle: the raw derivative peaks at the edge but also at noise, e.g. near . Bottom: convolving with the derivative-of-Gaussian smooths first, so only the true peak survives.

To address this, smooth before differentiating. Sensor noise is well modelled as an independent Gaussian perturbation at each pixel; averaging a pixel with its neighbors cancels it, and the best weighting keeps the nearest pixels heaviest. This weighting is the Gaussian filter, using the Gaussian of standard deviation and mean zero,

Smoothing replaces with a weighted sum of nearby pixels — a convolution of the image with the Gaussian, . A of one pixel erases a little noise; two pixels erases more at the cost of detail. There is a useful identity: for any and , . So instead of smoothing and then differentiating we can convolve the image once with the derivative of the Gaussian, , and mark as edges the peaks above a threshold. The bottom panel above is exactly ; the spurious peak at is gone.

Worked example: a 1-D edge through two kernels

For example, run a short signal through both kernels. Take nine intensity samples with a step near the middle and one bad pixel — a noise blip — at index :

The true edge is the jump from about to about between indices and ; the at index is noise. A raw difference, the two-tap kernel that gives , produces

The real edge shows up as at index — but the lone bad pixel throws off a then a (indices and ), a spurious pair a third the size of the true peak. Threshold at anything below and you flag the noise as an edge; threshold above it and you keep only the strongest edges. Now use a three-tap derivative-of-Gaussian kernel , which computes — a central difference over a two-sample span, so it lightly smooths as it differentiates:

The true edge is now a clean pair of at indices and , while the blip collapses to a ripple — the wider stencil averaged the outlier against its neighbors before differencing. The edge-to-noise gap widened from (a ratio of ) to (a ratio of ), so a single threshold now separates edge from noise cleanly. This is at a tiny acting on one row; the two-dimensional detector does the same thing with the partial derivatives of a -D Gaussian.

In two dimensions an edge can run at any angle. Treating brightness as a scalar function of and , its gradient is a vector

and, as before, we compute in one step by convolving with the partial derivatives of a Gaussian. Edges are where the gradient magnitude is large. The gradient's direction defines the edge orientation,

giving a at every pixel. A pixel is an edge point when its gradient magnitude is a local maximum along the gradient direction (so the edge sits exactly on the crest, not its flank) and exceeds a threshold. A final linking stage joins neighboring edge pixels with consistent orientations into continuous edge curves.

Texture

In computational vision texture is a spatially repeating pattern that can be sensed visually — windows on a building, stitches on a sweater, spots on a leopard, pebbles on a beach. Sometimes the repetition is nearly periodic; often it is only statistical. Where brightness is a property of a single pixel, texture only makes sense for a multi-pixel patch. A natural summary computes the edge orientation at each pixel of a patch and forms a histogram of orientations: bricks give two peaks (vertical and horizontal), leopard spots give a broad spread.

A texture is summarized by a histogram of local edge orientations. A brick wall concentrates orientation near horizontal and vertical (two peaks); leopard spots spread orientation broadly. The summary is largely invariant to illumination, which makes texture a stable cue.

Orientation histograms are largely invariant to changes in illumination, which makes texture a stable clue for recognition where brightness edges are not: the same markings survive a change in lighting. Texture also rescues segmentation on textured objects, where the important boundaries can be lost among the texture elements — you miss the tiger for the stripes. A patch on the tiger and a patch on the grass have very different orientation histograms, so comparing texture properties recovers the boundary between them.

Optical flow

Give the camera a video instead of a single frame. When an object moves, or the camera moves relative to an object, the resulting apparent motion in the image is optical flow — the direction and speed of image features, measured in pixels per second. Flow encodes scene structure: from a moving train, distant scenery drifts slowly and near scenery streaks by, so the rate of apparent motion carries distance. Flow also exposes actions; the fastest-flowing regions of a tennis video are the racket and the front leg.

The flow field at a point has components and . To measure it we match corresponding points between one frame and the next. A simple method exploits that image patches around corresponding points have similar intensity: take a block centred on at time and compare it to blocks centred on at , using the sum of squared differences

with ranging over the block. The displacement that minimizes SSD gives the flow . This needs texture: on a uniform white wall the SSD is nearly equal for every candidate, so the match is a blind guess. The best flow algorithms add further constraints where the scene is only partly textured.

Segmentation of images

Segmentation breaks an image into regions of similar pixels. Within one object, or one part, attributes like brightness, color, and texture vary little; across an inter-object boundary one or more of them jumps. Two dual approaches exist: detect the boundaries of regions, or detect the regions themselves.

Two dual routes to segmentation. Boundary-based: classify each pixel and orientation as boundary-or-not from the contrast between two half-disks of a local window (features of brightness, color, texture). Region-based: treat pixels as graph nodes with similarity-weighted edges and cut the graph to keep similar pixels together.

For boundaries, note a boundary through pixel has an orientation , so detecting boundaries becomes classification: from features of a local neighborhood, predict the probability that a boundary of orientation runs through the pixel. Center a disk on , split it into two half-disks by a diameter at angle , and if a boundary really lies there the halves should differ in their histograms of brightness, color, and texture. A classifier trained on natural images that humans hand-marked can predict far better than simple edge detection — but thresholding need not yield closed curves, and it uses only local context.

The region approach instead clusters pixels by brightness, color, and texture. Treat each pixel as a graph node, put an edge between pixels weighted by how similar they are, and partition the graph to minimize a normalized cut: cut few of the strong edges, keep similar pixels grouped. Purely local, low-level segmentation cannot deliver the correct object boundaries by itself; reliably finding them needs high-level knowledge of the likely objects. A common compromise is to over-segment into hundreds of small homogeneous superpixels, then hand off to knowledge-based algorithms that reason over superpixels rather than millions of raw pixels. Exploiting object knowledge is the subject of recognition, next.

Object recognition by appearance

Appearance is shorthand for what an object tends to look like. Some categories vary little in appearance (a baseball looks about the same under most circumstances); for those we can compute a set of features describing images likely to contain the object and test them with a classifier. Other categories — houses, ballet dancers — vary greatly, and a useful abstraction treats such objects as collections of local patterns that move around with respect to one another; we then find the object by looking at local histograms of detector responses that reveal whether a part is present while suppressing exactly where.

Sliding-window detection

The general method is to test each image window with a learned classifier. It works especially well for frontal faces: at low resolution and under reasonable lighting all such faces look similar — round, bright compared to the sunken eye sockets, with a dark slash for the mouth. Consider first faces where the nose is vertical. Sweep a round window of fixed size over the image, compute features for each placement, and present them to a classifier — the sliding window. To find faces at different sizes, repeat the sweep over larger and smaller scaled copies of the image; then postprocess the responses across scales and locations.

The appearance-recognition pipeline (a face detector). Slide a fixed-size window over scaled copies of the image; correct each window's illumination; a regressor estimates and corrects face orientation; features feed a classifier; non-maximum suppression merges overlapping detections into one.

Postprocessing matters because the chosen window size rarely matches a face exactly, so several overlapping windows each report a match. A classifier that reports a strength of response (logistic regression or a support vector machine) lets us combine nearby partial matches into one high-quality detection — non-maximum suppression. To handle rotated faces, add two steps: train a regressor to estimate the best orientation of any face in a window, reorient the window, then test for a vertical face. Features must be robust to shadows and illumination, so one strategy builds them from gradient orientations, another estimates and corrects the illumination per window. Training data is cheap: marked-up face sets exist, and slightly perturbing each example window (in orientation, center, or scale) manufactures more. Frontal face detectors built this way now run in inexpensive cameras.

Features: histograms of gradient orientation

Many objects show more complex patterns than faces because several effects move features around: foreshortening (a slanted pattern is distorted), aspect (an object looks different from different directions — a doughnut is an oval from the side, an annulus from above), occlusion (parts hidden from some viewpoints, including self-occlusion), and deformation (internal degrees of freedom, as when a person moves their limbs). Still, the search across location and scale works, because some structure is preserved: a car image shows some arrangement of headlights, wheels, windows. This suggests modelling objects as collections of pattern elements — parts that may shift a little but appear roughly in place.

The obvious representation, a histogram of which pattern elements appear, throws away too much: the French, UK, and Netherlands flags have nearly identical color histograms though they arrange the same colors very differently. The representation must keep some spatial detail (headlights tend to be at the front, wheels at the bottom) while still summarizing.

Pedestrian detection is the canonical application: car accidents kill about 1.2 million people a year, roughly two thirds of them pedestrians, so a car that detects and avoids pedestrians could save many lives. At low resolution a walking pedestrian has a characteristic appearance — a lollipop (wide torso, legs together) or a scissor (legs mid-stride). Contrast against the background is often weak, so orientations beat edges; and because limbs swing, a histogram is used to suppress spatial detail. Break the window into overlapping cells and build an orientation histogram in each: the feature reports whether the head-and-shoulders curve sits at the top of the window without changing when the head shifts slightly.

One refinement remains. Because orientation features ignore brightness, the distinctive boundary curves of a pedestrian would otherwise count the same as fine clothing texture and drown in noise. Recover contrast by weighting each orientation vote by how strong its gradient is relative to others in the cell. Writing for the gradient magnitude at point and for the cell whose histogram we compute, a natural weight is

Gradients large relative to their neighbors get more weight. The resulting feature is the HOG feature (Histogram Of Gradient orientations). With it, a pedestrian detector is otherwise just a face detector: sweep a window, compute HOG, classify, apply non-maximum suppression. Similar constructions detect a wide variety of objects; an earlier relative, the SIFT feature (Scale-Invariant Feature Transform), matches distinctive keypoints between a model image and a test scene.

Modern object recognition has largely replaced these hand-built features. A convolutional neural network learns the whole feature hierarchy end-to-end from data, discovering edge, texture, part, and object detectors that a human once had to engineer — the same sliding sweep and score, but with trained rather than designed. The appearance pipeline above is the classical form of a computation that CNNs now perform implicitly, and it is worth understanding as the scaffold the learned version replaced.

So far every operation has run forward, from pixels toward a label — edges, texture, features, a category. But knowing that a patch of image is a face or a car does not tell an agent where that object sits in space, and an agent that must grasp or avoid it needs the geometry, not just the name. That is the inverse problem: rebuild the three-dimensional scene from its 2-D projection. This continues in Vision: Reconstructing the 3D World.

╌╌ END ╌╌