1
00:00:01,140 --> 00:00:07,380
So now let's move on to a seventh lesson called the arithmetic and Bitwise operations already have it

2
00:00:07,380 --> 00:00:09,180
open on this next tab here.

3
00:00:09,900 --> 00:00:10,740
So let's begin.

4
00:00:10,740 --> 00:00:16,380
So firstly, let's just quickly download and set up our libraries here will connect.

5
00:00:16,470 --> 00:00:22,500
You can see connecting to your machine up here, and it should be done right about now.

6
00:00:22,710 --> 00:00:23,160
There we go.

7
00:00:23,160 --> 00:00:27,810
So we have a machine and we've downloaded and set up in our libraries and code.

8
00:00:28,560 --> 00:00:35,670
So arithmetic operations, basically operations that allow us to add or subtract to the intensity or

9
00:00:35,670 --> 00:00:37,390
the the values of the image.

10
00:00:37,470 --> 00:00:37,770
OK.

11
00:00:38,370 --> 00:00:43,650
So what we're going to do, we're going to load in an image as a grayscale image and haven't showed

12
00:00:43,650 --> 00:00:45,420
you that did this before.

13
00:00:46,020 --> 00:00:52,570
But when you're using the emerade function, if you put after you put the part of the image here and

14
00:00:52,590 --> 00:00:58,710
the part basically is a file path of the image, which basically it's in here, how to point to remove

15
00:00:58,710 --> 00:01:00,840
this directory, hit images and liberty.

16
00:01:00,930 --> 00:01:03,090
So we have the file parts there.

17
00:01:03,900 --> 00:01:09,390
And if you put a comma zero, basically this tells this function to read this and as a grayscale image.

18
00:01:09,900 --> 00:01:16,650
So we're going to read it and as a grayscale image, and then we're going to create another image here.

19
00:01:17,430 --> 00:01:23,040
This is basically the image matrix of ones that we're going to multiply by 100 to get a matrix that

20
00:01:23,040 --> 00:01:28,410
is the same size of as this image here, but filled with values of 100.

21
00:01:28,920 --> 00:01:30,110
So that's clear.

22
00:01:30,120 --> 00:01:32,280
Actually, I can show you guys what it looks like.

23
00:01:32,730 --> 00:01:34,620
You can see what I'm printing 'em here.

24
00:01:35,130 --> 00:01:38,190
But for now, let's actually not print them here.

25
00:01:38,610 --> 00:01:45,810
Let's just print the initial image here so we can actually take a look at it properly.

26
00:01:48,000 --> 00:01:50,340
And let's add another code block here.

27
00:01:51,000 --> 00:01:53,030
And oops, not not this.

28
00:01:53,160 --> 00:01:54,540
Let's just print.

29
00:01:55,320 --> 00:01:58,520
And here's it coming in on capital and capital and.

30
00:02:00,950 --> 00:02:02,840
So you can see this is our image here.

31
00:02:02,870 --> 00:02:06,520
This is devalues the greyscale values for this point.

32
00:02:06,530 --> 00:02:12,790
Here you can see it's 41, 41 41, which means all of this is the same color gray and vice versa.

33
00:02:12,800 --> 00:02:15,800
So you can see it actually forms this pretty cool image in the end.

34
00:02:16,560 --> 00:02:23,250
No, when you have actually actually print this one, know this m here is the same dimension where we

35
00:02:23,480 --> 00:02:29,090
specified it in the function to created that same shape as the input image here, but it's now just

36
00:02:29,090 --> 00:02:30,310
fill the values of 100.

37
00:02:30,500 --> 00:02:31,700
And why are we doing that?

38
00:02:32,570 --> 00:02:33,170
What are we going to do?

39
00:02:33,200 --> 00:02:39,500
We're going to add these two matrices together using the CV to add, and that effectively is going to

40
00:02:39,500 --> 00:02:41,240
increase the brightness of the image.

41
00:02:41,630 --> 00:02:46,630
So in case you're wondering how we have increased brightness of images, this is basically what it's

42
00:02:46,630 --> 00:02:46,880
suddenly.

43
00:02:46,880 --> 00:02:52,760
Just add more values to the original image, and this is how it's done programmatically with OpenCV.

44
00:02:53,570 --> 00:02:55,230
So let's do it here.

45
00:02:55,250 --> 00:02:56,690
So there's two methods we're going to do.

46
00:02:57,140 --> 00:03:03,470
We're going to edit using the key to add function and then we're going to edit normally just like this,

47
00:03:03,470 --> 00:03:05,930
adding two matrices together and see what happens.

48
00:03:06,080 --> 00:03:08,540
And let's take a look and see why it's different.

49
00:03:09,860 --> 00:03:15,260
So in the first case, with the using the key to that idea, you can see it looks as expected.

50
00:03:15,290 --> 00:03:18,900
We get a nice, brighter image a bit too bright, but it's fine.

51
00:03:19,490 --> 00:03:20,600
It's what we wanted.

