A photograph looks like a moment frozen in time, but to a camera or phone it is really a giant table of numbers. Lens settings follow geometric formulas, colours are stored as binary numbers, and every filter in a photo-editing app is a mathematical operation. Let us open up the camera and look at the calculations inside.
An Image Is a Matrix of Numbers
A digital image is a grid of tiny squares called pixels (short for "picture elements"). Each pixel stores numbers describing its colour. In mathematics, a grid of numbers arranged in rows and columns is called a matrix, so every digital photo is literally a matrix.
The resolution is the number of pixels: width × height. A camera producing images 4000 pixels wide and 3000 pixels tall captures
$$ 4000 \times 3000 = 12{,}000{,}000 \text{ pixels} = 12 \text{ megapixels (MP)} $$
The ratio \(4000 : 3000 = 4 : 3\) is the aspect ratio, common in phone cameras. Widescreen video uses 16 : 9, for example \(1920 \times 1080\).
Colour Depth and Binary
Most images use the RGB model: each pixel mixes Red, Green and Blue light. Each channel is stored with a certain number of bits. With 8 bits per channel, each colour can take \(2^8 = 256\) levels, from 0 (none) to 255 (full brightness). The total number of colours is:
$$ 256 \times 256 \times 256 = 2^{24} = 16{,}777{,}216 $$
This "24-bit colour" gives nearly 16.8 million colours, more than the human eye can distinguish in most situations. Professional cameras store RAW files with 12 or 14 bits per channel; 12 bits gives \(2^{12} = 4096\) levels per channel, which is why RAW files can be edited heavily without the colours breaking into visible bands.
Worked Example 1: File Size and Print Size
(a) How much memory does an uncompressed 12 MP image with 24-bit colour need?
Step 1: Bits per pixel. 24 bits = 3 bytes.
Step 2: Multiply by the number of pixels.
$$ 12{,}000{,}000 \times 3 = 36{,}000{,}000 \text{ bytes} = 36 \text{ MB} $$
Sanity check: a typical 12 MP JPEG from a phone is only 3 to 5 MB, roughly a tenth of this. That gap is the work done by compression, explained below.
(b) A 24 MP camera produces 6000 × 4000 pixel images. How large can you print one at 300 dots per inch (dpi), the standard for sharp photo prints?
Step 1: Width. \(6000 \div 300 = 20\) inches.
Step 2: Height. \(4000 \div 300 \approx 13.3\) inches.
So the photo prints sharply at about 20 × 13.3 inches (roughly 51 × 34 cm). Printing larger means fewer dots per inch, and the image starts to look soft from close up.
The Geometry of Lenses: Focal Length and f-Numbers
A lens bends light to form an image. Its focal length \(f\) (in millimetres) controls how "zoomed in" the picture is. The opening that lets light in is the aperture, with diameter \(D\). Photographers describe it using the f-number:
$$ N = \frac{f}{D} $$
A 50 mm lens at f/2 has an aperture diameter of \(50 \div 2 = 25\) mm. The amount of light passing through depends on the aperture's area, which is proportional to \(D^2\), so the light is proportional to \(\dfrac{1}{N^2}\).
This explains the strange-looking f-stop sequence on cameras:
f/1.4, f/2, f/2.8, f/4, f/5.6, f/8, f/11, f/16
Each number is the previous one multiplied by \(\sqrt{2} \approx 1.414\). Multiplying \(N\) by \(\sqrt{2}\) multiplies \(N^2\) by 2, so each step lets in exactly half as much light. Photographers call each halving or doubling of light one stop.
Worked Example 2: Balancing Exposure
A photographer's correct exposure is f/4 at a shutter speed of \(\tfrac{1}{250}\) s. She wants more of the scene in focus, so she changes to f/5.6. What shutter speed keeps the same exposure?
Step 1: Compare the light through the two apertures.
$$ \frac{\text{light at f/5.6}}{\text{light at f/4}} = \left(\frac{4}{5.6}\right)^2 = \frac{16}{31.36} \approx 0.51 $$
So f/5.6 lets in about half the light (one stop less).
Step 2: Compensate with time. Exposure = light rate × time. To keep it constant, the shutter must stay open about twice as long:
$$ 2 \times \frac{1}{250} = \frac{1}{125}\ \text{s} $$
Step 3: Check. f/5.6 at \(\tfrac{1}{125}\) s: half the light for double the time gives the same total exposure. Correct.
Bonus: going from f/2.8 to f/5.6 is two stops, since \((5.6 / 2.8)^2 = 2^2 = 4\), so four times less light reaches the sensor.
Editing Photos With Arithmetic
Converting to black and white
To turn a colour pixel into grey, editors use a weighted average, because our eyes are most sensitive to green and least sensitive to blue:
$$ \text{Grey} = 0.299R + 0.587G + 0.114B $$
For a pixel with \((R, G, B) = (200, 100, 50)\):
$$ 0.299(200) + 0.587(100) + 0.114(50) = 59.8 + 58.7 + 5.7 = 124.2 \approx 124 $$
Note that the weights add up to 1, so pure white (255, 255, 255) stays at 255.
Blurring and sharpening with convolution
A blur filter replaces each pixel with the average of itself and its neighbours. Suppose a noisy bright pixel (200) sits among darker ones in this 3 × 3 block:
10, 20, 30 / 40, 200, 60 / 70, 80, 90
The sum is \(10+20+30+40+200+60+70+80+90 = 600\), and the average is \(600 \div 9 \approx 67\). The bright speck is smoothed to 67, blending with its surroundings. This sliding-window operation is called convolution. Sharpening uses a different set of weights that exaggerates differences between a pixel and its neighbours. Convolution is also the core operation in the neural networks that power face detection and "portrait mode".
Compression: How JPEG Shrinks Files
The JPEG standard, published in 1992, splits an image into 8 × 8 blocks and applies the discrete cosine transform (DCT), which rewrites each block as a sum of cosine wave patterns. Fine, high-frequency details that the eye barely notices are stored roughly or thrown away. This is how a 36 MB image becomes a 4 MB file with little visible change.
Did You Know?
- The first digital camera was built by Kodak engineer Steven Sasson in 1975; it recorded 0.01 MP black-and-white images onto cassette tape.
- The "rule of thirds" in composition and the golden ratio overlay in editing apps are both geometric guidelines for placing the subject.
- Night mode on phones takes many short exposures and averages them; averaging \(n\) frames reduces random noise by a factor of about \(\sqrt{n}\).
Key Takeaways
- A digital image is a matrix of pixels; 4000 × 3000 pixels make 12 megapixels.
- 8 bits per colour channel gives \(2^{24} \approx 16.8\) million colours.
- The f-number is \(N = f/D\), and light varies as \(1/N^2\), so each \(\sqrt{2}\) step halves the light.
- Exposure can be balanced by trading aperture against shutter time.
- Editing filters and JPEG compression rely on weighted averages, convolution and cosine transforms.
If matrices, exponents or physics optics problems are slowing you down, Amathify's experts and PhD scholars can help with step-by-step solutions and assignments; message us on WhatsApp or use the Ask a Question form.
Stuck on a problem or assignment?
Our experts and PhD scholars solve maths, physics and chemistry — step by step.