Skip to content
Free public beta until December 4, 2026: every course is open, no card needed. After that, the first chapter of each course stays free and full access is a one-time $39 ($19 for up to 100 founding members chosen for helpful feedback). Your progress is kept. How the beta works

Convolution and kernels, recalled

~13 min

Nearly every technique this course builds is a variation on one operation: sliding a small grid of numbers over an image and computing a weighted sum at every position. Smoothing an image before detecting a feature uses it. Computing an image gradient uses it. Even a CNN's own learned filters (Chapter 11) use it. digital-image-processing built this operation in full. This section restates it, plus its three most common weight grids, at the depth this course needs from Chapter 2 onward.

Here's how to get one output pixel using correlation. First, lay the kernel down. Center it on the matching input pixel. Next, multiply each kernel number by the image pixel sitting right under it. Then add up all those products. That sum is your answer.

Convolution does the same laying-down-and-multiplying. The only difference: you flip the kernel first, end-to-end and top-to-bottom. Suppose the kernel looks the same after that flip — a plain averaging grid, say. Then flipping changes nothing. But for a lopsided kernel, it does change the result.

Here's a point that causes real confusion later, so it's worth stating plainly. A deep learning library often calls something a "convolutional layer." But strictly speaking, it's running correlation as this section defines it. The kernel never actually gets flipped. In practice, nobody who builds these networks worries about this. The network learns whatever numbers work, no matter which operation trained them. Still, it's good to know the label and the math don't quite agree. It's the same mismatch as a library's .shape order not quite matching how a person reads a photo's size out loud.

Now, the three named kernels. Identity does nothing at all — it's just a sanity-check baseline. The box kernel averages a neighborhood's pixels, all weighted equally. It's cheap to compute, but a little blocky. The Gaussian kernel also averages the neighborhood. But it lets nearby pixels count more than far-away ones. It tapers off smoothly, instead of cutting off sharply at the window's edge. That's why a Gaussian blur looks soft and natural. A box blur, by contrast, can leave faint rectangular traces.

Take an image I and a small weight grid H (a kernel) of size (2a+1)\times(2b+1). The 2D discrete correlation computes one output value per position: center H on that position, multiply each kernel entry by the image value underneath it, and sum the results. (I \star H)(x,y) = \sum_{i=-a}^{a}\sum_{j=-b}^{b} I(x+i,\, y+j)\, H(i,j). Convolution, (I*H)(x,y), computes the identical kind of sum, but first reads the kernel flipped 180°: replace H(i,j) with H(-i,-j) in the formula above. For a kernel that is symmetric under that flip — the box and Gaussian kernels below both are — the two operations produce identical output. For one that isn't, like Chapter 3's Sobel/Prewitt kernels, they don't, and the distinction matters there.

This is also the point where mathematics and software vocabulary part ways. It's worth stating plainly, once: most deep-learning frameworks label their convolutional layers' operation "convolution," but they actually implement correlation. The kernel is not flipped before sliding it across the input. A learned filter's own values absorb whatever difference that would have made during training, so the distinction has no practical consequence for a trained network. Still, it is a real naming mismatch between the framework's vocabulary and the mathematical operation this section actually defines — not a property of convolution itself.

Three named kernels recur throughout this course. The identity kernel has a single 1 at its center and 0 elsewhere, so it leaves the image unchanged. The box kernel has every entry equal to 1/K^2 for a K\times K grid, normalized so its entries sum to 1. It replaces each pixel with the plain average of its neighborhood. The Gaussian kernel H(i,j) = \frac{1}{2\pi\sigma^2} e^{-(i^2+j^2)/(2\sigma^2)} weights the neighborhood's center most heavily, tapering off smoothly along a bell curve controlled by \sigma (sigma). That produces a smoother, more natural blur than a box kernel's sharp-edged average. That's why it's the default smoothing step before almost every technique in Chapters 3–5.

Quick review

Practice from earlier coursework, pulled in for this topic.

From Digital Image Processing

A plus-shaped kernel [[0,1,0],[1,1,1],[0,1,0]] slides over the window [[1,2,3],[4,5,6],[7,8,9]]. What correlation value does it produce?

Correct! 🎉 Not quite.

Right on try — credit. Right — the answer had already been shown, so no credit this time. Next try is worth Answer shown after three tries — this one no longer earns credit. You chose to see the answer — this one earns no credit.

Why

0(1)+1(2)+0(3)+1(4)+1(5)+1(6)+0(7)+1(8)+0(9) = 2+4+5+6+8 = 25.

