 Hey guys welcome back to another python image library tutorial in this video I'm to try and synthesize a lot of the stuff we've learned in Well, I guess not a lot of the stuff that we've learned in other videos But one of the crucial things that we learned and of course introduce some new stuff to you Hopefully this video is going to be a little bit longer than the others because I do want to show you more stuff So initially what I want to start off things Off the bat with is this split function now this split function Of course lives in our image object and what this does is it returns a Tuple of other images and it's it's a little interesting in that way because what it does is it returns a tuple of Individual bands from the image and when I say band I'm referring to like r g and b each of these things Red green and blue are bands. They are different color attributes and color properties in the image and What this does is it will kind of give us them along with alpha, of course, so It's it's important to know what the mode of the image is because that'll determine If you'll be returned r g and b or alpha along with it or even other things like Simple black and whites or just a symbol a single band it is entirely up to the mode of the image So if I were to try and run this if I were to try and show you what this returns It's interesting because it'll tell us that okay the self dot. I am dot bands is It's a non-type. It doesn't have any attribute bands And this isn't in our code. This is in the actual Python image library source code so This is where the image library is a little funky because it gets kind of lazy In a previous tutorial, I told you that the load function, you know the Image dot load would return a pixel access object at least in versions 1.1.6 and later and this pixel access object pixel access object Allowed us to like get and set pixels in the object and in the image with these coordinates and indexing in a list And that's a good thing But also what this function does is it allocates storage for the image and loads it from the file Now normally you don't need to call this method because the open function will do it to begin with But sometimes it doesn't like I said the image module gets a little lazy So if we want to run the split function, we need to call image dot load Before we call image dot split So now if I run this you'll see it works And of course we're getting returned a tuple of three different kinds of images Actually four because we have our alpha values. So here if I were to set image to equal Let's say the first index of this if I run this you'll see that whoa My modified Python file has the bands that we had for all of the red colors if I go back to this We can do the same thing with green Run this now. There's a little bit more to it The same thing with blue. Oh it would help if I actually ran the code You can see it changed there And Alpha of course is going to be a little bit different check it out Not run the code John come on See now you get a whole different thing entirely because our alpha values So what I want to do at this point is actually merge these things together So this is where it's interesting because I'm going to save all of these bands red green blue and alpha And I'm going to put some of them together R G and B are the ones that I want. Let's say I don't want this alpha value anymore I just want a typical image that doesn't have transparency So what I can do is I can say image equals image dot merge Now this is going to create it simply with R, G and B values But no alpha value anymore. So if I run this code, let's see Okay, I'm wrong here I should be using the capital I image because this is within the module. So There we go Capital image capital I image because this is the module not the actual image We've got opened up for us. Now if I run this merge takes exactly two arguments three given Okay, okay, of course it takes the mode that we actually want to set here RG B which is going to be a string for the mode RGB and a the tuple a Tuple of the bands that we want to put to it and we just got these bands from the initial image object That we just split up and now we put it back together with the merge function So now if I run this there we go no more arrows No more errors and we've got this image that we the same thing when we had before but there is no alpha channel to it There is no transparency in it If I run this actually, I'll try and show you here If I print image dot get data Okay, the game will loop through it for color in image dot get data can I Print that color there we go You see all the bands that are shown here. Okay, I might want to kill this before it kills my text editor Thank you all the bands here. We've got all this white, but we don't have any alpha There is no transparency and when we get to the actual image, of course like the Python shape in the Python logo. There is still no alpha band. There is no transparency transparency RGB, but not RGB a Now what I passed into this merge function is a string that determines mode and We've seen this before or at least I guess I haven't shown you guys But all of these things that all the images that are created have a certain mode if I were to print I'll see do it after our image load function call If I were to print image dot mode It would tell us that yeah, this is an RGB a and that's a string now Of course, you know whenever we create an image like image to Equals image dot new we need to pass in a mode which is either RGB RGB a or anything else that we set for it. So There the image has a property it has Image dot mode and this is going to determine what the image is right now. So if I print this out That's the mode there now that we've recreated the image by merging the three bands RGB And it's got this mode if I print it out here image dot mode Now you can see it's RGB with our with no alpha channel with no alpha band with no transparency So okay three things we kind of covered in this video. We got image mode we got image split that sets it up in and it kind of separates all the bands And then we've got image merge Capital I consists within the module it creates a new image with the bands that you supply and the mode that you supply and None of this will work or at least not split Split won't work without image dot load. So a little bit more to it here I'm at least more than I want to show off But that's the way that we can strip an alpha channel strip other channels from it By just kind of taking what we want from split and of course you can kind of play with this, right? You can say. Oh, I don't know be Yeah, GBR set things in a different order. What do we get? Whoa? I got a funky looking Python logo You have a whole lot of options here for what you want to at least toy with if you do want to toy with things BG So I don't know mess around have fun But the point of this video and what I wanted to show you was mode split merge And of course load to be able to run split. So, okay, thanks for watching guys I know this was a little bit of a longer one, but I think that's a good thing Hey, I hope you're enjoying the series and I hope you're enjoying the cool stuff You can do with this library. So thanks everybody. I'll talk to you later