1
00:00:00,210 --> 00:00:02,310
So now let's begin section six.

2
00:00:02,520 --> 00:00:09,300
So this one is titled Scaling Resizing into positions and cropping, so let's open this up and wait

3
00:00:09,300 --> 00:00:12,540
for it to load and should be here by now.

4
00:00:12,780 --> 00:00:13,320
There it is.

5
00:00:13,950 --> 00:00:19,530
So what we're going to do in this lesson, we're going to actually look at resizing and scaling images.

6
00:00:19,560 --> 00:00:24,210
Now that sounds like two different things, and technically it's not.

7
00:00:25,350 --> 00:00:28,230
But basically, it's just changing the size of the image.

8
00:00:28,800 --> 00:00:31,450
So it opens.

9
00:00:31,450 --> 00:00:36,480
TV has a function called CV to door to resize, and that's what we're going to take a look at first.

10
00:00:36,990 --> 00:00:42,510
So this function is quite useful, and there's many different ways to resize images which might not

11
00:00:42,510 --> 00:00:43,960
might be surprising to you.

12
00:00:44,490 --> 00:00:46,800
But we'll take a look at a few of those ways right now.

13
00:00:47,850 --> 00:00:51,420
So firstly, we have let's look at this function here.

14
00:00:51,420 --> 00:00:53,970
Let's look at what the resize to function does.

15
00:00:54,450 --> 00:00:57,390
So we have this here and highlighting that view.

16
00:00:58,020 --> 00:00:59,870
So we have the input to the image here.

17
00:00:59,880 --> 00:01:03,030
We have this size, this size, which is the output image size.

18
00:01:03,030 --> 00:01:06,960
If we want this design, some sense for dimension here.

19
00:01:07,020 --> 00:01:13,050
So we can specify actual dimensions of here, or we can have the X y scale here, as well as the interpolation

20
00:01:13,050 --> 00:01:13,440
method.

21
00:01:13,860 --> 00:01:15,330
So that could something a bit confusing.

22
00:01:15,330 --> 00:01:16,590
So let's take a look at this.

23
00:01:17,280 --> 00:01:24,180
So the interpolation methods here they are into area, into nearest, into linear, into cubic and Lonzo

24
00:01:24,660 --> 00:01:29,760
Lonzo Sorry four, which is supposedly the best resizing algorithm.

25
00:01:30,360 --> 00:01:33,000
So let's just test these out shortly.

26
00:01:33,000 --> 00:01:36,690
OK, so that actually this can happen to you guys.

27
00:01:36,690 --> 00:01:37,260
So it's a good thing.

28
00:01:37,260 --> 00:01:43,230
This lesson as I'm shooting this lesson club only allows you to open five notebooks at the same time.

29
00:01:43,740 --> 00:01:51,480
So because we're no longer using one to three and four, this just closes off too many of them and go

30
00:01:51,480 --> 00:01:52,290
back to this year.

31
00:01:53,190 --> 00:02:00,320
So now, because we're only allowed to connect to five virtual machines remotely on the cloud, so we

32
00:02:00,540 --> 00:02:04,800
so we don't abuse the resources that collab offers us so nicely for free.

33
00:02:05,580 --> 00:02:11,610
So we've downloaded all images and imported our libraries, so I just rehash what the types of methods

34
00:02:11,610 --> 00:02:12,240
here, huh?

35
00:02:12,270 --> 00:02:18,750
This blog go on Chadwick sites and the site here by Chadwick Todrick.

36
00:02:18,750 --> 00:02:22,860
I should say he has some nice examples of the different resizing methods.

37
00:02:22,860 --> 00:02:23,820
Here you can take a look.

38
00:02:24,270 --> 00:02:26,550
This is basically the input image here.

39
00:02:26,730 --> 00:02:27,900
This is Zoom in a bit.

40
00:02:28,440 --> 00:02:28,890
All right.

41
00:02:29,860 --> 00:02:32,670
Um, so this is a default image, 50 by 50.

