How a camera makes an image: lens, sensor, exposure, and the ISP pipeline
What the lens, the sensor, the exposure settings and the camera's built-in processing each do to the pixel values a model reads, and why the same scene gives different numbers on two cameras.
A camera makes an image in a fixed order: the lens bends light from the scene onto a sensor, the sensor counts that light at a grid of spots, and the camera's processing turns those counts into the JPEG file you load. Each step changes the numbers. Where the camera stands decides how big an object comes out, the exposure settings decide how grainy or blurred it is, and the processing decides its colors. A model only ever sees the result, so knowing what each step does tells you why a model trained on one camera can get worse on another.
Framing: resolution and field of view
Two numbers describe what a camera captures. Resolution is the number of pixels in the image: its height times its width. A 1920 by 1080 image has about two million pixels. Field of view is how much of the world the camera takes in. A wide view sees a whole room, and a narrow view sees a small slice of it.
The two are separate. Two cameras at the same spot with different fields of view record different scenes at the same resolution.

More pixels only help if the evidence made it into the frame. If the object is tiny, out of focus or outside the frame, adding pixels does nothing. Getting it big and sharp enough is a choice of camera position and lens, made when the photos are collected. More pixels also cost compute time, memory and storage. A good resolution is the smallest one that still shows the evidence clearly.
![]()
Aspect ratio and fitting a model's input size
Many models take a fixed input size such as 224 by 224, while a phone photo is often 1920 by 1080. Aspect ratio is width divided by height. A 1920 by 1080 image is 16:9, about 1.78, and a square is 1:1. It describes the shape of the frame, whatever the number of pixels.

Resize a 16:9 photo straight into a square and everything gets squeezed sideways. A resize function that takes only a target height and width does exactly this unless you check. Text leans and circles become ovals. Boxes change shape, masks distort, and points marked on a face drift off the features they marked. A model trained on stretched images also learns the wrong proportions.

There are three common ways to fit an image into a fixed size:
- stretch it, which distorts shapes but keeps the whole image
- center-crop to the target shape, then resize, which keeps shapes and cuts off the edges
- letterbox it: resize until the long side fits, then pad the short side with a plain color
Pick one on purpose, and apply the same change to the labels.

To letterbox an image into a square of side target, scale it by whichever ratio is smaller, so both sides fit:
def letterbox_size(w, h, target):
scale = min(target / w, target / h)
new_w = round(w * scale)
new_h = round(h * scale)
return new_w, new_h
new_w, new_h = letterbox_size(1920, 1080, 640)
print(new_w, new_h) # 640 360
print("padding rows:", 640 - new_h) # padding rows: 280
print("aspect ratio before:", round(1920 / 1080, 2), "after:", round(new_w / new_h, 2))
# aspect ratio before: 1.78 after: 1.78For a 1920 by 1080 photo and a 640 square, the two ratios are $640 / 1920 = 0.333$ and $640 / 1080 = 0.593$. The smaller one wins, so the image becomes 640 by 360. The remaining 280 rows are padding, 140 above and 140 below, and the aspect ratio stays 1.78. If boxes come out in the wrong place afterward, check that they were scaled by the same scale and shifted down by the 140 padding rows.

The pinhole camera: the simplest model
How big an object looks and how much of the scene fits in the frame are both decided before light reaches the sensor. The simplest model of how that happens is the pinhole camera: a sealed box with one tiny hole.
Each point in the scene sends light in all directions, and only the one ray that passes through the hole reaches the back wall. So each scene point hits exactly one point of the image, and the image comes out upside down.

Because every ray passes through the same hole, an object twice as far away makes an image on the back wall at half the size. That is why the two edges of a straight road seem to meet in the distance, and why a person far away is only a few pixels tall.

Perspective as similar triangles
Call the distance from the hole to the back wall $f$. A point at height $Y$ and distance $Z$ in front of the hole hits the wall at height $y'$:
$$y' = \frac{f \cdot Y}{Z}$$
The triangle in front of the hole and the one behind it have the same shape, so their ratios match: $y' / f = Y / Z$. Here is the same formula in code, for a person 1.8 meters tall and a box with $f = 0.05$ meters:
def project_y(Y, Z, f):
return f * Y / Z
f = 0.05 # hole-to-wall distance in meters
for Z in (10, 20, 40):
print(Z, round(project_y(1.8, Z, f), 6))
# 10 0.009
# 20 0.0045
# 40 0.00225At 10 meters the person is 9 millimeters tall on the wall. At 20 meters the image halves to 4.5 millimeters, and at 40 meters it halves again. Doubling the distance halves the size.