52
00:03:20,600 --> 00:03:25,100
By adding 100 to every value here, we increased the likeness.

53
00:03:25,130 --> 00:03:30,080
When I say the likeness, I mean, instead of darker, it gets lighter, like library of the image.

54
00:03:30,770 --> 00:03:36,770
Now look what happens if you just added here, this is where you actually see you get some black spots

55
00:03:36,770 --> 00:03:37,070
here.

56
00:03:37,070 --> 00:03:44,180
And that's because at Eclipse, remember the values only range and in these functions and these images

57
00:03:44,390 --> 00:03:45,560
to 255.

58
00:03:46,070 --> 00:03:50,200
So what if there was a point that was, say, 200 in the original image?

59
00:03:50,210 --> 00:03:51,440
Let's go back to the original image.

60
00:03:51,440 --> 00:03:53,870
Look, here might be high 200s.

61
00:03:54,350 --> 00:03:59,750
If you add a hundredth of that, you would get 300 and something, but 300 and something, let's say

62
00:03:59,750 --> 00:04:06,920
200 isn't allowed as an image value because the image values have only allowed to go up to 55.

63
00:04:07,370 --> 00:04:13,670
So what's going to happen is that it's going to go back to zero and it's going to go back to zero.

64
00:04:13,790 --> 00:04:15,650
But it's going to go back to fully zero.

65
00:04:16,010 --> 00:04:19,310
It's a 300 minus 255 is 40.

66
00:04:19,910 --> 00:04:23,150
So it's going to go all the way over to 255.

67
00:04:24,530 --> 00:04:26,390
It's going to be sort of the 255.

68
00:04:26,390 --> 00:04:29,420
It's going to basically go back from zero up to 40.

69
00:04:29,870 --> 00:04:35,810
So something so that's why you'll see these dogs, you'll see dark spots in areas that were bright in

70
00:04:35,810 --> 00:04:36,530
the original image.

71
00:04:37,070 --> 00:04:38,210
So you can kind of see it here.

72
00:04:38,990 --> 00:04:43,970
Some of these dark areas here will have bright spots in the original image like this wall here, especially

73
00:04:44,420 --> 00:04:46,310
is very white and it's very dark.

74
00:04:46,580 --> 00:04:51,490
So you can see that is why you probably don't want to just add values to images.

75
00:04:51,540 --> 00:04:52,520
A like this here.

76
00:04:53,210 --> 00:04:54,300
You want to use it.

77
00:04:54,320 --> 00:04:56,360
You would actually keeps it at 255.

78
00:04:56,810 --> 00:05:04,430
So instead of going over to 200 and then which is basically represented as like 40 in the end, what

79
00:05:04,430 --> 00:05:08,540
you do here is you actually eclipse it and its max value keeps it at that.

80
00:05:10,070 --> 00:05:13,720
So similarly, we can this we can subtract the values here.

81
00:05:13,730 --> 00:05:16,460
You can see we do that using CB2 Dot Subtract.

82
00:05:17,360 --> 00:05:21,770
It's a very similar function, and it does not allow values to go past zero.

83
00:05:22,190 --> 00:05:24,500
So you can see it gets darker as expected here.

84
00:05:25,070 --> 00:05:27,500
And now let's see what happens when we do the other one.

85
00:05:28,850 --> 00:05:30,320
It looks quite weird again.

86
00:05:30,920 --> 00:05:35,810
And that's because the values are actually going negative and they're not allowed to go negative, so

87
00:05:35,810 --> 00:05:40,220
they're actually going in the other direction, which is from 255 downward.

88
00:05:40,370 --> 00:05:44,510
So which is why you got so many bright areas when you're supposed to be darkening this image.

89
00:05:45,260 --> 00:05:49,280
So now let's move on to Bitwise operations and masking.

90
00:05:49,880 --> 00:05:52,550
So brightness and stuff is fine.

91
00:05:52,700 --> 00:05:57,950
However, there are a lot of more operations that we can do in open TV that require something called

92
00:05:57,950 --> 00:05:59,120
Bitwise operations.

93
00:05:59,570 --> 00:06:01,520
And what are they exactly?

94
00:06:01,550 --> 00:06:03,050
So let's to them this.

95
00:06:03,440 --> 00:06:05,060
Let's just create some images here.

96
00:06:05,060 --> 00:06:06,520
Let's create two images.

97
00:06:06,530 --> 00:06:12,260
Let's create this white square in the middle of this image here by these lines of code here.

98
00:06:13,160 --> 00:06:15,320
And that's making lips as well here.

99
00:06:16,370 --> 00:06:18,200
So now we're going to use these two images.

100
00:06:18,710 --> 00:06:21,800
We're going to do something called image operations.

101
00:06:21,800 --> 00:06:26,960
Image Bitwise Operations, where we take two images and make them act on each other.

102
00:06:27,440 --> 00:06:31,760
And you may remember this from maybe logic gates class in college.

103
00:06:32,030 --> 00:06:33,050
Yeah, one college.