42
00:02:33,030 --> 00:02:36,630
And these are the results by reducing the size to 15 by 15.

43
00:02:36,930 --> 00:02:38,580
So you're shrinking the size.

44
00:02:39,000 --> 00:02:41,700
So we're reducing the quality of only 15 by 15.

45
00:02:42,180 --> 00:02:45,510
But we're using a few different interpolation methods to generate this here.

46
00:02:45,600 --> 00:02:54,720
So this is the entire area, how it looks into cubic, into Lonzo's and into nearest and into linear.

47
00:02:55,230 --> 00:03:00,810
So you can see, I think, the best ones, probably into Quebec and into Nereus in this case here into

48
00:03:00,810 --> 00:03:02,670
Lonzo's is quite good as well.

49
00:03:03,660 --> 00:03:09,830
So these are of examples of these different interpolation methods being used here, and you can see

50
00:03:09,840 --> 00:03:13,470
even enlarging the images here when it's actually had a fairly good quality already.

51
00:03:13,950 --> 00:03:17,580
So we enlarge that image now to 150 to 50 to 100.

52
00:03:17,700 --> 00:03:19,860
And you can see what looks, how it looks here.

53
00:03:20,610 --> 00:03:23,460
So what is interpolation actually doing?

54
00:03:23,700 --> 00:03:27,390
So I didn't actually explain it well, actually didn't explain it at all.

55
00:03:27,960 --> 00:03:33,960
Interpolation is basically how is an algorithm to find a value between two points?

56
00:03:34,170 --> 00:03:35,900
Let's take a look at this slide here.

57
00:03:35,940 --> 00:03:40,740
Just briefly bringing this up in during the lesson that can actually put some of this can put this picture

58
00:03:40,740 --> 00:03:43,800
into the lesson that I place in the book for you guys afterward.

59
00:03:44,550 --> 00:03:47,520
So you can see, let's take a look at what interpolation actually is.

60
00:03:47,880 --> 00:03:53,130
So imagine we have a GPS that's logging coordinates as we move along this road of here.

61
00:03:53,610 --> 00:03:56,730
So you can see we took this corner at this point here.

62
00:03:56,760 --> 00:03:59,070
However, we didn't log this green point here.

63
00:03:59,460 --> 00:04:00,990
This is where the actual path was.

64
00:04:01,500 --> 00:04:07,830
So interpolation is going to guess a point in between these two red points that the yellow yellows are

65
00:04:07,830 --> 00:04:10,380
basically the guesses between the points as it moves along.

66
00:04:10,830 --> 00:04:17,460
So it's a way of actually adding more data to existing data to interpolated means as to connect the

67
00:04:17,460 --> 00:04:18,480
ones in between.

68
00:04:19,470 --> 00:04:23,980
So now going back to our lesson here, that's basically what interpolation methods do.

69
00:04:23,980 --> 00:04:29,310
There is when we resize an image, when we enlarge the image, we now have two kind of guests the pixels

70
00:04:29,310 --> 00:04:31,440
that are going to be there that aren't there right now.

71
00:04:31,890 --> 00:04:33,590
Remember, we way we're trying to make.

72
00:04:33,660 --> 00:04:34,710
Let's go back to this blog.

73
00:04:35,010 --> 00:04:37,830
We're trying to make enlarge this image here.

74
00:04:38,400 --> 00:04:43,200
Actually, this is this is the original image here and trying to guess the points it's going to be take

75
00:04:43,200 --> 00:04:44,400
in a new dimension.

76
00:04:45,060 --> 00:04:50,190
So the quality that it's being done is quite important, so into cubic and into these methods.

77
00:04:50,610 --> 00:04:57,810
These are these different formulas that use to apply to actually interpolate and guess the values that

78
00:04:57,810 --> 00:04:58,500
it should be there.

79
00:04:58,740 --> 00:04:59,760
When I say guess, I mean.