Correct answer

Also accepted:

Why

Nine products this time -- sum them all.

From Digital Image Processing

The correlation and convolution formulas differ by...

Correct! 🎉 Not quite.

Right on try — credit. Right — the answer had already been shown, so no credit this time. Next try is worth Answer shown after three tries — this one no longer earns credit. You chose to see the answer — this one earns no credit.

Both formulas center the window at the same output position -- the center convention is identical.

Neither formula requires a square kernel.

Padding is an independent choice, unrelated to the correlation/convolution distinction.

Why

Correlation uses I(x+i,y+j) while convolution uses I(x-i,y-j) -- the two formulas differ by exactly one sign inside the image's index.

Compare which sign appears inside the image index in each formula.

Formula

2D Discrete Convolution and Correlation

also known as: the sliding-window sum, filtering an image by a kernel

Recalled from Digital Image Processing · 2D discrete convolution and correlation, defined — first taught there.

🔖

For an image I and a kernel H of size (2a+1)\times(2b+1), the 2D discrete correlation is (I \star H)(x,y) = \sum_{i=-a}^{a}\sum_{j=-b}^{b} I(x+i,\, y+j)\, H(i,j), and the 2D discrete convolution is (I * H)(x,y) = \sum_{i=-a}^{a}\sum_{j=-b}^{b} I(x-i,\, y-j)\, H(i,j). The two differ by exactly one sign inside the image's index — a 180° rotation of the kernel — and coincide whenever the kernel is symmetric under that rotation. Both are a weighted sum over a window of input pixels centered at (x,y), with H supplying the weights.

A normalized box kernel, smoothing a bright square

Step through the output grid one position at a time -- each output value is the plain average of the 3x3 neighborhood underneath the kernel, exactly the box-kernel formula above.

Loading interactive…

Worked example

Computing one correlation output by hand

  1. 1

    A 3\times3 window of image values is \begin{bmatrix}40&40&220\\40&220&220\\220&220&220\end{bmatrix}. The kernel is the normalized box kernel above, \tfrac19 at every entry. Compute the correlation output at this position. Multiply corresponding entries and sum. The \tfrac19 factor is the same at every entry, so pull it out and apply it once, to the raw sum.

  2. 2

    Raw sum: 40+40+220+40+220+220+220+220+220 = 1440. Multiply by \tfrac19: 1440/9 = 160. That's the plain average of those nine values — exactly the box kernel's own definition.

Loading interactive…

Worked example

Why a symmetric kernel makes convolution and correlation agree

  1. 1

    Using the identical window and kernel from the previous example: does switching from correlation to convolution — flipping the kernel 180° before sliding it — change the 160 computed above? Flip the box kernel's 3\times3 grid of identical \tfrac19 entries 180° and compare it to the original.

  2. 2

    No. Every entry of the box kernel is the same value, \tfrac19. So flipping the grid 180° produces the exact same grid back. Convolution and correlation compute identical sums for this kernel. That matches this section's own claim: a flip-symmetric kernel erases the distinction between the two operations.

Loading interactive…

Where this goes next

Feature detection and CNN filters

Chapter 4 builds Harris corner detection directly on this section's Gaussian kernel. Smoothing an image first, before measuring how its brightness changes, is a standard step. Nearly every classical feature detector does it. Chapter 11 later reuses the identical sliding-window math for a CNN's own convolutional layer. Only one thing changes: an engineer no longer picks the kernel's numbers by hand (identity, box, Gaussian). Instead, the network learns them from training data. The formula itself doesn't change at all. Only where the numbers come from is different.

Check your understanding (counts toward your progress)

Which named kernel weights the center of its neighborhood most heavily and tapers off smoothly toward the edges?

Correct! 🎉 Not quite.

Right on try — credit. Right — the answer had already been shown, so no credit this time. Next try is worth Answer shown after three tries — this one no longer earns credit. You chose to see the answer — this one earns no credit.

The identity kernel has a single 1 at its center and 0 everywhere else -- it doesn't average or taper at all, it just copies the pixel underneath.

The box kernel weights every entry in its window EQUALLY -- it's the Gaussian kernel that weights the center more heavily.

The box kernel is the one that weights every entry equally -- the Gaussian kernel is the exception, tapering by a bell curve.

Why

The Gaussian kernel's bell-curve weighting favors the center and tapers smoothly, unlike the box kernel's uniform weights.

For which kind of kernel do convolution and correlation always produce the identical output?

Correct! 🎉 Not quite.