104
00:06:33,050 --> 00:06:39,050
He did computer science in that trickle engineering or even physics or high school to do this in physics

105
00:06:39,050 --> 00:06:40,820
classes or maths class as well.

106
00:06:41,510 --> 00:06:42,810
So what are we going to do?

107
00:06:42,830 --> 00:06:46,730
We're going to apply and all this is all and not OK.

108
00:06:47,810 --> 00:06:49,430
So let's take the Bitwise operations.

109
00:06:49,430 --> 00:06:54,070
Have these two images screen ellipse and we'll do an end here.

110
00:06:54,170 --> 00:06:54,920
This is where we are.

111
00:06:54,920 --> 00:06:56,210
We hope we apply to end Bitwise.

112
00:06:56,210 --> 00:06:58,730
And I should say it gives an output.

113
00:06:59,260 --> 00:07:06,630
Outputs a variable called recall, and we keep it as restored as and that we're going to do or extra

114
00:07:07,110 --> 00:07:08,850
and not as well.

115
00:07:09,330 --> 00:07:15,390
All of these have built in functions into open KV C v2 that Bitwise or not or.

116
00:07:15,840 --> 00:07:16,780
And let's take a look.

117
00:07:16,800 --> 00:07:19,050
Let's run this and let's take a look at the outputs.

118
00:07:20,070 --> 00:07:22,800
Oh, square, we didn't define this here.

119
00:07:24,960 --> 00:07:27,420
Remember, we needed to run that cell before we run this, so.

120
00:07:30,270 --> 00:07:32,190
So let's stick a look at this.

121
00:07:32,940 --> 00:07:37,950
So the end function you can see and basically is where both of them intersect only.

122
00:07:38,640 --> 00:07:44,700
So let's take a look at that that can see in these images here where it's actually is.

123
00:07:44,700 --> 00:07:51,450
Maybe it is in some middle area here, which is exactly what we're seeing this middle area right here.

124
00:07:52,350 --> 00:08:00,680
So no, the wise or is basically both of them where everything is in both of them and XOR is actually

125
00:08:00,690 --> 00:08:06,600
what you would expect BlackWidow intersecting and wide Twitter not intersecting buildings where they

126
00:08:06,600 --> 00:08:09,790
exist still and not basically.

127
00:08:10,770 --> 00:08:16,590
This is actually only run on one image the not one here on the square.

128
00:08:16,980 --> 00:08:17,310
OK.

129
00:08:17,340 --> 00:08:18,330
So it shows everything.

130
00:08:18,350 --> 00:08:19,680
It isn't part of the square.

131
00:08:20,070 --> 00:08:22,200
It isn't one with two images like the others before.

132
00:08:22,890 --> 00:08:24,450
So you can see what not does.

133
00:08:24,960 --> 00:08:30,210
So this is quite useful when you're doing things like with image masking and living color, inverting

134
00:08:30,210 --> 00:08:33,780
images or buying arising in a way you don't really use it for binaries.

135
00:08:33,780 --> 00:08:39,210
I mean, you can use it for a lot of the masking type operations where you want to actually keep things

136
00:08:39,210 --> 00:08:42,060
or drop things, depending on what the logic is.

137
00:08:42,690 --> 00:08:44,940
So I hope you found this less than useful.

138
00:08:47,190 --> 00:08:52,990
A lot of these lessons there in isolation like this, you don't actually find them.

139
00:08:53,730 --> 00:08:55,260
You don't find a use case for them.

140
00:08:55,800 --> 00:09:01,050
However, when you're putting together computer vision applications that require like a pre-processing

141
00:09:01,050 --> 00:09:06,330
pipeline of different things that you may want to do, it's good to know what these individual functions

142
00:09:06,330 --> 00:09:11,400
do and how it are used so that you can actually implement some of the things you may want to implement.

143
00:09:11,910 --> 00:09:13,290
So that's what opens you.

144
00:09:13,290 --> 00:09:15,210
That's why open CV is so useful.

145
00:09:15,630 --> 00:09:21,690
It allows you so much powerful image manipulations that you can't call yourself a computer vision practitioner

146
00:09:21,690 --> 00:09:22,380
or engineer.

147
00:09:22,710 --> 00:09:27,180
If you're not familiar with it, open CV or the functions implemented by open CV.

148
00:09:27,600 --> 00:09:33,840
Now, open CV isn't the actual only tool that could do image operations in Python or in other programming

149
00:09:33,870 --> 00:09:34,530
languages.

150
00:09:34,950 --> 00:09:43,080
There are few others, but open CV is by far the most robust biggest library, one of the fastest libraries

151
00:09:43,080 --> 00:09:46,630
out there because it's built in C++, so it's quite useful.

152
00:09:46,680 --> 00:09:52,590
So I would I would encourage you to use strictly open CV as your main image processing tool.

153
00:09:52,830 --> 00:09:53,310
Thank you.

154
00:09:53,730 --> 00:09:55,260
So let's go on to the next lesson.