80
00:05:00,150 --> 00:05:07,200
Algorithmically, guess the best guess so we can actually get so some in some ways basically looks at

81
00:05:07,200 --> 00:05:13,830
averaging over different pixels in four different areas that's put into cubic does nearest basically

82
00:05:13,830 --> 00:05:15,780
mirrors into political neighborhood pollution.

83
00:05:16,590 --> 00:05:19,200
I'm not going to explain all of these because they actually can get quite technical.

84
00:05:19,650 --> 00:05:20,590
So what are we going to do?

85
00:05:20,610 --> 00:05:23,250
We're just going to resize images in a few different ways here.

86
00:05:23,700 --> 00:05:26,450
So I like resizing a lot.

87
00:05:26,490 --> 00:05:31,880
It's actually quite a useful operation because when you resize an image, we reduce its size.

88
00:05:31,890 --> 00:05:35,100
You actually can speed up a lot of photo operations afterward.

89
00:05:35,490 --> 00:05:39,660
So it's quite a good efficiency technique while you do lose some information.

90
00:05:39,990 --> 00:05:45,630
If you if you use a good interpolation algorithm, you should do what you generally lose a lot from

91
00:05:45,630 --> 00:05:46,590
actually scaling down.

92
00:05:47,580 --> 00:05:48,750
So let's take a look at this.

93
00:05:48,760 --> 00:05:53,820
So the first case here, what we're going to do, we're going to use the argument effects and f way

94
00:05:54,330 --> 00:06:00,510
to reduce the size of an image by 75 percent 0.75 off the original image.

95
00:06:01,260 --> 00:06:03,240
What are we going to do in the second one now?

96
00:06:04,140 --> 00:06:08,820
We're going to double it by using effects equal to fly equal to.

97
00:06:10,110 --> 00:06:16,710
And we're going to use the different interpolation methods doing that twice and then what we're going

98
00:06:16,710 --> 00:06:17,070
to do.

99
00:06:17,520 --> 00:06:20,310
We're going to use the dimensional method, which is actually very useful.

100
00:06:20,400 --> 00:06:26,130
Oftentimes, when, especially when, when you want to keep the aspect ratio off an image, the same

101
00:06:26,130 --> 00:06:27,480
is actually not always possible.

102
00:06:28,410 --> 00:06:32,310
Actually, there's possibilities of what to keep the values the same here, but this is actually quite

103
00:06:32,310 --> 00:06:34,570
good if you actually need to fix a size.

104
00:06:35,040 --> 00:06:40,110
Quite like a function requires image to be an exact size, exact specific size, and you can resize

105
00:06:40,110 --> 00:06:40,350
it.

106
00:06:40,470 --> 00:06:44,640
You can resize any image that size by using this this method here.

107
00:06:45,240 --> 00:06:50,790
So you can just run this here, and we just generally going to resize so images a few times.

108
00:06:52,170 --> 00:06:54,480
So this is with linear interpolation here.

109
00:06:55,320 --> 00:07:00,210
This is the point seventy five scaling right here from the original image.

110
00:07:00,660 --> 00:07:05,700
You can see it doesn't really lose much information, but you can see, though, even though it looks

111
00:07:05,700 --> 00:07:07,110
and looks like the same size.

112
00:07:07,530 --> 00:07:10,680
The pixels go up to 960 here, but now it goes up to 720.

113
00:07:11,370 --> 00:07:17,190
And if you look carefully at a sign this, this zoom into the sign a bit, you can see it's probably

114
00:07:17,460 --> 00:07:21,710
depends on the internet connection and how good your resolution is at your streaming lesson.

115
00:07:22,320 --> 00:07:29,940
But you can see that it actually is lower quality here, especially these words and this less this line

116
00:07:29,940 --> 00:07:32,100
right here compared to this one.

117
00:07:32,820 --> 00:07:35,100
So that's what the resizing did.

118
00:07:35,940 --> 00:07:36,690
Now what are we going to do?

