[MUSIC] Hello, in this lecture, we're gonna summarize everything we've learned so far and introduce you to some image processing on the most basic level using what we've learned so far. And this should be very helpful with the final project of this course. And so, this will be your first look at sort of what kind of things we'll be doing throughout this course, and further on in specialization. All right, so we've learned a few things so far. We're gonna start by defining a 2D array that represents an image, so let's do that, image =, and then sort of open up with some new lines here. And within an image are pixels, and pixels are generally represented just by integer values. And so, we're gonna simplify every down and say that images are just 2D arrays of numbers from 0 to 10. So we've got this image, it looks like this. As you can see, I'm sort of painting before your eyes. Yeah, that's nice. Let's add an 8. Beautiful. And even a 2. All right, so here's our image, and this actually, albeit very simple, it's a good representation of an image because, if it was a three-pixel image, here you would have brightness, and you would be able to see something. It's a bit of a stretch, but we're gonna keep calling an image, and we're going to define a function that processes this image in a certain way. And so, if you recall, func, and what we're gonna do is, we're gonna take these sort of darker parts, if we say that the lower numbers are sort of darker parts of the image, and just make them brighter cuz darkness doesn't look as good. All right, so we're gonna call it raiseLowerValuesOfImage. I'm gonna pass an image, and we have to give it its type. Do you remember it? The type of a 2D array is simply an array of int. And if you ever are not sure what to put here, you can hold Alt and click on this, and it will give you the type, and this is shorthand, so the square brackets like this are shorthand for array. With the angle bracket bit type, so this looks much nicer. All right, and soon we're gonna see something interesting about this definition that we've never seen before, but first let's do some processing. All we're gonna do is take any lower value, say less than 5, and set it equal to 5, so we'll have a double for loop. Remember we can do a for in loop here, as in for, we're going to call this a row cuz we're gonna get a row for the first iteration in image. Remember, what's a row? So a row will be a single array of integers now. That's exactly what you want, and now we go to the columns. In each row, and a column should be an integer. Great, now we get the value here, and although this is nice and it's great for reading the value, the interesting thing is we can't really set the value here. Because we have image, but we don't know which pixel we're on, so we're going to do this differently. I just wanted to show you this. All right, so we're going to have to know which exact coordinate we're on, like (0,0), (0,1), so forth. So we're gonna have an i. We're actually gonna use row, but instead of in the image, we're gonna make it be an integer, so we can go from 0 to image.count, and so we use the range operator as we've seen once before. And now row is directly an integer. It's similar to before but different, as in now in this next column, we are going to have to access the actual row image. We can still call .count because image, once you access the row, it's a single array, and now in columns and other count from 0 to the length, which in this case is 3, so what can we do here? Here we know that we can read the value of the pixel, which is just image row column, and if we call this right now, raiseLowerValuesOfImage, it should run nine times and tell us what it printed, and we can see that again from here. And it tries to graph it to us cuz it is called sequentially, and you see it's 3, 7, 10, 6, 4, 2, etc. I'm going to hide that. All right, so this works, we want to set it to something, so we need an if statement here. So if this value is less than 5, we're simply gonna set it to 5, and this is where we're going to get an error. And we're going to read the error, and it is, we cannot assign it because image is a constant. When you pass a parameter into a function you can't modify that parameter. That's what return values are for, but in cases like this, where you do want to modify the parameter, you can mark it with var, and there's a nice fix it here which makes it super easy. Let's just click on that, and all it did was add var to our parameter, and now it works. And now we raise the value of our image. We're still calling it, and it says it ran four times, which would be one, two, three, four. Four times is correct, and now if we print out imaging in down here, all right, so once we print out image, we see our function's not working as intended. And this is great, well, this is not great, but now this lets me demonstrate something more to you, and I do know why that's the case. So, when you set it as var, it's still passing in a copy of the image because image is a structure. You get a copy of the image inside your function. When you set it to a var, it becomes mutable so you can change it as much as you want into function, but it's not actually changing this image outside of the function that we passed in. So, if you print this image here, you'll see that it hasn't even been changed, but it hasn't been changed here. And so, can we get what we want, though? Can we actually change image? We can, and it's a different sort of modifier here. Var means that to pass it in and create a variable that you can change, but there's another parameter called inout, which is what we want, which means it comes in and it goes out. That's how I see it, but what it means is that now it's almost passed by reference. Now you're passing this by reference, and when you do changes to it, they will be reflected outside, too. And inout is a bit special, as you can see, we get an error down here to make it clear when you're calling the function that this parameter might be changed. Swift makes you add an ampersand to it. This is a lot like passing a reference in C and C++, and it's really nice, so when you do this, you know that it might be changed. And when you don't do this, you know that your variable will not be touched by this function. All right, now that we've made this change, we can see image has, indeed, now been modified by this function. And so, yes, this is a good overview of what we learned so far, and I hope this helps you later on in your assignments. We'll see you next lecture.