All right, enough talk.
Let's process some images and use our Python knowledge.
Now, you might be thinking that image processing is something that you can do on your machine using
something like Photoshop, even using a simple editing software.
But where this tool really shines is when we have to process hundreds, thousands of images.
You can do things really, really fast with Python.
So let's get started with this.
I've actually attached to this lesson a pokédex for you.
And this pokédex has all these cute little pokemon's.
We have bulbasaur, we have Charmander, we have Pikachu, we have Squirtle.
It's great.
They're all extremely cute.
And by the way, a little bonus just for taking this course.
No other course is going to teach you this.
Get ready for it.
You ready?
Bob Bazaar original name in Japanese is for Shiki.
Charmander.
Well, charmander is Itokawa.
And then Pikachu, while Pikachu is just Pikachu, and then Squirtle is Xenia.
There you go.
Free Japanese lesson bonus for this Python course.
Yes.
This is that good of a course.
All right.
Let's get back to some serious stuff.
We have these images.
Let's see what we can do with them.
I'm going to have an image file so you can just create this on your own.
And I'm using sublime text here in my command prompt, but you can use whatever you want.
And what I'm about to show you is something that remember you can always reference in the official documentation
when learning a library.
There's nothing better than the official documentation, right?
And we see over here that the first thing we need to do is to actually import the module just like this.
So let's go back here and say from Pil.
Import image.
So now we can do something pretty exciting.
The first thing we can do is say image equals.
The image that we've imported and just simply say, open.
Now in here, we just give it a file path that we want to open.
In our case.
Let's open up Pikachu JPEG.
So I'm going to say.
Dot slash, which means current directory.
And remember, we're in the image playground directory and I want to go inside of the Pokédex folder.
So I'm going to say Pokédex.
And say slash.
Pikachu.
Make sure I spell Pikachu right here.
Dot jpeg.
And let's just print the image here to see what we get.
Going to save and run this file.
So I'm going to say.
Python.
Three and run the image dot pie file.
Images.
Dot pie file because that's the name.
There you go.
We get an object here.
You see, it's a pill object.
It's a JPEG image plugin, JPEG image file, and it tells me exactly what it is.
So we've converted or opened up this JPEG into an image object that pillow gives us that we can now
manipulate.
So what can we do here?
Well, first let's just see the image dot format and this property is going to say, hey, what is image
format?
Image format.
It's a JPEG because.
Well, it's a JPEG.
That's awesome.
So we get different properties here.
What about size?
Can you tell us about the size?
Well, yeah, the size of the image is 640 by 640.
Awesome.
That's good.
We get some information.
What if we do moat here?
What does Moat do?
Let's see.
Now we see that the colouring is in rugby.
So that's red, green, blue.
All right.
Awesome.
Let's clear the console here.
There you go.
Now, remember, we're able to figure out what kind of functions, methods, properties and attributes
this image has by doing the command.
Right.
So if I just remove this.
And DuJour over the image.
We get well, all the things that this image has given to us.
And again, this is something that we can check on the documentation websites as well.
But let's do something even more exciting.
You know what I want to do?
I want to be able to maybe add some filters, maybe blur things in here.
Well.
Pillow gives us this image filter.
That we can now filter the image with.
So how can we use it?
Well, we can now have a filtered.
Image.
And this filter image is going to equal the image that we've grabbed and we're going to say dot filter
and in here give it the image filter with some options.
So here we can do different things.
Let's do blur here.
So capital blur.
So now it's going to apply a filter of blurring.
So let's see what happens if I do this.
I'm going to instead of printing, I'm actually going to say image.
Dot save and this is going to save the filter damage.
So let's do filter damage save.
And give it.
Let's call it.
Blur.
Comma and then the extension that we want to save it in.
Let's just do P&G here.
We'll change it to a P&G file.
Like this.
And if I run this.
Look at that.
We have a new file bleu pag here.
If I click on it, pikachu is all blurred up.
You can see the original image right here.
Then the blurred image.
How cool is that?
So let's do that again.
Let's do something else.
Let's do maybe.
Smooth, which is another filter that we can do.
If I run this again.
All right.
We see that the image is now.
Well, you can't really tell, but it's smoother.
That's a filter that usually works better with landscape images.
We can also do something like Sharpen and again, you can read the documentation to see different filtering
so that we can do.
But let's check this one out as well.
We got the original and then the sharpened one.
There you go.
There's a bit of a notice.
Pikachu is looking very, very sharp.
Now, the reason that I've converted this into a P&G is because P&G supports these image filters.
So you might get an error if you actually keep it as a jpeg.
And you know what?
While we're at it, let me show you another thing that we can do.
So instead of this filter image, we can actually do something called convert.
And this converts the image to different formats.
So one of the formats that we can actually do is something called grayscale, which is with a capital
L.
So when I do convert like this, this image and let's rename it to Gray Dot, P&G, if I run this.
My great pag oop.
Pikachu is in black and white.
So you can also convert images to different formats.
So remember we had the GB Red, Green, Blue format.
There's different formats that you can convert images to, but this one looks pretty cool.
We've just grayed out Pikachu.
Now, this is just one picture that we worked with.
But the power and what I'm going to show you in the upcoming videos is how we can apply, let's say,
a function like this.
To hundreds and thousands and millions of images if we want, and process them really fast.
But for now, I think this is enough.
You can experiment and try different converts and try different image filters on your own.
And we're going to learn some more in the next video.
Bye bye.