1
00:00:00,060 --> 00:00:06,120
So welcome back to the course, the lesson we're about to do now is adding and removing noise to images

2
00:00:06,510 --> 00:00:13,620
and then fixing his images with histogram equalization, so we adjust a contrast to make it more even

3
00:00:13,620 --> 00:00:14,460
across the image.

4
00:00:15,000 --> 00:00:19,530
So go ahead and open this notebook and let's begin to lesson.

5
00:00:20,100 --> 00:00:21,600
So already have it opened here?

6
00:00:21,630 --> 00:00:26,510
So firstly, since we're talking about noise, what exactly is noise?

7
00:00:26,990 --> 00:00:31,320
Noise is something that plagues low light vision or photography.

8
00:00:32,250 --> 00:00:39,600
That happens because when you have a very dark scene, you have to adjust your camera sensor.

9
00:00:40,050 --> 00:00:45,270
You have to increase the sensitivity so it becomes much more sensitive to pick up low light in low light

10
00:00:45,270 --> 00:00:45,960
environments.

11
00:00:46,470 --> 00:00:53,010
However, that comes at a price because what happens now is that the camera now receives a lot of other

12
00:00:53,370 --> 00:01:00,630
noise because the actual light is reflected that's been reflected to the camera is so close in amplitude

13
00:01:00,630 --> 00:01:03,330
or intensity to no light at all.

14
00:01:03,780 --> 00:01:10,510
So the camera produces its basically produces images like this when you have an issue of of twelve hundred

15
00:01:10,540 --> 00:01:11,220
twenty eight thousand.

16
00:01:11,910 --> 00:01:14,310
So actually, it's two of those 900.

17
00:01:14,310 --> 00:01:14,580
Sorry.

18
00:01:15,120 --> 00:01:22,590
So you can see definitely like low ISO nice lawyers or at 100 gives you a nice, clean images like this

19
00:01:22,590 --> 00:01:23,070
case here.

20
00:01:23,430 --> 00:01:26,310
However, you can see how much added white noise.

21
00:01:26,310 --> 00:01:27,390
This is what it's called here.

22
00:01:27,960 --> 00:01:33,280
It happens when you increase the surface sensitivity of a camera sensor, so that's what noises.

23
00:01:33,360 --> 00:01:37,320
So let's take a look at how we can add noise to a photo.

24
00:01:37,320 --> 00:01:43,770
So let's load our images and load on functions and declare the MCO function, which I've already done.

25
00:01:43,770 --> 00:01:46,440
So I have to already, you know, need to do it.

26
00:01:47,190 --> 00:01:51,320
So let's create a function that adds white noise to an image.

27
00:01:51,330 --> 00:01:52,440
So how do we do this?

28
00:01:52,620 --> 00:01:55,710
Well, firstly, we take an input image here.

29
00:01:56,010 --> 00:02:02,700
However, inside this function, we create a random value called probability, which will be the probability

30
00:02:02,700 --> 00:02:06,090
of noise that's assigning some random value of noise.

31
00:02:06,240 --> 00:02:09,660
So we took a number between one zero five and point one.

32
00:02:10,380 --> 00:02:12,690
If we increase this, we added a lot more noise to the image.

33
00:02:12,690 --> 00:02:18,270
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

34
00:02:18,270 --> 00:02:19,290
every time we added.

35
00:02:19,290 --> 00:02:25,500
Just because it's a random white noise bunch and you don't want it to always add the same amount of

36
00:02:25,500 --> 00:02:25,790
noise.

37
00:02:25,800 --> 00:02:28,530
I mean, if you did it, it's fine, but we don't want to in this case.

38
00:02:29,160 --> 00:02:34,890
So what we do next, we generate random matrix in the shape of an image that's going to be of a noise

39
00:02:35,100 --> 00:02:35,520
image.

40
00:02:36,150 --> 00:02:44,400
So what we do next, we take the image, you get the size, and then we actually apply random variations

41
00:02:44,790 --> 00:02:50,970
to the pixels in the image using this random probability random matrix with the noise that we created

42
00:02:50,970 --> 00:02:54,690
above, and that's how we actually generate the noise.

43
00:02:55,260 --> 00:02:59,550
So we have these random values between here where this adds it to the image.

44
00:02:59,970 --> 00:03:05,340
So and as only for ones that are meeting the probability requirements.

45
00:03:05,940 --> 00:03:10,890
So let's take a look at how that actually works and what the results are.

46
00:03:10,920 --> 00:03:17,300
So let's run this little script here, and you can see this is the original image looks quite good this

47
00:03:17,310 --> 00:03:19,560
low light noise in the image.

