So now let's take a look at the second lesson in this open TV chapter, and that's called grace killing
images.
So let's open this file by double click and it's on.
It's here and it opens the notebook and a new window, as you can see.
We don't need to see this.
So welcome to this lesson.
So this lesson is quite simple.
What you're going to learn to do is tick a color image, color image and convert that image into a grayscale
image.
Which song is simple?
And it's actually it is very simple and open TV.
So let's import our libraries like we did before we're importing Bud CB2 and Mark Gottlieb.
Together, you'll see the convention in Python is actually to import all your libraries at a top of
a notebook, followed by a Python file.
So we will do that and most of our lessons from now on.
So you can see we've expanded the function a bit here, the lines that are new.
Basically, these three lines here.
So what's different about this is that we're getting the height, the width and height from the image
here, from the image, it's passed in the function.
We're keeping two aspect ratio.
We're getting the aspect ratio here because I think the width divided by the height and we do that because
we want to actually have a parameter called size that controls the figure size of this image.
But to ensure that the aspect ratio is maintained, we keep the aspect ratio here as an argument.
So we have size times, debt and size him so that size.
This is the arguments for the fixed size part of ModCloth Lib.
So you don't need to know too much about MATLAB.
You just need to know that this is how we adjust to figure size here, and this is how we mentioned
the aspect ratio of our image here.
So let's go ahead and run this.
We've declared our function.
We've done little files like we did in the previous lesson.
So the image we're going to learn is a place in Tobago.
That's my home country, Trinidad and Tobago.
It's a beautiful beach called Star Beach.
This is actually part of costar of Beach called Heavenly Bay.
So we're going to load this image here and display below like we already have are seeing there.
And you can see we didn't have the size argument here.
So now let's put in this size argument right now.
But size equal to let's try six.
And you can see it's going to be displayed much smaller than previously.
The default is 10.
So if you leave it out entirely, it uses 10 as the default in that function.
So that's pretty cool.
So now let's move on to Greece dealing damage, so it wasn't going to go ahead and preview that what
images looks like, what I'm going to do actually might as well, because this could might be easier
to see if it's in the middle of the screen for you guys.
So what we do here, remember the key to this CVT dot?
Sorry to see v2 dot CVD, the tea color function.
Remember, we changed it from BGR to RGV in the function here.
As you can see, CVT color, we couldn't fitting into BGR to RGV.
What we're going to do now is convert it into gray.
BGR to Gray is a lot of these built in conversions into different color spaces and is a lot of them
built into open TV?
You wouldn't need a lot of them unless you're doing something special.
What we do is we do use a few of them in this course and you'll encounter them occasionally.
So this color function, this basically just takes two arguments, as you saw previously the image,
that's what we look at here.
You can see it's easy to read.
We've loaded this image and stored it as a variable here.
And and now the other argument is basically the conversion code here.
So we've called in this new image that created.
We're calling it gray image.
So now let's display gray image using our major function, and we give it a nice little title converted
to grayscale.
And we can see it looks a lot less pretty in black and white, but that's how it is.
That's grayscale.
Now what is grayscale actually mean?
Do you remember RGV has true dimensions red, blue and green?
Well, in grayscale is just one dimension.
It's an intensity of gray or black, or that red color range between the white and black.
So as you can see, let's assume in a bit here, you can see that this is the number one that was handwritten
by me, actually.
And you can see these are the color codes here.
You can see two, when it's took 55 to 55 is the range of all colors and off into it, skill is zero
to 255.
Zero is black.
You don't even see the zeros here because they're actually black as well.
But the numbers zero, but at zero mean jurors absence of light.
Totally black.
However, white is the maximum color.
That's 255 because that's orange 256 numbers zero to 255.
So you can see 255 is pure white.
And as you come down like 227, it's a lighter shade than 220.
170 is darker and 90 you want is quite darker.
68 is much darker.
This one is probably 20 or 30.
So you can see the colors there.
So that's how grayscale.
That's how we actually display grayscale images.
It's just all these three dimensions here now compressed into one dimension.
So to Grayscale, the image open TV takes the average of the red, green and blue colors, and this
uses that as a final intensity here.
So again, we get this through the shape.
I don't know why I actually put this into the lesson.
If you just wanted to see the shape, the ship is consistently to seem to agree.
The scaling doesn't change, and that's it for this lesson.
So in this lesson, we just learned a very simple way to just to convert an image to grayscale.
Nothing too amazing, but it's actually a very handy function in OpenCV.
And that's because a lot of other functions can only take grayscale images as inputs.
So hopefully you found this important and and you take away a valuable lesson from this, this dissection.
So now let's move on to the third section.
So stay tuned.