|
| https://realpython.com/ |
| Start Here | https://realpython.com/start-here/ |
|
Learn Python
| https://realpython.com/lessons/python-pillow-image-processing/ |
| Python Tutorials →In-depth articles and video courses | https://realpython.com/search?kind=article&kind=course&order=newest |
| Learning Paths →Guided study plans for accelerated learning | https://realpython.com/learning-paths/ |
| Quizzes & Exercises →Check your learning progress | https://realpython.com/quizzes/ |
| Browse Topics →Focus on a specific area or skill level | https://realpython.com/tutorials/all/ |
| Community Chat →Learn with other Pythonistas | https://realpython.com/community/ |
| Office Hours →Live Q&A calls with Python experts | https://realpython.com/office-hours/ |
| Podcast →Hear what’s new in the world of Python | https://realpython.com/podcasts/rpp/ |
| Books →Round out your knowledge and learn offline | https://realpython.com/products/books/ |
| Reference →Concise definitions for common Python terms | https://realpython.com/ref/ |
| Code Mentor →BetaPersonalized code assistance & learning tools | https://realpython.com/mentor/ |
| Unlock All Content → | https://realpython.com/account/join/ |
|
More
| https://realpython.com/lessons/python-pillow-image-processing/ |
| Learner Stories | https://realpython.com/learner-stories/ |
| Python Newsletter | https://realpython.com/newsletter/ |
| Python Job Board | https://www.pythonjobshq.com |
| Meet the Team | https://realpython.com/team/ |
| Become a Tutorial Writer | https://realpython.com/write-for-us/ |
| Become a Video Instructor | https://realpython.com/become-an-instructor/ |
| Search | https://realpython.com/search |
| https://realpython.com/search |
| Join | https://realpython.com/account/join/ |
| Sign‑In | https://realpython.com/account/login/?next=%2Flessons%2Fpython-pillow-image-processing%2F |
| Unlock This Lesson | https://realpython.com/account/join/?utm_source=rp_lesson&utm_content=python-pillow |
| Unlock This Lesson | https://realpython.com/account/join/?utm_source=rp_lesson&utm_content=python-pillow |
| https://realpython.com/courses/python-pillow/#team |
| Process Images Using the Pillow Library and Python | https://realpython.com/courses/python-pillow/ |
| Darren Jones | https://realpython.com/courses/python-pillow/#team |
| Recommended Tutorial | https://realpython.com/image-processing-with-the-python-pillow-library/ |
| Course Slides (.pdf) | https://realpython.com/courses/python-pillow/downloads/python-pillow-slides/ |
| Sample Code (.zip) | https://realpython.com/courses/python-pillow/downloads/python-pillow-code/ |
| Ask a Question | https://realpython.com/lessons/python-pillow-image-processing/#discussion |
| https://realpython.com/feedback/survey/course/python-pillow/liked/?from=lesson-title |
| https://realpython.com/feedback/survey/course/python-pillow/disliked/?from=lesson-title |
| Transcript | https://realpython.com/lessons/python-pillow-image-processing/#transcript |
| Discussion | https://realpython.com/lessons/python-pillow-image-processing/#discussion |
| 00:00 | https://realpython.com/lessons/python-pillow-image-processing/#t=0.45 |
| Image Processing Using Pillow in Python. Previously in the course, | https://realpython.com/lessons/python-pillow-image-processing/#t=0.45 |
| you’ve learned how to crop and rotate images, resize them, | https://realpython.com/lessons/python-pillow-image-processing/#t=5.43 |
| and extract color bands from color images. However, | https://realpython.com/lessons/python-pillow-image-processing/#t=8.95 |
| none of the actions that you’ve taken so far have made any changes to the | https://realpython.com/lessons/python-pillow-image-processing/#t=12.96 |
| content of the image. In these sections of the course, | https://realpython.com/lessons/python-pillow-image-processing/#t=16.29 |
| you’ll learn about image processing features in the Python Pillow library. | https://realpython.com/lessons/python-pillow-image-processing/#t=19.27 |
| 00:23 | https://realpython.com/lessons/python-pillow-image-processing/#t=23.91 |
| To do this, you’ll make use of the ImageFilter module in Pillow. | https://realpython.com/lessons/python-pillow-image-processing/#t=23.91 |
| 00:29 | https://realpython.com/lessons/python-pillow-image-processing/#t=29.1 |
| One of the methods that’s used in image processing is image convolution using | https://realpython.com/lessons/python-pillow-image-processing/#t=29.1 |
| kernels. | https://realpython.com/lessons/python-pillow-image-processing/#t=33.32 |
| A detailed explanation of image processing theory is outside the scope of this | https://realpython.com/lessons/python-pillow-image-processing/#t=34.44 |
| course, but if you’re interested in the science of image processing, | https://realpython.com/lessons/python-pillow-image-processing/#t=37.96 |
| one of the best resources you can use is Digital Image Processing by Gonzales | https://realpython.com/lessons/python-pillow-image-processing/#t=41.86 |
| and Woods, which is seen on-screen. In this section, | https://realpython.com/lessons/python-pillow-image-processing/#t=46.28 |
| you’ll learn the basics of how you can use convolution kernels to perform image | https://realpython.com/lessons/python-pillow-image-processing/#t=50.46 |
| processing. But what is a convolution kernel? | https://realpython.com/lessons/python-pillow-image-processing/#t=54.16 |
| 00:58 | https://realpython.com/lessons/python-pillow-image-processing/#t=58.23 |
| A kernel is a matrix. | https://realpython.com/lessons/python-pillow-image-processing/#t=58.23 |
| You can consider a simple image to understand the process of convolution using | https://realpython.com/lessons/python-pillow-image-processing/#t=60.9 |
| kernels. | https://realpython.com/lessons/python-pillow-image-processing/#t=65.32 |
| The image has a size of 30x30 pixels and contains a vertical line and a dot. | https://realpython.com/lessons/python-pillow-image-processing/#t=66.38 |
| 01:12 | https://realpython.com/lessons/python-pillow-image-processing/#t=72.02 |
| The line is four pixels wide, | https://realpython.com/lessons/python-pillow-image-processing/#t=72.02 |
| and the dot consists of a 4x4 pixel square. | https://realpython.com/lessons/python-pillow-image-processing/#t=73.7 |
| The image is seen on-screen, enlarged for display purposes. | https://realpython.com/lessons/python-pillow-image-processing/#t=77.31 |
| You can place the kernel anywhere on the image and use the location of the | https://realpython.com/lessons/python-pillow-image-processing/#t=81.9 |
| kernel’s central cell as a reference. | https://realpython.com/lessons/python-pillow-image-processing/#t=85.56 |
| 01:28 | https://realpython.com/lessons/python-pillow-image-processing/#t=88.71 |
| The diagram on-screen is a representation of the top-left portion of the image. | https://realpython.com/lessons/python-pillow-image-processing/#t=88.71 |
| The white squares represent pixels in the image that have a value of zero. | https://realpython.com/lessons/python-pillow-image-processing/#t=93.6 |
| 01:37 | https://realpython.com/lessons/python-pillow-image-processing/#t=97.79 |
| The red squares represent pixels in the image that have a value of 255. | https://realpython.com/lessons/python-pillow-image-processing/#t=97.79 |
| Each purple region represents the kernel. | https://realpython.com/lessons/python-pillow-image-processing/#t=102.79 |
| The diagram shows a kernel in three different positions labeled 1, 2, | https://realpython.com/lessons/python-pillow-image-processing/#t=105.75 |
| and 3. | https://realpython.com/lessons/python-pillow-image-processing/#t=109.75 |
| 01:51 | https://realpython.com/lessons/python-pillow-image-processing/#t=111.33 |
| A new image can be created as a result of the convolution of the image with the | https://realpython.com/lessons/python-pillow-image-processing/#t=111.33 |
| kernel. Let’s take a look at kernel position 1. | https://realpython.com/lessons/python-pillow-image-processing/#t=115.05 |
| The position of the kernel is (3, 2), | https://realpython.com/lessons/python-pillow-image-processing/#t=120.27 |
| which is the position of its central cell because it’s in the fourth row with | https://realpython.com/lessons/python-pillow-image-processing/#t=122.05 |
| index of 3, and the third column with index of 2. | https://realpython.com/lessons/python-pillow-image-processing/#t=125.73 |
| 02:09 | https://realpython.com/lessons/python-pillow-image-processing/#t=129.95 |
| Each image pixel in the region covered by the kernel has a value of zero, | https://realpython.com/lessons/python-pillow-image-processing/#t=129.95 |
| so therefore, all of the multiplication from step 2 will be zero, | https://realpython.com/lessons/python-pillow-image-processing/#t=134.06 |
| and the addition will also be zero. | https://realpython.com/lessons/python-pillow-image-processing/#t=138.43 |
| 02:21 | https://realpython.com/lessons/python-pillow-image-processing/#t=141.59 |
| The new image will have a value of zero at pixel (3, 2). | https://realpython.com/lessons/python-pillow-image-processing/#t=141.59 |
| 02:26 | https://realpython.com/lessons/python-pillow-image-processing/#t=146.25 |
| In the case of the other kernel positions, the situation is different. | https://realpython.com/lessons/python-pillow-image-processing/#t=146.25 |
| Take a look at kernel position 2, located at (4, 7). One of the image pixels | https://realpython.com/lessons/python-pillow-image-processing/#t=150.16 |
| overlapping this is not zero. | https://realpython.com/lessons/python-pillow-image-processing/#t=155.09 |
| 02:37 | https://realpython.com/lessons/python-pillow-image-processing/#t=157.83 |
| The multiplication of this pixel value, 255, | https://realpython.com/lessons/python-pillow-image-processing/#t=157.83 |
| multiplied by the kernel value of 1/9, gives 28.33. | https://realpython.com/lessons/python-pillow-image-processing/#t=162.17 |
| The eight remaining multiplications are still zero because all of those other | https://realpython.com/lessons/python-pillow-image-processing/#t=167.45 |
| image pixels are zero. | https://realpython.com/lessons/python-pillow-image-processing/#t=171.03 |
| 02:53 | https://realpython.com/lessons/python-pillow-image-processing/#t=173.8 |
| This will mean the value at pixel position (4, 7) would be | https://realpython.com/lessons/python-pillow-image-processing/#t=173.8 |
| 28.33. | https://realpython.com/lessons/python-pillow-image-processing/#t=177.37 |
| 03:00 | https://realpython.com/lessons/python-pillow-image-processing/#t=180.76 |
| The third kernel position is at (8, 11). | https://realpython.com/lessons/python-pillow-image-processing/#t=180.76 |
| There are four non-zero image pixels overlapping with this kernel. | https://realpython.com/lessons/python-pillow-image-processing/#t=184.21 |
| Each one has a value of 255, | https://realpython.com/lessons/python-pillow-image-processing/#t=188.39 |
| so the multiplication result for each of them will be 28.33. | https://realpython.com/lessons/python-pillow-image-processing/#t=191.14 |
| 03:15 | https://realpython.com/lessons/python-pillow-image-processing/#t=195.58 |
| The overall result for this kernel position is 113.33, | https://realpython.com/lessons/python-pillow-image-processing/#t=195.58 |
| and the new image will have this value at (8, 11). | https://realpython.com/lessons/python-pillow-image-processing/#t=200.45 |
| 03:24 | https://realpython.com/lessons/python-pillow-image-processing/#t=204.94 |
| Remember that this is only the three kernel positions shown in the diagram. | https://realpython.com/lessons/python-pillow-image-processing/#t=204.94 |
| The convolution process repeats this process for every possible kernel position | https://realpython.com/lessons/python-pillow-image-processing/#t=208.76 |
| in the image, which gives a new value for each pixel position. In the image | https://realpython.com/lessons/python-pillow-image-processing/#t=212.74 |
| 03:38 | https://realpython.com/lessons/python-pillow-image-processing/#t=218.4 |
| on-screen, | https://realpython.com/lessons/python-pillow-image-processing/#t=218.4 |
| you can see the result of the convolution shown on the right, with the original | https://realpython.com/lessons/python-pillow-image-processing/#t=219.16 |
| image on the left. | https://realpython.com/lessons/python-pillow-image-processing/#t=222.78 |
| 03:45 | https://realpython.com/lessons/python-pillow-image-processing/#t=225.78 |
| The kernel you saw previously is called a box blur kernel. | https://realpython.com/lessons/python-pillow-image-processing/#t=225.78 |
| The factor of 1/9 is there so that the overall weighting of the kernel is | https://realpython.com/lessons/python-pillow-image-processing/#t=229.62 |
| one, as it covers nine pixels. | https://realpython.com/lessons/python-pillow-image-processing/#t=233.1 |
| 03:55 | https://realpython.com/lessons/python-pillow-image-processing/#t=235.66 |
| The result of the convolution is a blurred version of the original image. | https://realpython.com/lessons/python-pillow-image-processing/#t=235.66 |
| 04:01 | https://realpython.com/lessons/python-pillow-image-processing/#t=241.46 |
| There are other kernels that perform different functions, including different | https://realpython.com/lessons/python-pillow-image-processing/#t=241.46 |
| blurring methods, edge detection, sharpening, and more. | https://realpython.com/lessons/python-pillow-image-processing/#t=245.37 |
| 04:11 | https://realpython.com/lessons/python-pillow-image-processing/#t=251.73 |
| The Pillow library has several built-in kernels and functions that will perform | https://realpython.com/lessons/python-pillow-image-processing/#t=251.73 |
| the convolution described here. | https://realpython.com/lessons/python-pillow-image-processing/#t=255.55 |
| You don’t need to understand the math of filtering through convolution to use | https://realpython.com/lessons/python-pillow-image-processing/#t=257.89 |
| these filters, | https://realpython.com/lessons/python-pillow-image-processing/#t=261.43 |
| but it always helps to know what’s happening behind the scenes when using these | https://realpython.com/lessons/python-pillow-image-processing/#t=262.53 |
| tools. The following sections of the course will look at the kernels and image | https://realpython.com/lessons/python-pillow-image-processing/#t=266.03 |
| filtering capabilities available in the ImageFilter module in Pillow, | https://realpython.com/lessons/python-pillow-image-processing/#t=270.45 |
| starting by looking at blurring, sharpening, and smoothing. | https://realpython.com/lessons/python-pillow-image-processing/#t=274.61 |
| Become a Member | https://realpython.com/account/join/ |
| https://realpython.com/lessons/python-pillow-bands-modes/ |
| Overview | https://realpython.com/courses/python-pillow/ |
| https://realpython.com/lessons/python-pillow-blur-sharpen-smooth/ |
|
Process Images Using the Pillow Library and Python (Overview) 01:59
| https://realpython.com/videos/python-pillow-overview/ |
|
Basic Image Operations 07:51
| https://realpython.com/videos/python-pillow-operations/ |
|
Basic Manipulations 02:42
| https://realpython.com/videos/python-pillow-manipulations/ |
|
Bands and Modes of an Image 05:25
| https://realpython.com/lessons/python-pillow-bands-modes/ |
|
Image Processing 04:39
| https://realpython.com/lessons/python-pillow-image-processing/ |
|
Blurring, Sharpening, and Smoothing 04:31
| https://realpython.com/lessons/python-pillow-blur-sharpen-smooth/ |
|
Edge Detection, Enhancement, and Embossing 03:05
| https://realpython.com/lessons/python-pillow-edge-enhance-emboss/ |
|
Segmentation and Superimposition 05:36
| https://realpython.com/lessons/python-pillow-segment-superimpose/ |
|
Erosion and Dilation 04:18
| https://realpython.com/lessons/python-pillow-erode-dilate/ |
|
Image Segmentation 03:38
| https://realpython.com/lessons/python-pillow-segmentation/ |
|
Superimposition of Images 04:55
| https://realpython.com/lessons/python-pillow-superimpose-images/ |
|
Using NumPy With Pillow 03:19
| https://realpython.com/lessons/python-numpy-pillow/ |
|
Creating Images With NumPy 03:09
| https://realpython.com/lessons/python-numpy-create-image/ |
|
Creating Animations With NumPy 03:14
| https://realpython.com/lessons/python-pillow-numpy-animate/ |
|
Process Images Using the Pillow Library and Python (Summary) 00:47
| https://realpython.com/lessons/python-pillow-summary/ |
| Privacy Policy | https://realpython.com/privacy-policy/ |
Viewport: width=device-width, initial-scale=1, shrink-to-fit=no, viewport-fit=cover