Why real cameras use lenses
A pinhole small enough for a sharp image lets in very little light, so a photo would take minutes. A lens gathers light through a wide opening and bends it into focus, which gives a bright and sharp image quickly.
A lens has a focal length, measured in millimeters, which plays the role of the hole-to-wall distance $f$. A short focal length gives a wide view. A long focal length gives a narrow view that magnifies a small slice of the scene.

A wide lens fits a whole room but makes each object small. A long lens fills the frame with one distant object and leaves out everything around it. So the lens decides what evidence is in the image at all.
How flat or deep a photo looks depends on where the camera stands, not on the lens. Long lenses are usually used from far away, which makes faces look flatter. Wide lenses are usually used up close, which makes whatever is nearest look larger.

Say a model's training photos came from one lens and the deployed camera uses another. Object sizes, perspective and sharpness all change, and the model can get worse for no reason other than the lens. When the images a model sees in use differ from the ones it was trained on, that is called domain shift. Lenses are one cause, and the sensor and the camera's processing add more.

The sensor turns light into numbers
The lens puts light in the right place, and the sensor turns it into numbers. A sensor is a grid of light-sensitive cells. Each cell counts the light that arrives while the photo is being taken and turns that count into a number. Measuring the light at a fixed grid of spots is where the pixel grid comes from.
Each cell has limits. Below a minimum amount of light it cannot tell the signal from nothing, so very dark scenes come out mostly as random speckle. Above a maximum it fills up and stops counting, which caps the bright end.

Exposure: aperture, shutter speed and ISO
Exposure is the total amount of light recorded for a photo. Too little gives a dark, grainy image. Too much turns the highlights pure white. Three settings control it:
- aperture sets how wide the lens opening is
- shutter speed sets how long the sensor collects light
- ISO amplifies the signal after it is collected, which brightens the image without adding any light

A wider aperture lets in more light, and it also narrows the band of distances that stays sharp. That band is the depth of field. With a wide aperture only a thin slice of the scene is in focus, and the background goes soft. A narrower aperture lets in less light and keeps more of the scene sharp.

A slow shutter collects more light, but anything that moves during that time smears across the image. A fast shutter freezes motion and collects less light. So a fast shutter needs something else to make up the light: a wider aperture, more light on the scene or a higher ISO.

ISO brightens a dark image without collecting more light. It amplifies the random speckle along with the signal, so high-ISO photos look grainy.

These settings end up in the dataset. Photos taken at high ISO in low light are grainy. Photos of moving subjects taken with a slow shutter are blurred. Photos taken with a wide aperture have soft backgrounds. A model trained on one kind and used on another inherits the difference. Knowing which setting caused a bad image tells you what would fix it: a different setting, a different lens, or nothing at all.

Noise, blur and lens distortion
Even a well-exposed photo carries errors that the camera added while capturing it.
Sensor noise
Take two photos of a still scene with identical settings, and they still differ pixel by pixel. That difference is noise: random variation added to the true signal during capture and processing.

Light arrives as separate particles called photons, at random times. So the count in a fixed exposure wobbles by about the square root of the count. A cell that collects 10,000 photons varies by about $\sqrt{10000} = 100$, which is 1 percent. A cell that collects 100 photons varies by about $\sqrt{100} = 10$, which is 10 percent. You can check this with simulated photon counts:
import torch
torch.manual_seed(0)
for mean_photons in (10_000.0, 100.0):
# 100,000 cells, each catching photons at random with the same average
counts = torch.poisson(torch.full((100_000,), mean_photons))
spread = counts.std().item()
print(f"average {mean_photons:>8.0f} wobble {spread:6.1f} relative {spread / mean_photons:.1%}")
# average 10000 wobble 100.1 relative 1.0%
# average 100 wobble 10.0 relative 10.0%torch.poisson draws random counts with a given average, which is how photon arrivals behave. The bright cells wobble by more photons in absolute terms, about 100 against 10. Compared with the signal, though, the dark cells wobble ten times as much. That is why dark images look noisier. This photon noise comes from light itself, so it sets a limit on how clean a dark image can be. The sensor's electronics and its heat add more noise on top.

