1 00:00:00,270 --> 00:00:03,640 So far, we've only talked about the image module. 2 00:00:03,640 --> 00:00:06,580 And the image module lets us do quite a bit of stuff, but 3 00:00:06,580 --> 00:00:10,100 maybe we want to do some enhancements or we want to do some filters. 4 00:00:10,100 --> 00:00:15,495 So, if those are the case, we should look at how to do enhance. 5 00:00:15,495 --> 00:00:19,130 ImageEnhance lets us do things like sharpen an image, change the color, 6 00:00:19,130 --> 00:00:21,550 change the contrast, stuff like that and 7 00:00:21,550 --> 00:00:26,670 the filter module lets us do things like blurring or EMBOSSING, Gaussian blurring. 8 00:00:26,670 --> 00:00:31,900 They give us a little bit of Photshopy abilities inside Pillow. 9 00:00:31,900 --> 00:00:35,340 They're not necessarily as powerful as Photoshop, so 10 00:00:35,340 --> 00:00:36,640 don't think they are a replacement for it. 11 00:00:36,640 --> 00:00:40,600 But they're a good way to apply small effects to images. 12 00:00:40,600 --> 00:00:42,130 So we need to go ahead and import them. 13 00:00:42,130 --> 00:00:43,830 So from_PIL import. 14 00:00:43,830 --> 00:00:45,025 Let's just import both of them. 15 00:00:45,025 --> 00:00:51,341 ImageEnhance, ImageFilter. 16 00:00:51,341 --> 00:00:53,544 All right. 17 00:00:53,544 --> 00:00:55,890 So, first let's do an ImageEnhance. 18 00:00:55,890 --> 00:01:00,950 So I think that our balloons could be more interesting if they were desaturated, or 19 00:01:00,950 --> 00:01:02,650 at least partially desaturated. 20 00:01:02,650 --> 00:01:03,690 Put them closer to gray. 21 00:01:03,690 --> 00:01:08,330 So we need to instantiate a color enhancer for this image. 22 00:01:08,330 --> 00:01:09,990 This is a little bit of a weird interface, 23 00:01:09,990 --> 00:01:12,970 but it makes a lot of sense once you get used to it. 24 00:01:12,970 --> 00:01:19,670 So we'll say balloons_enhancer is an ImageEnhance.Color. 25 00:01:22,310 --> 00:01:25,860 And then the image that we want it to work on is the balloons image. 26 00:01:27,410 --> 00:01:35,280 And now we can apply the enhancements, so we can say balloons_enhancer.enhance. 27 00:01:35,280 --> 00:01:37,000 And then, how much do we want to do it? 28 00:01:37,000 --> 00:01:38,310 What's our factor? 29 00:01:38,310 --> 00:01:42,300 So if we do 0.0, or just 0, that'll make it all the way grey. 30 00:01:42,300 --> 00:01:47,230 If we do it at 1, it'll be the regular full color image that it already is. 31 00:01:47,230 --> 00:01:53,510 So let's go half way saturated, let's say 0.5, then we'll say to show this. 32 00:01:55,070 --> 00:01:58,630 And we get a nicely desaturated image. 33 00:01:58,630 --> 00:02:01,060 Our greens, our golds are no where near as bright as they were before. 34 00:02:01,060 --> 00:02:05,150 We've got a bit of a maybe a bit of an Instagram, hipstery feel to it. 35 00:02:05,150 --> 00:02:08,350 You could, of course, create your own Instagram with this kind of work. 36 00:02:09,600 --> 00:02:12,760 All right, there are some other enhancements that you might want to check 37 00:02:12,760 --> 00:02:15,160 out inside the enhance module here. 38 00:02:15,160 --> 00:02:16,800 That's the only one I'm going to show you. 39 00:02:16,800 --> 00:02:20,910 But like contrast would let you, again, move it toward gray, brightness would 40 00:02:20,910 --> 00:02:25,280 let you move it up or down, and sharpness would let you sharpen it. 41 00:02:25,280 --> 00:02:27,420 Notice that sharpness goes up to 2.0, 42 00:02:27,420 --> 00:02:30,200 whereas the other ones only go between 0 and 1.0. 43 00:02:30,200 --> 00:02:33,430 Good idea to play with these a little bit. 44 00:02:33,430 --> 00:02:36,410 All right so now let's talk about filters. 45 00:02:36,410 --> 00:02:39,430 So most of these filters are kind of obvious, 46 00:02:39,430 --> 00:02:41,520 find edges, smooth, stuff like that. 47 00:02:41,520 --> 00:02:44,780 Let's play with this Gaussian blur cuz this one's fun. 48 00:02:44,780 --> 00:02:48,110 So we're gonna take that out. 49 00:02:48,110 --> 00:02:52,000 And yeah, so like I said, it's kind of like a code driven Photoshop. 50 00:02:52,000 --> 00:02:54,780 So let's take our ribbons image and let's blur that. 51 00:02:54,780 --> 00:02:57,830 So we'll say ribbons.filter. 52 00:02:57,830 --> 00:03:01,030 Filter is a method on the image class and 53 00:03:01,030 --> 00:03:03,200 there's all sorts of filter stuff in there. 54 00:03:03,200 --> 00:03:07,610 But the easiest way to do it is to use the image filters along with it. 55 00:03:07,610 --> 00:03:12,870 So we'll say ImageFilter.GaussianBlur and then we get to specify a radius. 56 00:03:12,870 --> 00:03:16,510 And let's say the radius is 10 pixels and then show. 57 00:03:16,510 --> 00:03:18,460 So we blur ever pixel by 10 pixels. 58 00:03:20,470 --> 00:03:23,600 And when we run that it takes a little bit of time to run that. 59 00:03:23,600 --> 00:03:27,590 But you can see now that we have a very nicely blurred image. 60 00:03:27,590 --> 00:03:28,840 So, cool. 61 00:03:28,840 --> 00:03:29,460 That's kind of neat. 62 00:03:30,530 --> 00:03:31,890 All right. 63 00:03:31,890 --> 00:03:34,500 So that's how we use the Gaussian blur one. 64 00:03:34,500 --> 00:03:35,980 The rest of them all work the same way. 65 00:03:35,980 --> 00:03:39,810 If you look down through here there's like unsharp mask there's other stuff. 66 00:03:39,810 --> 00:03:42,170 These are all going to work. 67 00:03:42,170 --> 00:03:42,730 The same way. 68 00:03:42,730 --> 00:03:45,830 You'll just specify what things you want to put in. 69 00:03:45,830 --> 00:03:48,760 But then, these up here are some predefined ones. 70 00:03:48,760 --> 00:03:52,350 So let's check out, we'll say the EMBOSS one. 71 00:03:52,350 --> 00:03:56,180 So we'll go back over here, and actually I want to do this one to the balloons. 72 00:03:56,180 --> 00:03:59,880 I think that might be a more interesting thing. 73 00:04:00,970 --> 00:04:04,280 And so instead of this GaussianBlur(radius=10), 74 00:04:04,280 --> 00:04:06,880 we're just going to do EMBOSS. 75 00:04:06,880 --> 00:04:08,270 All in caps. 76 00:04:08,270 --> 00:04:09,470 Like an EMBOSS, right? 77 00:04:10,490 --> 00:04:16,390 And that gives us this amazing [LAUGH] and super useful image. 78 00:04:16,390 --> 00:04:18,670 Actually I'm not sure this is useful at all. 79 00:04:18,670 --> 00:04:19,780 And then it shows you where the edges are. 80 00:04:19,780 --> 00:04:21,740 That can be really handy depending on what you're trying to do. 81 00:04:21,740 --> 00:04:23,830 Maybe you're trying to detect faces or 82 00:04:23,830 --> 00:04:26,870 something like that, letters, words in a sign. 83 00:04:27,900 --> 00:04:31,970 I don't know when this would be useful but if you ever need automated embossing, 84 00:04:31,970 --> 00:04:34,430 then we definitely have that available. 85 00:04:34,430 --> 00:04:36,909 So Pillow let's us do quite a bit with images. 86 00:04:37,910 --> 00:04:40,430 I did not mean to push tha button. 87 00:04:40,430 --> 00:04:42,400 Pillow lets us do quite a bit with images. 88 00:04:42,400 --> 00:04:46,910 Its really handy and its definitely a tool that I'm happy to have in my back pocket. 89 00:04:47,990 --> 00:04:50,680 Pillow gives you a ton of power over images. 90 00:04:50,680 --> 00:04:53,490 I've used it to create thumbnails, rotate images back to the proper 91 00:04:53,490 --> 00:04:56,070 orientation that they are rotated in the camera, and 92 00:04:56,070 --> 00:04:58,440 do some interesting color effects in the past. 93 00:04:58,440 --> 00:05:02,499 If you want to do more with image formats, check out the movie.pie library too.