119
00:07:36,720 --> 00:07:38,040
We're going to double the size now.

120
00:07:39,060 --> 00:07:44,760
Now we shouldn't actually get any information mode of it to just look better and bigger when it's printed.

121
00:07:45,030 --> 00:07:53,740
Perhaps that's a good way to a good reason to resize images for printing purposes and scaling the area

122
00:07:53,760 --> 00:07:54,600
can see when we scale.

123
00:07:54,600 --> 00:07:57,150
It's that weird size it actually affected aspect ratio.

124
00:07:57,600 --> 00:08:02,730
So depending on what you need to do, just remember that when you resize to a specific dimension.

125
00:08:03,570 --> 00:08:06,840
So, no, let's move on to using image pyramid's image.

126
00:08:06,840 --> 00:08:12,870
Pyramids are much quicker operation, and you're a quick way to actually scale up a scaled down image.

127
00:08:12,960 --> 00:08:19,470
Basically, double or half the size so you can see this PR people are down.

128
00:08:19,470 --> 00:08:23,490
Pyramid Down takes the image and reduced it to half its size.

129
00:08:23,940 --> 00:08:24,720
Then it actually.

130
00:08:24,720 --> 00:08:28,380
Then we can actually take the same smaller image input and give it back up here.

131
00:08:28,770 --> 00:08:32,730
That would probably give us a pixelated image, which you will see below shortly.

132
00:08:33,150 --> 00:08:37,500
So let's run this function here and see what what we have then.

133
00:08:39,000 --> 00:08:40,680
So let's take a look at this.

134
00:08:40,680 --> 00:08:42,090
So we have the original image here.

135
00:08:42,930 --> 00:08:48,150
We scaled it down here, half the size, so you can see that's half the dimensions of snow 450.

136
00:08:49,290 --> 00:08:52,560
And no, this is the one that was scaled back up.

137
00:08:53,100 --> 00:08:56,340
So we took a smaller image here and then made it bigger again.

138
00:08:56,880 --> 00:08:59,010
And you can see it does lose a lot of information.

139
00:08:59,070 --> 00:08:59,850
It doesn't look.

140
00:09:00,060 --> 00:09:03,270
It looks a bit blurry compared to the original image.

141
00:09:03,400 --> 00:09:10,920
You can see that the details, like in the little walls and windows, is a bit blurry or no, not significantly

142
00:09:10,920 --> 00:09:11,190
so.

143
00:09:11,970 --> 00:09:13,220
And we can do it even more.

144
00:09:13,620 --> 00:09:15,210
But I didn't actually go through this lens.

145
00:09:15,630 --> 00:09:18,090
But what we did here, we actually went.

146
00:09:18,090 --> 00:09:22,330
It went even smaller by actually shrinking it down, shrinking out a smaller image.

147
00:09:22,330 --> 00:09:28,020
So this is Courtnall quarter size of the original image, and you can see it's quite blurry right now.

148
00:09:28,530 --> 00:09:33,420
It's a 200 pixels by three something pixels to something extra something.

149
00:09:34,170 --> 00:09:36,150
So now let's take a look at cropping.

150
00:09:36,150 --> 00:09:42,990
Cropping is a very, very useful technique in computer vision, especially with object detectors or

151
00:09:43,020 --> 00:09:46,710
OCR, where you have to crop segments out of an image.

152
00:09:47,310 --> 00:09:53,790
So how it is cropping with cropping is basically done just actually by using them, by slicing.

153
00:09:54,120 --> 00:09:54,450
OK.

154
00:09:55,710 --> 00:09:56,550
Arrear slicing.

155
00:09:57,030 --> 00:09:59,430
So basically slicing when it is slicing, it means that it is.

156
00:09:59,840 --> 00:10:05,360
Ticking and ticking sections of the era, extracting sections of the array list out.

157
00:10:05,990 --> 00:10:07,190
So how do we do that?

158
00:10:07,340 --> 00:10:08,290
We can actually do it.

