A person tells a cat from a human at a glance, but what a computer receives is a table packed with numbers from 0 to 255. We follow how a photo becomes a matrix down to a single pixel, see why pixel distance can’t measure “resemblance,” and then compute by hand a convolution that finds edges with a 3 × 3 filter. Finally, we look at the strengths and limits of hand-designed features (face boxes, landmarks, edge strength).
Pointy ears and fur versus smooth skin. A person tells them apart at a glance. What does a computer receive this photo as, and which clues can it find first?
The red lines on the cat at left are a facial skeleton connecting the forehead, eyes, and nose. The green box on the person at right is a detection result saying “there is a face here,” the red dots are landmarks along the jawline, eyebrows, and lips, and the pink dots mark the key positions of the two eyes, nose, and mouth. All of these are clues for which a person decided in advance “what to look at.”
This episode looks at two things. First, what a computer receives is not lines and dots like these but a matrix of numbers (Sections 2–3). Second, filters that find clues like edges in those numbers, and the limits of clues chosen by people (Sections 4–6).
For the number examples, the whole series follows the same single chihuahua photo (the star of 4-4). That’s because pixels and filters work the same way on any photo. In the hands-on activities, you can choose any of the five photos: cat, human, dog, chihuahua, and muffin.
A problem that is easy for people isn’t necessarily easy for a computer. A person notices “it has fur” and “its ears are pointy” the moment they see a photo, but a computer has to compute each of those clues from numbers, one by one. In cat vs human, those clues are fairly clear, which makes it a good first exercise in image classification.
A photo is a grid of numbers, and a color photo is three such grids stacked together. The smallest unit a model takes as input is a single channel value (0–255).
A digital photo is a collection of tiny cells, finely divided across and down. Each of these cells is called a pixel (picture element). A pixel holds just one color, and that color is written as three intensities of red (R), green (G), and blue (B) light. Each intensity is an integer from 0 (no light) to 255 (brightest). So a color photo becomes a table of height × width × 3 numbers, that is, a matrix (strictly speaking, a three-layer tensor).
Put simplyIt’s like coloring in graph paper. If you write down, from 0 to 255, how many drops from each of three paint pots (red, green, blue) went into each square, anyone can repaint the same picture from that note alone. What the computer has is not the picture but this note.
Keep breaking a photo down and you reach one pixel, the R, G, B numbers inside it, and the eight bits that make up one number. A bit is the smallest unit a computer stores, but a single bit is neither color nor brightness, just on or off.
So in image deep learning, the smallest piece of information with meaning is a single channel value: a number like “the red intensity of this cell is 39.” The model’s first layer takes exactly these numbers (X[y, x, c]) as input.
But this single number carries no meaning of “chihuahua” at all. An eye pixel (39, 37, 43) and a blueberry pixel (37, 31, 37) are almost the same as numbers. Meaning comes from how many pixels are grouped together, and finding those groupings is the feature extraction of Section 4.
This shows the chihuahua photo cut into 14 cells across and down, with one eye cell picked and turned into numbers. The numbers on the right are computed from the photo’s actual pixels.
Choose a photo and a resolution, then click a cell in the picture or hover over it. The table beside it (below it on mobile) shows the actual numbers of the chosen cell and its surrounding 7 × 7 cells. After clicking the picture, you can move between cells with the arrow keys.
Q1. How many numbers are in a color photo that is 10 cells wide and 10 cells tall?
Q2. What color is the pixel value (R, G, B) = (0, 0, 0)?
Q3. If you shift the same photo two cells to the right, what happens to the numbers at the same positions?
Q4. What is the smallest piece of information an image deep learning model takes as input?
A pixel is a small cell that makes up a photo, and each cell records the intensities of red, green, and blue light as numbers from 0 to 255. Compared with the table in 4-1, one photo is a single row of “height × width × 3” cells. Click cells in the Pixel Magnifier to check the actual numbers, and change the resolution to see how the count of numbers changes.
If you measure distance by subtracting the numbers at the same positions in two photos, can you measure “resemblance”? We shift or darken the same chihuahua and measure the distances among all five photos.
The pixel distance between two photos is found by subtracting the grayscale numbers at the same positions, squaring, averaging, and taking the square root (0 means identical). Try shifting the chihuahua sideways or darkening it. To the human eye it’s still the same chihuahua, but in numbers it can become a photo farther away than the muffin.
We measured the pixel distance between every pair of the five photos on this page. The smaller the number, the more “alike” they were computed to be. The smallest value is highlighted.
The values in this table were measured on the five photos on this page (cropped to the face and reduced to 56 × 56). With other photos, the values vary greatly with background, lighting, and framing, but the conclusion that “pixel distance differs from distance in meaning” is a well-known property of real photos too.
Code 1 runs the same experiment on the face regions of a cat photo (chelsea) and a human photo (astronaut) included in scikit-image, reduced to 56 × 56. Shifting the same cat by 1 cell raised the distance to 16.9, by 2 cells to 27.1, and by 8 cells to 40.5, while the distance between the cat and the human was 85.3. Shifting by just a few cells gets you close to half the distance to a different animal.
Pixel distance only measures “whether the numbers at the same positions are similar.” So it is sensitive to position, brightness, and framing, and it knows nothing about what is in the picture. This limitation is why we need the filters of Section 4 and the CNN of 4-3.
The k-NN in 4-1 asked its “nearest neighbors.” To do the same with photos, the distance between photos has to reflect meaning. But by pixel distance, the chihuahua is closer to the muffin than to a fellow dog (the golden retriever), and the same chihuahua shifted by just 4 cells ends up farther away than the muffin. This means you shouldn’t find neighbors using raw pixel distance between photos.
Slide a 3 × 3 table of numbers (a filter) across the photo, multiplying and adding. Places that resemble the pattern give large numbers, and collecting those results gives a feature map.
A feature is a pattern made by many pixels together, such as “bright here, then suddenly dark (an edge),” “a round spot darker than its surroundings (a spot),” or “dense thin lines (fur texture).” A CNN places a small table of numbers such as 3 × 3, called a filter (kernel), on the photo and slides it one cell at a time, multiplying the overlapping numbers and adding them all up. Places that resemble the filter’s pattern produce large numbers, other places produce small ones, and the new matrix collecting these results is a feature map. This calculation is called convolution.
Put simplyIt’s a game of matching a pattern stamp. Press a stamp carved with a “dark on the left, bright on the right” pattern at every spot on the photo, and write a high score wherever the pattern lines up well. Once the score sheet is full, you can see at a glance where the vertical edges are in the photo. Change the stamp, and the pattern you’re looking for changes too.
A filter is the “pattern you want to find” written down as numbers. A filter whose left column is −1 and right column is +1 produces larger numbers the brighter the right side is compared with the left. That’s why the vertical edge between the chihuahua’s eye (dark) and fur (bright) gives a large value like 302, while a flat area of fur gives a value close to 0.
The key point is that the same filter is reused at every position in the photo. A single filter has only 9 numbers, yet it finds edges anywhere in the photo. It also eases the problem from Section 3, where “shifting by one cell changes every number.” When the photo shifts, the feature map just shifts along with it; the fact that an edge is there stays the same.
The first layer of a real CNN uses dozens of filters like this. Each filter produces one feature map, so the output becomes a thick matrix of “photo size × number of filters.”
We place a vertical edge filter, one cell at a time, on an 8 × 8 grayscale patch near the chihuahua’s eye (cut from the photo reduced to 28 × 28). Blue numbers mean “the right is brighter,” and orange numbers mean “the left is brighter.”
Choose a photo and a filter. You can also edit the numbers in the filter cells directly. Bright areas in the feature map on the right are “where the pattern was found.” Click a cell in the feature map to see the calculation for that position below. To keep the output at 56 × 56, the area outside the edges is filled by copying the nearest edge pixel. This differs from the zero padding in Diagram 3, so values in the border cells may differ from what zero padding would give.
Q1. In convolution, how is the value at one filter position computed?
Q2. What do you get when you apply the vertical edge filter [−1 0 1]×3 to a flat patch where every cell is 10?
Q3. What size do you get after applying 2 × 2 max pooling to a 56 × 56 feature map?
Q4. Who decides the numbers in a CNN’s filters?
Convolution repeats the weighted sum of the 4-1 perceptron (w·x + b) on every small patch of a photo. The 9 numbers in the filter are the weights, and because the same filter is reused at every position in the photo, an eye is found the same way no matter where it is. In Code 2, you check that the hand calculation matches scipy’s result, and you see that when handwritten digits are shifted by 2 pixels, a neural network that uses the raw pixels collapses to 14.2% while a small CNN holds on at 90.4%.
Before deep learning, people decided “what to measure.” Here we look at the strengths of that approach and at its limit: change the photo, and the judgment flips.
Before deep learning, face recognition relied on human-chosen features. In 2001, Viola and Jones found face boxes in photos by rapidly computing thousands of simple rectangular features (Haar features) that measure brightness differences such as “the eye region is darker than the cheeks” [R4]. In 2005, HOG found the outlines of people by counting edge directions in each small cell [R5]. Facial landmarks, which locate the corners of the eyes, the tip of the nose and the jawline like the red dots in the Section 1 image, are then computed inside the face box found this way [R6].
These methods are fast and easy to explain, but a person has to know in advance what to measure, and they struggled with lighting, angle and occlusion. CNNs overcame this limit by learning the same kind of filters from data [R7].
The image from Section 1. The green box is the detection result (“there is a face here”), the red dots are facial landmarks around the jawline, eyebrows and lips, and the pink dots mark the key positions of the two eyes, nose and mouth. The red lines on the cat form a facial skeleton linking the forehead, eyes and nose.
A person decides first what to measure, such as “the distance between the eyes” or “the angle of the ear tips.”
The filter numbers K start out random, and training adjusts them toward the correct answer.
Switch to the “Edge strength” view. Interestingly, the average edge strength over the whole photo is almost the same for both. That’s because the human photo also has many fine lines in the long hair. The difference is where the edges are. The cat has fur texture and stripes packed right into the middle of its face, while the human has smooth cheeks and forehead, so the edges gather at the eyes, nose, mouth and hair. The “center region” value below shows this difference. This is why we need a map by location, that is, a feature map, rather than a single average number.
Part features at around layer 3 also clearly separate them. Pointed triangular ears on top of the head, stripes on the forehead, a small pink nose and long whiskers don’t exist on a human face. The red lines and dots in the Section 1 image are a way for people to specify such clues by hand; a CNN finds the same clues on its own with filters.
In the table in Section 3, the grayscale pixel distance between cat and human is about the same as the distance between cat and dog. For people, this is the easiest matchup, yet pixel distance doesn’t reveal the difference. It’s one more piece of evidence that pixel distance doesn’t know meaning.
In the pair comparison above, using this page’s photos, the cat had the larger central edge strength. But when you measure it in Code 1 with the cat and human photos from scikit-image, it comes out the other way around (edge strength in the face area: cat 101.5, human 123.6). That’s because the hair and the teeth of the smiling mouth in the human photo create strong edges.
A single human-chosen feature like “lots of edges means cat” flips easily when the photo changes. So we need a combination of many features rather than just one, and a method that learns that combination from data. That is the topic of 4-3.
Human-chosen features make it easy to explain “why the decision was made,” and they work even with little data. On the other hand, people have to know in advance what to look for, and they break down easily when the photo conditions change. In the pair comparison, switch to the “Edge strength” view and compare where the edges gather for the cat and the human.
First-layer filters find lines and edges. Stack layers, and lines combine into corners, corners into eyes and ears, and eyes and ears into a face.
When you stack layers while shrinking the photo with pooling, one cell in a deeper layer sees a wider area of the original photo. So early layers find small lines, deeper layers find eyes and ears, which are combinations of lines, and even deeper layers find the whole face. This figure is a simplified rendering of the tendency Zeiler and Fergus (2014) showed by visualizing the layer-by-layer responses of a trained CNN.
When you stack layers while shrinking the photo with pooling, one cell in a deeper layer sees a wider area of the original photo. So early layers find small lines, and deeper layers find combinations of those lines [R8]. In 4-3, we’ll see how a CNN built by stacking these layers produces probabilities, and why stacking layers separates what a single plane couldn’t.
Both code samples use only libraries that come preinstalled in Colab and built-in data. Click “Download notebook (.ipynb)” and open it in Colab with File → Upload notebook, or copy the code and paste it into a new notebook cell.
Looks at the shape and pixel values of the cat and human photos included in scikit-image, and computes grayscale luminance, pixel distance and edge strength. To use your own data, read your photo with io.imread and change the (top, left, side) in small() to the position of the face.
Computes a convolution with a 3 × 3 vertical edge filter by hand and checks it against scipy, then compares an MLP and a small CNN on test images of handwritten digits shifted by 1–2 pixels.
These are prompts to paste into an AI assistant such as ChatGPT, Qwen, or Claude. Click “Copy” and the code you selected is attached after the prompt. Replace the text inside 〔 〕 with your own situation.
An AI’s answer is only a starting point. Always check any papers, figures, or library functions it suggests against the originals and the official documentation. If you used AI help for a competition entry or a paper, disclose that you did and to what extent, following the rules of the organizers or the journal.
This is the same dictionary as the yellow dotted underlines in the text. The same terms are used throughout the series. Click a section name to jump to where the term first appears.
Analogies are a first step toward understanding, but they can also plant misunderstandings. Analogies to the human eye and brain are marked by strength. Direct There is evidence that it actually does the same thing · Partial Only some properties are similar · None No known counterpart
| Concept | Everyday analogy | Human eye/brain analogy | Where the analogy breaks down |
|---|---|---|---|
| Pixel | A single mosaic tile | Partial The retina of the eye also has densely packed light-sensing cells | Retinal cells aren’t laid out evenly in a grid; they are concentrated in the center (the fovea), and the kinds and proportions of color cells differ |
| Convolution filter | A stamp carved with a pattern | Partial Simple cells in the visual cortex respond strongly to edges in a particular direction | Brain cells have far more complex learning and wiring. A CNN filter reuses the same numbers at every position, but the brain doesn’t |
| Feature map | The X on a treasure map | None | A map is a single sheet, but a real layer has as many feature maps stacked up as it has filters |
| Pooling | Picking a class representative | None | Class representatives are chosen by people, but max pooling mechanically picks the cell with the largest number |
| Facial landmarks | Signposts on a map | None | Signposts are put up by people, but landmark positions are computed by a trained model for each photo. If part of the face is covered, they land in the wrong spot |
E-1 About the Author · E-2 Academic References · E-3 Figure and Data Sources
A guide for instructors, on-the-job training (OJT) leads, and tutors. Times are estimates, so adjust them to your actual class.
| Audience | College students and working professionals who have finished 4-1. Practitioners who want to know “how image AI receives a photo” |
|---|---|
| Prerequisites | Features, targets and weighted sums from 4-1; multiplication and addition |
| Learning Goals | ① Calculate the shape of a color photo (H × W × 3) and how many numbers it contains ② Compute one 3 × 3 convolution cell by hand ③ Explain the limits of pixel distance and human-chosen features with examples |
| Estimated Time | Reading 40–50 min · hands-on demo 25 min · Colab practice 25 min (Code 1: 10 min; Code 2: 1 min to run + 14 min to interpret) |
Intro 5 min (Section 1) → Section 2 Pixel Magnifier 15 min → Section 3 shift experiment 10 min → Section 4 convolution by hand 15 min → Check Questions 5 min.
Use Section 2 to calculate the resolution and number count of photos from your own work (defective products, scanned documents, etc.) 20 min → find filters that suit your photos in the Section 4 Filter Lab 25 min → discuss the limits of human-chosen features from Section 5 15 min → run and interpret Code 2 30 min.
Beginners: Sections 1, 2 and 4 only. Have intermediate learners redo the output-size formula in Section 4 with padding and stride, and predict how robustness to shifts changes if GlobalMaxPooling is replaced with Flatten in the Code 2 CNN.
| Section | Questions to pause and ask | Interaction tips |
|---|---|---|
| 1 Problem | “What do people look at to know it’s a cat?” | Point out that the lines and dots are clues chosen by people |
| 2 Pixels | “What are the three numbers in the eye cell?” | Change the resolution in the Pixel Magnifier from 7 → 56 |
| 3 Pixel distance | “It’s the same chihuahua, so why is it farther than the muffin?” | Move the shift slider to 4 pixels or more |
| 4 Convolution | “What happens if you stamp a vertical edge filter on a flat patch of fur?” | Pause the animation at “Add them all” and check it by hand |
| 5 Human-chosen features | Is “lots of edges means cat” always true? | Look at the edge-strength view in the pair comparison together with the Code 1 results |
| 6 Deeper layers | “Which layer holds the filter that finds eyes?” | Walk through the layer-by-layer figure from left to right |
| Misconception | Correct explanation | Scene to show |
|---|---|---|
| A photo is a picture file, so it’s different from numbers | To a computer, a photo is H × W × 3 numbers from 0 to 255 | Section 2 Pixel Magnifier |
| Similar pixels mean the same thing was photographed | Shifting by just one pixel changes the distance a lot. Pixel distance doesn’t know meaning | Section 3 shift experiment |
| Convolution is complicated math | It just multiplies 9 overlapping pairs and adds them up. Same as the perceptron’s weighted sum | Number example in Section 4 |
| Filters are designed by people | The filters in the hands-on activity are examples. A CNN learns the filter numbers from data | Section 4 Check Question Q4 |
| Human-chosen features are useless | They’re easy to explain and need little data. But they’re weak when conditions change | Section 5 and the flipped result in Code 1 |
Color: 56 × 56 × 3 = 9,408; grayscale: 56 × 56 = 3,136.
0.299×39 + 0.587×37 + 0.114×43 = 11.661 + 21.719 + 4.902 ≈ 38.3.
(174−92) + (137−38) + (176−55) = 82 + 99 + 121 = 302. A strong edge, brighter on the right.
56 − 3 + 1 = 54, i.e., 54 × 54. With padding 1, it stays 56 × 56.
Convolution, which reuses the same filter at every position (finding the same pattern even when its position changes), and global max pooling, which throws away position and keeps only the largest response.
In Code 1, read a photo of your own face (or your pet), print its shape and number count, and make a table of pixel distances for shifts of 1, 2 and 4 pixels.
In the Code 2 CNN, replace GlobalMaxPooling2D with Flatten, retrain, and report the change in accuracy on photos shifted by 1 and 2 pixels using 3 seeds. Explain why, linking it to the interpretation in Section 4.
| Beginners | You can skip the distance table in Section 3 and Section 6. Just make sure to do the hands-on activities in Sections 2 and 4 |
|---|---|
| Advanced | Have them research Haar features and HOG, then build similar filters in the Section 4 Filter Lab. Check the papers they research in the original |
| Learn more | 3-3 Images and CNNs · 4-3 Cat vs Dog (overall CNN structure) |
| Instructor materials | Grading criteria for the Check Questions and sample answers for the assignments are on the answer page for educators (4-2) |
You’ve read “4-2 Cat vs Human” all the way through. The lab crew will each sum it up in a word.