Right on try — credit. Right — the answer had already been shown, so no credit this time. Next try is worth Answer shown after three tries — this one no longer earns credit. You chose to see the answer — this one earns no credit.

A lopsided kernel like Sobel's genuinely gives different results under the two operations -- they don't always agree.

Having a negative entry says nothing about whether the kernel looks the same after a 180-degree flip.

Any kernel that looks identical after flipping 180 degrees works, not just the identity kernel -- a uniform box kernel is a second example.

Why

Flipping a kernel 180 degrees only changes anything if the flip actually rearranges its entries -- a flip-symmetric kernel (identity, box, Gaussian) looks the same either way.

A deep learning framework's "convolutional layer" is, strictly speaking, usually computing...

Correct! 🎉 Not quite.

Right on try — credit. Right — the answer had already been shown, so no credit this time. Next try is worth Answer shown after three tries — this one no longer earns credit. You chose to see the answer — this one earns no credit.

Most frameworks skip the 180-degree flip entirely, despite the "convolutional" name -- that flip is what would make it true convolution.

A framework layer computing convolution with the kernel unflipped is, by this section's own definition, actually correlation.

The layer computes a real weighted-sum operation over a learned kernel -- it just isn't the operation its own name suggests.

Why

Most deep-learning frameworks slide the kernel across the input without flipping it first -- correlation by this section's definition, despite the "convolution" label.

A 3\times3 window is \begin{bmatrix}10&10&10\\10&10&10\\10&10&10\end{bmatrix}. Using the normalized 3\times3 box kernel, what is the correlation output, and does convolution (kernel flipped) give a different number for this specific window?

Correct! 🎉 Not quite.

Right on try — credit. Right — the answer had already been shown, so no credit this time. Next try is worth Answer shown after three tries — this one no longer earns credit. You chose to see the answer — this one earns no credit.

Why

The raw sum is 90, divided by 9 gives 10 -- and since every window and kernel entry is identical either way, flipping the box kernel changes nothing here; convolution gives the same 10.

Correct answer

Also accepted:

Why

To compute one output value by 2D correlation, the kernel is...

Correct! 🎉 Not quite.

Right on try — credit. Right — the answer had already been shown, so no credit this time. Next try is worth Answer shown after three tries — this one no longer earns credit. You chose to see the answer — this one earns no credit.

Flipping the kernel 180 degrees first is what CONVOLUTION does -- correlation reads the kernel exactly as written.

Every position under the kernel's window contributes, not just the corners of the whole image.

Each output position is computed independently from the image and kernel -- it never depends on a previously computed output value.

Why

Correlation slides the kernel across the image and reads it in its original orientation; convolution is the one that flips it first.

Explain why the correlation/convolution naming mismatch in deep-learning frameworks has no practical effect on a trained network's accuracy.

Practice: Correlation, convolution, and the three named kernels (4 problems · doesn’t affect your progress)

In your own words, what's the one-step difference between how correlation and convolution treat the kernel?

A 3\times3 window has every entry equal to 80. What does correlating it with the identity kernel give?

Correct! 🎉 Not quite.

Right on try — credit. Right — the answer had already been shown, so no credit this time. Next try is worth Answer shown after three tries — this one no longer earns credit. You chose to see the answer — this one earns no credit.

Why

The identity kernel copies only the center pixel through unchanged -- 80.

Correct answer

Also accepted:

Why

80

A 3\times3 window has every entry equal to 60. What does correlating it with the normalized box kernel give?

Correct! 🎉 Not quite.

Right on try — credit. Right — the answer had already been shown, so no credit this time. Next try is worth Answer shown after three tries — this one no longer earns credit. You chose to see the answer — this one earns no credit.

Why

Averaging nine identical values of 60 still gives 60.

Correct answer

Also accepted:

Why

60

For a lopsided (non-symmetric) kernel like Sobel's, why do correlation and convolution generally give different numeric outputs?

Correct! 🎉 Not quite.

Right on try — credit. Right — the answer had already been shown, so no credit this time. Next try is worth Answer shown after three tries — this one no longer earns credit. You chose to see the answer — this one earns no credit.

Why

A 180-degree flip only leaves a kernel unchanged if it was already symmetric under that flip -- Sobel's kernel is not, so flipping it produces a genuinely different set of weights.

flipping a non-symmetric kernel genuinely rearranges its entries into a different pattern

Feeling good about this section?

Take the section quiz

Every answer gets a full explanation at the end.

Graph settings

Calculator

Sign in to save highlights

Insert an equation

  • No matches.