So welcome back to the course, the lesson we're about to do now is adding and removing noise to images
and then fixing his images with histogram equalization, so we adjust a contrast to make it more even
across the image.
So go ahead and open this notebook and let's begin to lesson.
So already have it opened here?
So firstly, since we're talking about noise, what exactly is noise?
Noise is something that plagues low light vision or photography.
That happens because when you have a very dark scene, you have to adjust your camera sensor.
You have to increase the sensitivity so it becomes much more sensitive to pick up low light in low light
environments.
However, that comes at a price because what happens now is that the camera now receives a lot of other
noise because the actual light is reflected that's been reflected to the camera is so close in amplitude
or intensity to no light at all.
So the camera produces its basically produces images like this when you have an issue of of twelve hundred
twenty eight thousand.
So actually, it's two of those 900.
Sorry.
So you can see definitely like low ISO nice lawyers or at 100 gives you a nice, clean images like this
case here.
However, you can see how much added white noise.
This is what it's called here.
It happens when you increase the surface sensitivity of a camera sensor, so that's what noises.
So let's take a look at how we can add noise to a photo.
So let's load our images and load on functions and declare the MCO function, which I've already done.
So I have to already, you know, need to do it.
So let's create a function that adds white noise to an image.
So how do we do this?
Well, firstly, we take an input image here.
However, inside this function, we create a random value called probability, which will be the probability
of noise that's assigning some random value of noise.
So we took a number between one zero five and point one.
If we increase this, we added a lot more noise to the image.
So we don't want to add too much noise but want to add some noise for sure, and we want it to be different
every time we added.
Just because it's a random white noise bunch and you don't want it to always add the same amount of
noise.
I mean, if you did it, it's fine, but we don't want to in this case.
So what we do next, we generate random matrix in the shape of an image that's going to be of a noise
image.
So what we do next, we take the image, you get the size, and then we actually apply random variations
to the pixels in the image using this random probability random matrix with the noise that we created
above, and that's how we actually generate the noise.
So we have these random values between here where this adds it to the image.
So and as only for ones that are meeting the probability requirements.
So let's take a look at how that actually works and what the results are.
So let's run this little script here, and you can see this is the original image looks quite good this
low light noise in the image.
And yet it's in the nighttime environment, so that's pretty good.
However, you can see what noise added.
Let's zoom in a bit.
Oops.
You can see there's a lot of white speck dust on the image here, and it's also the image, and it looks
a bit blurry.
So that's what noise is in the original image.
Sorry, but it's jumping around, doing it on its own.
For some reason, you're going to see there's no noise in the original image yet when you go down,
there's noise added.
So let's take a look at admitted we can use to the noise or remove noise from an image.
So OpenCV has a few functions.
One of them is fast, and it means the noise in coloured, which looks in coloured images and you can
set some of the parameters here.
These are the recommended values for these parameters, but feel free to explore.
You can decide what the parameters names are and experiment with them.
So let's run this and see how it performs on our noisy image here.
Let's see if it's how much noise it can remove.
So there we go.
You can see the noise is still visible.
However, you can see it's a lot less than it was before.
Let's go up to the noisy image.
You can definitely see the white speck dust is more pronounced in this image.
I hope you can see it on the video and you end see your internet connection is high enough.
You will see the difference.
So this is with noise added and then it's a bit noise removed.
You can see it looks a bit better, not a lot better.
But what I would encourage you to do is experiment with different parameters here.
See if we can get this better now.
You should know the price of this function is that it's going to remove detail.
So immediately, if you needed to have detail, you would immediately know that dysfunction and sacrifices
that.
So if there was some text that was here, you needed to do an image that may actually make it worse
with the noisy collection now later on in discourse, we're actually going to take a look at deep learning
guns, super resolution guns that can remove noise or increase resolution.
So those are pretty cool.
So we will get to see that a little later half of the course.
There were a lot more, a lot better than this.
So now let's take a look at this actually, the other sorry one.
These are the other denoting functions that are available in open TV so you can try them.
They work with different types of images.
This is greyscale colored multi images and multicolored so can apply them as you see fit.
So let's take a look at histogram equalization.
So what is histogram equalization?
Remember when we did it, the histogram plots of images so you could see the amount of red or ho intends
to red colors, green colors, blue colors were offered to grayscale is how intense to general colors
were like in this example here.
Well, you can see in this image here all of the intensities focus into one area.
However, there's a lot of more bright and dark that's not being used.
So what if there's a way we can flatten this and expand it on this axis here so that we can take advantage
of the full spectrum of intensities?
It leads to a better looking photo generally, and there's a way we can do it.
Using the histogram functions and open TV, we can create a histogram here, get the cumulative sum
from that histogram right here and then run some normalization on it.
This is how we compress it into this nice looking distribution here, and we can actually display the
output well, the graph of it here.
So this is just a normal histogram likely to do.
This isn't actually the
histogram equalized image.
This is just a sample of what it would look like.
So this is the original image.
You can see it looks like everything is a bit focus into like a light medium gray type color spectrum.
And immediately you can see that in the histogram results.
If this is a normalize histogram and this is a great skill vision, because what we're going to do,
we're going to apply the equalization method and open TV to this grayscale image so we can get flattened
more equally, equally distributed histogram of intensities.
So let's applied histogram equalization.
This is the way it's done here.
So you take the grayscale image, you passage through this function and get the image out.
It's quite simple to use.
And then we just create the histogram distribution like we did before so we can see the results of that
change.
So let's run this and you can see it's a lot different to the previous grayscale image.
It looks like it has a lot more detail added to it, doesn't it?
This one looks so faded and filmed.
It's not much you can cancel them.
You can even tell where the image of shadow is light, and this one you can definitely tell.
Like these are shadows diesel indentations of the Christmas tree on this snowflake or this.
This is just a snowflake.
It's not a Christmas tree, but it looks a bit like it.
And this is the result of this economic rotation.
You can see it's not evenly distributed, mostly the spike here, but that's natural.
You can't we can't do that perfectly all the time.
We still have to retain some of the information in the original image.
So this is how we do it for grayscale images.
And as a homework exercise for you guys, you can equalize each channel, each RGV child using the key
to a split function and then using the V to merge function image and back together together equalized
color image.
So I'll leave that for you guys to do so.
You can practice with your open OpenCV techniques.
So that's it for this lesson will now move on to detecting blue in images, which is quite useful when
you're doing things like OCR, and you need to extract the sharpness image from like a video scene.
So we'll take a look at that lesson shortly.
Thank you.