How Blurs & Filters Work - Computerphile

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
what I would understand to be a filter is perhaps slightly different from what people who use Instagram would describe as a filter usually in an app or cam phone app or Facebook or some other thing where you can apply some filter it's going to actually be a combination of lots of low level processing of various types you know blurs contrast changes color changes what I tend to use in my day-to-day work would be below level things Gaussian blurs edge detection this kind of stuff but really they're all filters and they all take some image process it and come come up with some output today we're going to look at a simple technique called kernel convolution and that is kind of the core of Gaussian blurs and nor mean blurs and edge detection and lots of other things and it's a very simple technique that we use a lot around here with computer vision work kernel convolution is just a process where we take a small grid of numbers and we pass them over the whole image transforming it based on what those numbers are and by using different numbers in the kernel we can perform blurs or edge detection or sharpen unsharp and basically any effect we like so I'll first describe kernel convolution and then we'll look at a couple of examples of what sort of kernels that we see a lot of kernel convolution works by if this is our test image that's five by five and this is our kernel which is three by three so generally speaking the kernel will be smaller than the image and usually actually quite small and what we do this is my moveable kernel that we've come up with and what we do basically is for every pixel in our image we put our kernel over it so that the pixel is in the center so let's look at this pixel here number 64 we put our kernel over it and then we are looking at the three by three grid centered around that pixel and we take whatever values in our kernel multiply it by 17 and then the top value and multiply it by 14 on the top corner value of x 13 so we take each corresponding image value and kernel value we multiply them together in pairs and then we sum the whole thing up and then finally we normalize by dividing by the total value of our kernel to make sure that it doesn't get brighter or darker so severe like averaging it's exactly is averaging yep in a way it's just a big weighted average or if all the numbers are the same an actual average so in fact that's the first one we can look at so if if all of our values in our Kohinoor won then that's a mean blur so if you go into Adobe Photoshop or any other image protein package and you go for blurs blur filters and mean that's what it's going to be doing this is a kernel of size 3 you usually will do it obviously centered around a single pixel so odd sizes so 3 5 7 and so on so what we're going to do here is we're going to go 17 x 1 + 14 x 1 and so on and divide the whole thing by the sum of this which is 9 and that will basically take an average and then we'll overwrite that pixel with the output of that kernel convolution the only thing to make clear is that we should output these to a different image because if we overwrite them as we go it's going to mess up the mat as we go down I use blurs to remove noise from images before I process them in other ways for my job some other people might try and remove noise from images just to make them look better or you might try and blow the background out in a photograph or something like that and you can achieve a lot of effects just by convolving a kernel over an image you move it around for every pixel and when you look at whatever window but it's the size of your kernel the only other thing is but if you're at the edge then you've got to make some decision as to what you do here so you could ignore those ones and they wouldn't contribute at all or you could wrap the image around or you could duplicate the edge ones you could do lots of different things generally speaking I would just ignore them and then do a slightly smaller averaging for the corners that'll mean but the blurring around the edges is ever so slightly less than the blurring elsewhere in the image but just in the last edge pixel in a five to ten megapixel image probably won't make much of a difference so that's a very very simple kernel if we go for a slightly more complicated cone or we can go for the normal distribution of Gaussian blur so gaussian blur is extremely common probably I suppose the most common blur it's a little bit more controlled and edge preserving than a mean blur and so a lot of people like it so a normal distribution is a bell curve so if we have our axes there and we draw a bell curve and the standard deviation of this curve so the standard deviation is essentially the average distance from the mean of all the points will determine how why inves bell-curve is so a really large standard deviation we'll have a really large bell curve okay it should be symmetrical and a really small standard deviation we'll have a really tight bell curve which is essentially really prioritizing the the weights in the middle now if we wait these numbers based on the values from our normal distribution then we get a gaussian blur' an example of a very small Gaussian kernel would be a 3x3 so these values are going to be you know floating point decimal values but we just simplify it a little bit so for two on the edges and one now the crucial difference between this and the mean blur is that we're really prioritizing those in the middle the further away you get from the pixel of interest the less weight you have in the combined average and that's important because it basically means that you're not going to be blowing too much where where there's an edge let's say a sharp change in intensity as you approach that edge you're not going to be taking too many of those pixels and this Gaussian blur can obviously get a lot bigger so in your image processing program you might have an option that says standard deviation or ladys and what that's really referring to is a standard deviation of the normal distribution but produced this kernel and also the width of the kernel so we have to increase the size of our kernel as the radius of the Gaussian function increases this is a very small normal distribution if this was a bell curve it's it's really steep if we had a bigger standard deviation then we're going to need a bigger window to be able to hold enough information this isn't near big enough so let me draw a test image and then we'll do a blow on it and see how it works so okay so this is a good sized image this image is pretty basic it's an edge so we've got area of 50 intensity and layer of 100 intensity just put our mean one here as well just for comparison so if we do I mean first so we put that on let's say this this 50 here which is all right on the edge okay so we put our kernel on there and we're going to be doing 50 times 1 plus 50 times 1 plus it 100 times 1 and so on so it's going to be 100 200 300 400 5 600 and then we divide that by 9 and that gives us 66.6 okay and we round it to the nearest integer value for a Gaussian blur with this Gaussian blur here we're going to be doing 50 times 1 plus two times two plus 100 times one and so on okay and that will be a value of this is where we cut a hair so it's a thousand these add up to a thousand divided by sixteen which is sixty two and a half so ever so slightly closer to these fifty values on this edge then perhaps the mean blow was it's subtle but the the edge has been slightly preserved and generally speaking we're giving more weight to the numbers really really close to us these are very low-level filters these are sort of filters I will use in my day day to day work to alter images fine but I need to analyze but on Facebook and you know on the all these camera apps for your phone you'll see a lot of other perhaps more complicated filters bloom you know sepia vintage ones that make it look like some camera from the 1800's or something like that and really what they're doing is nothing hugely complicated they're just chaining together low-level image processing so a grayscale filter maybe a bit of blur and then some kind of border to make you look good in things like this so really these kind of filters at the core of a lot of the stuff that you see even if you might not know it you
Info
Channel: Computerphile
Views: 443,065
Rating: 4.9489274 out of 5
Keywords: computers, computerphile, computer, science, computer science, university of nottingham, mike pound, computer vision, blur, gaussian blur, filter, filters, graphical filters, kernel convolution
Id: C_zFhWdM4ic
Channel Id: undefined
Length: 7min 52sec (472 seconds)
Published: Fri Oct 02 2015
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.