48
00:03:19,560 --> 00:03:21,900
And yet it's in the nighttime environment, so that's pretty good.

49
00:03:22,560 --> 00:03:24,500
However, you can see what noise added.

50
00:03:24,510 --> 00:03:25,500
Let's zoom in a bit.

51
00:03:26,400 --> 00:03:26,730
Oops.

52
00:03:28,050 --> 00:03:33,780
You can see there's a lot of white speck dust on the image here, and it's also the image, and it looks

53
00:03:33,780 --> 00:03:34,410
a bit blurry.

54
00:03:35,460 --> 00:03:38,990
So that's what noise is in the original image.

55
00:03:39,000 --> 00:03:41,610
Sorry, but it's jumping around, doing it on its own.

56
00:03:41,610 --> 00:03:47,700
For some reason, you're going to see there's no noise in the original image yet when you go down,

57
00:03:47,700 --> 00:03:48,540
there's noise added.

58
00:03:48,960 --> 00:03:55,050
So let's take a look at admitted we can use to the noise or remove noise from an image.

59
00:03:55,740 --> 00:03:58,070
So OpenCV has a few functions.

60
00:03:58,080 --> 00:04:03,810
One of them is fast, and it means the noise in coloured, which looks in coloured images and you can

61
00:04:03,810 --> 00:04:05,380
set some of the parameters here.

62
00:04:05,400 --> 00:04:09,650
These are the recommended values for these parameters, but feel free to explore.

63
00:04:09,660 --> 00:04:13,530
You can decide what the parameters names are and experiment with them.

64
00:04:14,040 --> 00:04:18,360
So let's run this and see how it performs on our noisy image here.

65
00:04:19,020 --> 00:04:21,810
Let's see if it's how much noise it can remove.

66
00:04:23,400 --> 00:04:24,030
So there we go.

67
00:04:24,030 --> 00:04:26,250
You can see the noise is still visible.

68
00:04:26,400 --> 00:04:28,980
However, you can see it's a lot less than it was before.

69
00:04:29,430 --> 00:04:31,580
Let's go up to the noisy image.

70
00:04:31,590 --> 00:04:35,850
You can definitely see the white speck dust is more pronounced in this image.

71
00:04:35,850 --> 00:04:40,680
I hope you can see it on the video and you end see your internet connection is high enough.

72
00:04:41,130 --> 00:04:42,490
You will see the difference.

73
00:04:42,510 --> 00:04:46,050
So this is with noise added and then it's a bit noise removed.

74
00:04:46,050 --> 00:04:48,630
You can see it looks a bit better, not a lot better.

75
00:04:48,630 --> 00:04:52,500
But what I would encourage you to do is experiment with different parameters here.

76
00:04:52,980 --> 00:04:54,960
See if we can get this better now.

77
00:04:54,990 --> 00:04:59,610
You should know the price of this function is that it's going to remove detail.

78
00:05:00,080 --> 00:05:06,620
So immediately, if you needed to have detail, you would immediately know that dysfunction and sacrifices

79
00:05:06,620 --> 00:05:06,890
that.

80
00:05:07,220 --> 00:05:13,310
So if there was some text that was here, you needed to do an image that may actually make it worse

81
00:05:13,310 --> 00:05:19,700
with the noisy collection now later on in discourse, we're actually going to take a look at deep learning

82
00:05:19,700 --> 00:05:24,830
guns, super resolution guns that can remove noise or increase resolution.

83
00:05:25,220 --> 00:05:26,930
So those are pretty cool.

84
00:05:26,960 --> 00:05:30,590
So we will get to see that a little later half of the course.

85
00:05:31,040 --> 00:05:33,170
There were a lot more, a lot better than this.

86
00:05:33,950 --> 00:05:37,370
So now let's take a look at this actually, the other sorry one.

87
00:05:37,790 --> 00:05:43,130
These are the other denoting functions that are available in open TV so you can try them.

88
00:05:43,130 --> 00:05:45,840
They work with different types of images.

89
00:05:45,860 --> 00:05:52,820
This is greyscale colored multi images and multicolored so can apply them as you see fit.

90
00:05:53,240 --> 00:05:57,320
So let's take a look at histogram equalization.

91
00:05:57,680 --> 00:05:59,580
So what is histogram equalization?

92
00:05:59,820 --> 00:06:05,450
Remember when we did it, the histogram plots of images so you could see the amount of red or ho intends

93
00:06:05,450 --> 00:06:10,370
to red colors, green colors, blue colors were offered to grayscale is how intense to general colors

94
00:06:10,370 --> 00:06:11,780
were like in this example here.

95
00:06:12,410 --> 00:06:16,760
Well, you can see in this image here all of the intensities focus into one area.

