So now let's begin section six.
So this one is titled Scaling Resizing into positions and cropping, so let's open this up and wait
for it to load and should be here by now.
There it is.
So what we're going to do in this lesson, we're going to actually look at resizing and scaling images.
Now that sounds like two different things, and technically it's not.
But basically, it's just changing the size of the image.
So it opens.
TV has a function called CV to door to resize, and that's what we're going to take a look at first.
So this function is quite useful, and there's many different ways to resize images which might not
might be surprising to you.
But we'll take a look at a few of those ways right now.
So firstly, we have let's look at this function here.
Let's look at what the resize to function does.
So we have this here and highlighting that view.
So we have the input to the image here.
We have this size, this size, which is the output image size.
If we want this design, some sense for dimension here.
So we can specify actual dimensions of here, or we can have the X y scale here, as well as the interpolation
method.
So that could something a bit confusing.
So let's take a look at this.
So the interpolation methods here they are into area, into nearest, into linear, into cubic and Lonzo
Lonzo Sorry four, which is supposedly the best resizing algorithm.
So let's just test these out shortly.
OK, so that actually this can happen to you guys.
So it's a good thing.
This lesson as I'm shooting this lesson club only allows you to open five notebooks at the same time.
So because we're no longer using one to three and four, this just closes off too many of them and go
back to this year.
So now, because we're only allowed to connect to five virtual machines remotely on the cloud, so we
so we don't abuse the resources that collab offers us so nicely for free.
So we've downloaded all images and imported our libraries, so I just rehash what the types of methods
here, huh?
This blog go on Chadwick sites and the site here by Chadwick Todrick.
I should say he has some nice examples of the different resizing methods.
Here you can take a look.
This is basically the input image here.
This is Zoom in a bit.
All right.
Um, so this is a default image, 50 by 50.
And these are the results by reducing the size to 15 by 15.
So you're shrinking the size.
So we're reducing the quality of only 15 by 15.
But we're using a few different interpolation methods to generate this here.
So this is the entire area, how it looks into cubic, into Lonzo's and into nearest and into linear.
So you can see, I think, the best ones, probably into Quebec and into Nereus in this case here into
Lonzo's is quite good as well.
So these are of examples of these different interpolation methods being used here, and you can see
even enlarging the images here when it's actually had a fairly good quality already.
So we enlarge that image now to 150 to 50 to 100.
And you can see what looks, how it looks here.
So what is interpolation actually doing?
So I didn't actually explain it well, actually didn't explain it at all.
Interpolation is basically how is an algorithm to find a value between two points?
Let's take a look at this slide here.
Just briefly bringing this up in during the lesson that can actually put some of this can put this picture
into the lesson that I place in the book for you guys afterward.
So you can see, let's take a look at what interpolation actually is.
So imagine we have a GPS that's logging coordinates as we move along this road of here.
So you can see we took this corner at this point here.
However, we didn't log this green point here.
This is where the actual path was.
So interpolation is going to guess a point in between these two red points that the yellow yellows are
basically the guesses between the points as it moves along.
So it's a way of actually adding more data to existing data to interpolated means as to connect the
ones in between.
So now going back to our lesson here, that's basically what interpolation methods do.
There is when we resize an image, when we enlarge the image, we now have two kind of guests the pixels
that are going to be there that aren't there right now.
Remember, we way we're trying to make.
Let's go back to this blog.
We're trying to make enlarge this image here.
Actually, this is this is the original image here and trying to guess the points it's going to be take
in a new dimension.
So the quality that it's being done is quite important, so into cubic and into these methods.
These are these different formulas that use to apply to actually interpolate and guess the values that
it should be there.
When I say guess, I mean.
Algorithmically, guess the best guess so we can actually get so some in some ways basically looks at
averaging over different pixels in four different areas that's put into cubic does nearest basically
mirrors into political neighborhood pollution.
I'm not going to explain all of these because they actually can get quite technical.
So what are we going to do?
We're just going to resize images in a few different ways here.
So I like resizing a lot.
It's actually quite a useful operation because when you resize an image, we reduce its size.
You actually can speed up a lot of photo operations afterward.
So it's quite a good efficiency technique while you do lose some information.
If you if you use a good interpolation algorithm, you should do what you generally lose a lot from
actually scaling down.
So let's take a look at this.
So the first case here, what we're going to do, we're going to use the argument effects and f way
to reduce the size of an image by 75 percent 0.75 off the original image.
What are we going to do in the second one now?
We're going to double it by using effects equal to fly equal to.
And we're going to use the different interpolation methods doing that twice and then what we're going
to do.
We're going to use the dimensional method, which is actually very useful.
Oftentimes, when, especially when, when you want to keep the aspect ratio off an image, the same
is actually not always possible.
Actually, there's possibilities of what to keep the values the same here, but this is actually quite
good if you actually need to fix a size.
Quite like a function requires image to be an exact size, exact specific size, and you can resize
it.
You can resize any image that size by using this this method here.
So you can just run this here, and we just generally going to resize so images a few times.
So this is with linear interpolation here.
This is the point seventy five scaling right here from the original image.
You can see it doesn't really lose much information, but you can see, though, even though it looks
and looks like the same size.
The pixels go up to 960 here, but now it goes up to 720.
And if you look carefully at a sign this, this zoom into the sign a bit, you can see it's probably
depends on the internet connection and how good your resolution is at your streaming lesson.
But you can see that it actually is lower quality here, especially these words and this less this line
right here compared to this one.
So that's what the resizing did.
Now what are we going to do?
We're going to double the size now.
Now we shouldn't actually get any information mode of it to just look better and bigger when it's printed.
Perhaps that's a good way to a good reason to resize images for printing purposes and scaling the area
can see when we scale.
It's that weird size it actually affected aspect ratio.
So depending on what you need to do, just remember that when you resize to a specific dimension.
So, no, let's move on to using image pyramid's image.
Pyramids are much quicker operation, and you're a quick way to actually scale up a scaled down image.
Basically, double or half the size so you can see this PR people are down.
Pyramid Down takes the image and reduced it to half its size.
Then it actually.
Then we can actually take the same smaller image input and give it back up here.
That would probably give us a pixelated image, which you will see below shortly.
So let's run this function here and see what what we have then.
So let's take a look at this.
So we have the original image here.
We scaled it down here, half the size, so you can see that's half the dimensions of snow 450.
And no, this is the one that was scaled back up.
So we took a smaller image here and then made it bigger again.
And you can see it does lose a lot of information.
It doesn't look.
It looks a bit blurry compared to the original image.
You can see that the details, like in the little walls and windows, is a bit blurry or no, not significantly
so.
And we can do it even more.
But I didn't actually go through this lens.
But what we did here, we actually went.
It went even smaller by actually shrinking it down, shrinking out a smaller image.
So this is Courtnall quarter size of the original image, and you can see it's quite blurry right now.
It's a 200 pixels by three something pixels to something extra something.
So now let's take a look at cropping.
Cropping is a very, very useful technique in computer vision, especially with object detectors or
OCR, where you have to crop segments out of an image.
So how it is cropping with cropping is basically done just actually by using them, by slicing.
OK.
Arrear slicing.
So basically slicing when it is slicing, it means that it is.
Ticking and ticking sections of the era, extracting sections of the array list out.
So how do we do that?
We can actually do it.
Let's quickly go through this year.
So what we're doing here, we're going to heighten wit here.
And the only reason we're getting to Python, which here is because we want to get to start row and
start column here for the cropping that we're going to do so to cropping.
I'll explain cropping shortly.
The section of the middle of the image out from point to five point twenty five two point seventy five
one seven five of the image.
So a quarter basically decent centre crop is what we're trying to do right now.
So this is a line.
Yeah, I need you to pay attention to this line right here.
So this line tells us this is the image here, the input image we're doing, and we're using index indexing
functions, indexing abilities of way to basically get that part of out of out of it.
So we have start row here, which is going to be the height of 0.05.
The end rule, which is the high times, went seven five.
So we're cropping that section here.
And then similarly here.
So I just call these variables.
This here, this actually can be actual numbers if you wanted to put in from the value from the image
here.
So let's just run this now and what we're going to do after we crop the image out.
Call it cropped.
We're going to take that cropped image here, and we're going to actually draw a rectangle around this
onto crop just to basically show the area we cropped out.
So this is it.
So.
Let's take a look.
Sorry for all the screwing.
This is the original image here.
And remember I said, we're going to take a rectangle.
The rectangle basically is just throwing a yellow block over the area we cropped out.
So this is your of away.
So I wanted to go one two five down two point two seven point seventy five down.
So let's take a look.
That's exactly what we did point to five here, two point seventy five here of the image and in terms
of ratios from the when the width and height and we were just displaying it.
Now this is the full crop here.
We dropped out.
So that's it.
That's it for cropping.
Hope you enjoyed this lesson.
In the next section, we'll take a look at arithmetic and Bitwise operations.
So stay tuned for that.
Thank you.