2:29

And convolve it with the 3 x 3 filter.

Â One slightly unfortunate thing about the notation is that in mathematics,

Â the asterisk is the standard symbol for convolution.

Â But in Python, this is also used to denote multiplication or

Â maybe element-wise multiplication.

Â So this asterisk has dual purposes, it's overloaded notation.

Â But I'll try to be clear in these videos when this asterisk refers to convolution.

Â And the output of this convolution operator will be a 4 x 4 matrix,

Â which you can interpret and which you can think of as a 4 x 4 image.

Â And the way you compute this 4 x 4 output is as follows.

Â To compute the first element, the upper left element of this 4 x 4 matrix,

Â what you're going to do is take the 3 x 3 filter and

Â paste it on top of the 3 x 3 region of your original input image.

Â So I've written here 1 1 1,

Â 0 0 0, -1 -1 -1.

Â And what you should do is take the element-wise products.

Â So the first one would be 3 x 1.

Â And then the second one would be 1 x 1, bring down here, 1 x 1.

Â And then + 2 x 1, this one.

Â And then add up all of the resulting nine numbers.

Â So then the middle column gives you 0 x 0 + 5 x 0 + 7 x 0.

Â And then the rightmost column gives 1 x -1,

Â 8 x -1 + 2 x -1.

Â And adding up these nine numbers will give you -5.

Â And so I'm going to fill in -5 over here.

Â Okay, and you can add up these nine numbers in any order, of course.

Â It's just that I went down the first column,

Â then the second column, then the third.

Â Next, to figure out what is this second element,

Â you're going to take the blue square and shift it one step to the right, like so.

Â And let me get rid of the green marks here.

Â And you're going to do the same element-wise product and then addition.

Â So you have 0 x 1, + 5 x 1, + 7 x 1,

Â + 1 x 0, + 8 x 0, + 2 x 0,

Â + 2 x -1, + 9 x -1, + 5 x -1.

Â And if you add up those nine numbers, you end up with -4, and so on.

Â If you shift this to the right, do the nine products and add them up, you get 0.

Â And then over here, you should get 8.

Â And just to verify, you have 2 + 9 + 5, that's 16.

Â Then the middle column gives you 0.

Â And then the rightmost column 4 + 1 + 3 x -1, that's -8.

Â So that's 16 on the left column, -8, and

Â that gives you 8, like we have over here.

Â Next, in order to get you this element in the next row,

Â what you do is take the blue square and now shift it one down.

Â So you now have it in that position.

Â And again, repeat the element-wise product and then adding exercise.

Â And if you do that, you should get -10 here.

Â 6:44

But the matrix on the left is convenient to interpret as an image.

Â And the one in the middle, we interpret as a filter.

Â And the one on the right, we can interpret that as maybe another image.

Â And this turns out to be a vertical edge detector.

Â And you see why on the next slide.

Â Before going on, though, just one other comment.

Â Which is that if you implement this in a programming language, then in practice,

Â most programming languages will have some different function

Â rather than an asterisk to denote convolution.

Â So, for example, in the programming exercise, you use or

Â you implement a function called conv_forward.

Â If you do this in tensorflow,

Â there's a function tf.nn.conv2d.

Â And then other deep learning programming frameworks.

Â In the Keras programming framework, which you'll see later in this course,

Â there's a function called Conv2D that implements convolution, and so on.

Â But all the deep learning frameworks that have good support for

Â convolution will have some function for implementing this convolution operator.

Â 8:03

So to illustrate this, we're going to use a simplified image.

Â So here is a simple 6 x 6 image,

Â where the left half of the image is 10 and the right half is 0.

Â If you caught this as a picture, it might look like this, where the left half,

Â the 10s, give you brighter pixel intensity values.

Â And the right half gives you darker pixel intensity values.

Â I'm using that shade of gray to denote 0s,

Â although maybe it could also be drawn as black.

Â But in this image, there's clearly a very strong vertical edge right down the middle

Â of this image as it transitions from white to black or white to darker color.

Â 9:06

So just to verify this math, if you want.

Â This 0, for example, is obtained by taking the element-wise products and

Â then multiplying with this 3 x 3 block.

Â And so you get from the left column 10 + 10 + 10, and

Â then 0s in the middle, and then -10 -10 -10.

Â Which is why you end up with 0 over here.

Â Whereas, in contrast, that 30 would be obtained from this.

Â 9:36

Which you get from having 10 + 10 + 10, and

Â then -0 -0, which is why you end up with a 30 over there.

Â Now if you plot this rightmost matrix as an image, it will look like that,

Â where there's this lighter region right in the middle.

Â And that corresponds to having detected this vertical edge

Â down the middle of your 6 x 6 image.

Â And in case the dimensions here seem a little bit wrong,

Â that the detected edge seems really thick.

Â That's only because we're working with very small images in this example.

Â And if you're using, say, a 1000 x 1000 image,

Â rather than 6 x 6 image, then you find that this

Â does a pretty good job detecting the vertical edges in your image.

Â And in this example,

Â this bright region in the middle is just the output image's way of saying that

Â it looks like there's a strong vertical edge right down the middle of the image.

Â And maybe one intuition to take away from vertical edge detection is that

Â a vertical edge is a 3 x 3 region since we're using a 3 x 3 filter.

Â Where there are bright pixels on the left.

Â And you don't care that much what's in the middle.

Â And dark pixels on the right.

Â And the middle of the image in the 6 x 6 image is really where there

Â could be bright pixels on the left and dark pixels on the right.

Â And that's why it thinks there's a vertical edge over there.

Â And the convolution operation gives you a convenient way to specify

Â how to find these vertical edges in an image.

Â So you've now seen how the convolution operator works.

Â In the next video, you'll see how to take this and

Â use it as one of the basic building blocks of a convolutional neural network.

Â