96
00:06:16,910 --> 00:06:20,750
However, there's a lot of more bright and dark that's not being used.

97
00:06:20,930 --> 00:06:27,920
So what if there's a way we can flatten this and expand it on this axis here so that we can take advantage

98
00:06:27,920 --> 00:06:30,170
of the full spectrum of intensities?

99
00:06:30,800 --> 00:06:36,860
It leads to a better looking photo generally, and there's a way we can do it.

100
00:06:37,280 --> 00:06:45,080
Using the histogram functions and open TV, we can create a histogram here, get the cumulative sum

101
00:06:45,350 --> 00:06:49,220
from that histogram right here and then run some normalization on it.

102
00:06:49,400 --> 00:06:56,750
This is how we compress it into this nice looking distribution here, and we can actually display the

103
00:06:56,750 --> 00:06:58,350
output well, the graph of it here.

104
00:06:58,370 --> 00:07:00,410
So this is just a normal histogram likely to do.

105
00:07:00,770 --> 00:07:02,150
This isn't actually the

106
00:07:04,970 --> 00:07:06,230
histogram equalized image.

107
00:07:06,620 --> 00:07:08,600
This is just a sample of what it would look like.

108
00:07:08,870 --> 00:07:10,250
So this is the original image.

109
00:07:10,700 --> 00:07:16,850
You can see it looks like everything is a bit focus into like a light medium gray type color spectrum.

110
00:07:17,330 --> 00:07:19,790
And immediately you can see that in the histogram results.

111
00:07:19,790 --> 00:07:24,830
If this is a normalize histogram and this is a great skill vision, because what we're going to do,

112
00:07:25,220 --> 00:07:33,440
we're going to apply the equalization method and open TV to this grayscale image so we can get flattened

113
00:07:33,590 --> 00:07:37,370
more equally, equally distributed histogram of intensities.

114
00:07:37,820 --> 00:07:39,770
So let's applied histogram equalization.

115
00:07:40,400 --> 00:07:41,810
This is the way it's done here.

116
00:07:42,140 --> 00:07:47,030
So you take the grayscale image, you passage through this function and get the image out.

117
00:07:47,040 --> 00:07:48,080
It's quite simple to use.

118
00:07:48,680 --> 00:07:53,570
And then we just create the histogram distribution like we did before so we can see the results of that

119
00:07:53,570 --> 00:07:54,080
change.

120
00:07:54,500 --> 00:08:00,590
So let's run this and you can see it's a lot different to the previous grayscale image.

121
00:08:00,590 --> 00:08:03,470
It looks like it has a lot more detail added to it, doesn't it?

122
00:08:04,160 --> 00:08:06,500
This one looks so faded and filmed.

123
00:08:06,920 --> 00:08:08,360
It's not much you can cancel them.

124
00:08:08,370 --> 00:08:13,820
You can even tell where the image of shadow is light, and this one you can definitely tell.

125
00:08:14,060 --> 00:08:20,350
Like these are shadows diesel indentations of the Christmas tree on this snowflake or this.

126
00:08:20,510 --> 00:08:21,440
This is just a snowflake.

127
00:08:21,440 --> 00:08:23,420
It's not a Christmas tree, but it looks a bit like it.

128
00:08:24,260 --> 00:08:26,900
And this is the result of this economic rotation.

129
00:08:27,170 --> 00:08:31,990
You can see it's not evenly distributed, mostly the spike here, but that's natural.

130
00:08:32,420 --> 00:08:34,930
You can't we can't do that perfectly all the time.

131
00:08:34,940 --> 00:08:38,330
We still have to retain some of the information in the original image.

132
00:08:38,750 --> 00:08:41,330
So this is how we do it for grayscale images.

133
00:08:41,660 --> 00:08:49,580
And as a homework exercise for you guys, you can equalize each channel, each RGV child using the key

134
00:08:49,580 --> 00:08:55,550
to a split function and then using the V to merge function image and back together together equalized

135
00:08:55,550 --> 00:08:56,360
color image.

136
00:08:56,750 --> 00:08:58,910
So I'll leave that for you guys to do so.

137
00:08:58,910 --> 00:09:01,700
You can practice with your open OpenCV techniques.

138
00:09:02,360 --> 00:09:08,900
So that's it for this lesson will now move on to detecting blue in images, which is quite useful when

139
00:09:08,900 --> 00:09:14,000
you're doing things like OCR, and you need to extract the sharpness image from like a video scene.

140
00:09:14,510 --> 00:09:16,640
So we'll take a look at that lesson shortly.

141
00:09:16,820 --> 00:09:17,210
Thank you.