159
00:10:08,300 --> 00:10:10,160
Let's quickly go through this year.

160
00:10:10,700 --> 00:10:14,420
So what we're doing here, we're going to heighten wit here.

161
00:10:14,450 --> 00:10:19,250
And the only reason we're getting to Python, which here is because we want to get to start row and

162
00:10:19,250 --> 00:10:24,190
start column here for the cropping that we're going to do so to cropping.

163
00:10:24,200 --> 00:10:25,460
I'll explain cropping shortly.

164
00:10:26,060 --> 00:10:30,700
The section of the middle of the image out from point to five point twenty five two point seventy five

165
00:10:30,710 --> 00:10:31,830
one seven five of the image.

166
00:10:31,830 --> 00:10:36,710
So a quarter basically decent centre crop is what we're trying to do right now.

167
00:10:37,250 --> 00:10:38,290
So this is a line.

168
00:10:38,330 --> 00:10:41,270
Yeah, I need you to pay attention to this line right here.

169
00:10:41,900 --> 00:10:48,620
So this line tells us this is the image here, the input image we're doing, and we're using index indexing

170
00:10:48,620 --> 00:10:53,960
functions, indexing abilities of way to basically get that part of out of out of it.

171
00:10:54,110 --> 00:10:58,220
So we have start row here, which is going to be the height of 0.05.

172
00:10:58,700 --> 00:11:01,340
The end rule, which is the high times, went seven five.

173
00:11:01,730 --> 00:11:03,740
So we're cropping that section here.

174
00:11:03,950 --> 00:11:05,270
And then similarly here.

175
00:11:06,020 --> 00:11:07,790
So I just call these variables.

176
00:11:07,880 --> 00:11:13,670
This here, this actually can be actual numbers if you wanted to put in from the value from the image

177
00:11:13,670 --> 00:11:13,880
here.

178
00:11:14,480 --> 00:11:19,760
So let's just run this now and what we're going to do after we crop the image out.

179
00:11:20,230 --> 00:11:20,930
Call it cropped.

180
00:11:21,680 --> 00:11:28,040
We're going to take that cropped image here, and we're going to actually draw a rectangle around this

181
00:11:28,040 --> 00:11:31,100
onto crop just to basically show the area we cropped out.

182
00:11:34,830 --> 00:11:35,850
So this is it.

183
00:11:36,540 --> 00:11:36,930
So.

184
00:11:38,790 --> 00:11:39,330
Let's take a look.

185
00:11:39,720 --> 00:11:40,710
Sorry for all the screwing.

186
00:11:41,880 --> 00:11:43,320
This is the original image here.

187
00:11:43,710 --> 00:11:45,690
And remember I said, we're going to take a rectangle.

188
00:11:46,140 --> 00:11:50,640
The rectangle basically is just throwing a yellow block over the area we cropped out.

189
00:11:50,730 --> 00:11:51,930
So this is your of away.

190
00:11:51,930 --> 00:11:56,250
So I wanted to go one two five down two point two seven point seventy five down.

191
00:11:56,820 --> 00:11:57,820
So let's take a look.

192
00:11:57,840 --> 00:12:02,850
That's exactly what we did point to five here, two point seventy five here of the image and in terms

193
00:12:02,850 --> 00:12:08,580
of ratios from the when the width and height and we were just displaying it.

194
00:12:08,590 --> 00:12:11,100
Now this is the full crop here.

195
00:12:11,130 --> 00:12:11,790
We dropped out.

196
00:12:12,510 --> 00:12:13,380
So that's it.

197
00:12:13,380 --> 00:12:14,340
That's it for cropping.

198
00:12:14,370 --> 00:12:15,660
Hope you enjoyed this lesson.

199
00:12:16,140 --> 00:12:20,460
In the next section, we'll take a look at arithmetic and Bitwise operations.

200
00:12:20,730 --> 00:12:21,960
So stay tuned for that.

201
00:12:22,020 --> 00:12:22,470
Thank you.