Noise competes with real detail. Fine texture, thin edges, small distant objects and faint text can all sink below the noise and become impossible to recover. That is why photos taken in low light are hard for object detection and for reading text.

Blur
Blur spreads each scene point across several pixels instead of one. Defocus blur comes from a lens focused at the wrong distance. Motion blur comes from the camera or the subject moving while the shutter is open, and its streak follows the direction of motion.
Recognition, reading text and finding small objects all need sharp edges, so blur hurts all three. Motion blur also carries information. A streak shows that something moved and roughly which way, which video models can use.

Lens distortion and vignetting
Real lenses bend straight lines. With lens distortion, straight lines in the world come out curved in the image, bowing outward or inward more and more toward the edges. A door frame near the edge of a wide-angle shot looks bent, and the effect is strongest with wide-angle and cheap lenses. Lenses also make the corners darker than the center, even when the scene is evenly lit. That falloff is called vignetting.

Distortion moves pixels away from where the pinhole model puts them. Vignetting changes brightness near the corners. Both throw off measurements, and both make it harder to match the same point across two photos. Camera calibration measures a lens's distortion so the image can be straightened before any geometry runs.

The image signal processing pipeline
A JPEG from a phone is not what the sensor measured. Between the sensor and the file, the camera runs a chain of steps called the image signal processing pipeline (ISP), and the file holds the result of that chain.
The chain starts from the sensor's RAW output, one value per cell. The camera subtracts the value a cell reports in total darkness and amplifies the rest.
Demosaicing
Most sensors do not measure red, green and blue at every cell. A color filter sits over each cell in a repeating mosaic, usually the Bayer pattern: half green, a quarter red and a quarter blue. Each cell records only one of the three colors.
Demosaicing estimates the two missing colors at every pixel from the neighboring cells. The RGB image you load is that estimate. Poor demosaicing leaves colored fringes along edges.

Denoising and sharpening
Next the camera smooths out noise and boosts the contrast along edges. Both steps throw information away. Denoising can smear fine texture, and sharpening can add bright halos and make the remaining noise stronger.

White balance and tone mapping
White balance removes the color cast of the light, so white objects come out white. Tone mapping squeezes the sensor's wide range of brightness into 0 to 255, which decides how much detail is kept in the shadows and the highlights.

Compression and metadata
Last, the camera compresses the image, usually to JPEG. That throws away more detail. It also attaches metadata: extra information such as the orientation, the camera settings, a timestamp and sometimes the location.

Put together, the model sees the end of this chain, never the light itself:

Why two cameras give different pixels
Point two cameras at the same scene and their pixels differ, for three reasons stacked on top of each other:
- optics: focal length, distortion and vignetting
- sensor: sensitivity, noise and resolution
- processing: demosaicing and denoising, then sharpening and white balance, then tone mapping and compression
A model trained on one camera sees colors, noise and sharpness it never learned when it runs on another. Before trusting the results, test on photos from the cameras the model will run on.

Common mistakes
- Resizing without checking the aspect ratio. A plain resize to 224 by 224 stretches a 16:9 photo. Choose stretch, crop or letterbox on purpose and move the labels with it.
- Buying resolution to fix a framing problem. If the object is tiny or outside the frame, more pixels do not help. Move the camera or change the lens.
- Training on one camera and deploying on another. Lens, sensor and processing all change the pixels. Test on images from the deployment camera before trusting the accuracy.
- Treating noise and blur as model problems. Grain from high ISO and smears from a slow shutter come from the capture settings. Changing the settings fixes them at the source.
- Measuring on distorted images. Distances and point matches drift near the edges of a wide-angle shot. Calibrate the camera and straighten the image first.
- Assuming the JPEG is the raw measurement. Every step of the processing chain has changed it, from demosaicing to compression.
Related concepts
What is computer vision? shows why images are measurements and why the same object can produce very different numbers. How images are stored as tensors covers what you get after loading the camera's JPEG. Image normalization for deep learning covers bit depth, clipping and the histogram view of exposure.
QuiddityML teaches how a camera forms an image in the images-as-data unit of its Computer Vision track, from framing and the pinhole model to the camera's processing pipeline. Learners there write letterbox_size from scratch, turn the projection formula into project_y, and put the camera's processing steps in order from sensor to stored file (QuiddityML).