|
| https://realpython.com/ |
| Start Here | https://realpython.com/start-here/ |
|
Learn Python
| https://realpython.com/lessons/python-pillow-numpy-animate/ |
| 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-numpy-animate/ |
| 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-numpy-animate%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-numpy-animate/#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-numpy-animate/#transcript |
| Discussion | https://realpython.com/lessons/python-pillow-numpy-animate/#discussion |
| 00:00 | https://realpython.com/lessons/python-pillow-numpy-animate/#t=0.47 |
| Using NumPy to Create Animations. In the previous section of the course, | https://realpython.com/lessons/python-pillow-numpy-animate/#t=0.47 |
| you created a color image containing three overlapping squares of different | https://realpython.com/lessons/python-pillow-numpy-animate/#t=5.33 |
| colors. In this section of the course, | https://realpython.com/lessons/python-pillow-numpy-animate/#t=9.23 |
| you’ll create an animation showing those three squares merging into a single | https://realpython.com/lessons/python-pillow-numpy-animate/#t=11.53 |
| white square. | https://realpython.com/lessons/python-pillow-numpy-animate/#t=15.44 |
| 00:16 | https://realpython.com/lessons/python-pillow-numpy-animate/#t=16.83 |
| You’ll create several versions of the images containing the squares, | https://realpython.com/lessons/python-pillow-numpy-animate/#t=16.83 |
| and the location of the squares will vary between successive images. | https://realpython.com/lessons/python-pillow-numpy-animate/#t=20.03 |
| 00:28 | https://realpython.com/lessons/python-pillow-numpy-animate/#t=28.39 |
| You create an empty list called square_animation, | https://realpython.com/lessons/python-pillow-numpy-animate/#t=28.39 |
| which you’ll use to store the images you generate. | https://realpython.com/lessons/python-pillow-numpy-animate/#t=30.78 |
| 00:36 | https://realpython.com/lessons/python-pillow-numpy-animate/#t=36.91 |
| Within the for loop, you create NumPy arrays for the red, green, | https://realpython.com/lessons/python-pillow-numpy-animate/#t=36.91 |
| and blue channels, as you did in the previous section. | https://realpython.com/lessons/python-pillow-numpy-animate/#t=40.79 |
| 00:48 | https://realpython.com/lessons/python-pillow-numpy-animate/#t=48.12 |
| The red square starts in a position displaced to the top left of the center. | https://realpython.com/lessons/python-pillow-numpy-animate/#t=48.12 |
| In each successive frame, | https://realpython.com/lessons/python-pillow-numpy-animate/#t=52.76 |
| the red square moves closer to the center until it reaches it in the final | https://realpython.com/lessons/python-pillow-numpy-animate/#t=54.2 |
| iteration of the loop. | https://realpython.com/lessons/python-pillow-numpy-animate/#t=58.14 |
| 01:00 | https://realpython.com/lessons/python-pillow-numpy-animate/#t=60.21 |
| The array containing the green layer is always the same and represents a square | https://realpython.com/lessons/python-pillow-numpy-animate/#t=60.21 |
| in the center of the image. | https://realpython.com/lessons/python-pillow-numpy-animate/#t=64.17 |
| The blue square is initially shifted towards the bottom right and moves towards | https://realpython.com/lessons/python-pillow-numpy-animate/#t=67.18 |
| the center in a similar way. | https://realpython.com/lessons/python-pillow-numpy-animate/#t=71.28 |
| 01:15 | https://realpython.com/lessons/python-pillow-numpy-animate/#t=75.17 |
| Note that in this example, you’re iterating over the range(0, 102, 2), | https://realpython.com/lessons/python-pillow-numpy-animate/#t=75.17 |
| which means that the variable offset increases in steps of two. | https://realpython.com/lessons/python-pillow-numpy-animate/#t=79.87 |
| 01:24 | https://realpython.com/lessons/python-pillow-numpy-animate/#t=84.5 |
| Each of the red, green, | https://realpython.com/lessons/python-pillow-numpy-animate/#t=84.5 |
| and blue images is created separately as a grayscale image, | https://realpython.com/lessons/python-pillow-numpy-animate/#t=85.83 |
| and while they’re named after each color, | https://realpython.com/lessons/python-pillow-numpy-animate/#t=89.53 |
| there isn’t any color information actually present in the images at this point. | https://realpython.com/lessons/python-pillow-numpy-animate/#t=91.36 |
| 01:40 | https://realpython.com/lessons/python-pillow-numpy-animate/#t=100.12 |
| The animation now has a new frame appended to it, | https://realpython.com/lessons/python-pillow-numpy-animate/#t=100.12 |
| consisting of a merge of the three images in the red, green, and blue channels. | https://realpython.com/lessons/python-pillow-numpy-animate/#t=102.75 |
| This is where the color is created. | https://realpython.com/lessons/python-pillow-numpy-animate/#t=107.69 |
| 01:58 | https://realpython.com/lessons/python-pillow-numpy-animate/#t=118.83 |
| You learned earlier on that you can save an Image object to a file | https://realpython.com/lessons/python-pillow-numpy-animate/#t=118.83 |
| using Image.save(). | https://realpython.com/lessons/python-pillow-numpy-animate/#t=122.06 |
| You can use the same function to save a GIF file that includes a sequence of | https://realpython.com/lessons/python-pillow-numpy-animate/#t=124.27 |
| images. You call Image.save() on the first image in the sequence, | https://realpython.com/lessons/python-pillow-numpy-animate/#t=128.25 |
| which is the first image that you stored in the list square_animation. | https://realpython.com/lessons/python-pillow-numpy-animate/#t=133.04 |
| 02:17 | https://realpython.com/lessons/python-pillow-numpy-animate/#t=137.29 |
| The first argument in .save() is the filename for the file that you want to save. | https://realpython.com/lessons/python-pillow-numpy-animate/#t=137.29 |
| The extension in the filename tells .save() which file format it needs to output. | https://realpython.com/lessons/python-pillow-numpy-animate/#t=142.4 |
| 02:27 | https://realpython.com/lessons/python-pillow-numpy-animate/#t=147.69 |
| You also include two keyword arguments in .save(). | https://realpython.com/lessons/python-pillow-numpy-animate/#t=147.69 |
| save_all=True ensures that all the images in the sequence are saved and not | https://realpython.com/lessons/python-pillow-numpy-animate/#t=152.31 |
| just the first one. | https://realpython.com/lessons/python-pillow-numpy-animate/#t=156.53 |
| 02:38 | https://realpython.com/lessons/python-pillow-numpy-animate/#t=158.87 |
| append_images allows you to append the remaining images in the sequence to the | https://realpython.com/lessons/python-pillow-numpy-animate/#t=158.87 |
| file. Once the file is saved, which may take some time | https://realpython.com/lessons/python-pillow-numpy-animate/#t=162.93 |
| depending on your system, you can open it with any image software. | https://realpython.com/lessons/python-pillow-numpy-animate/#t=167.75 |
| 02:52 | https://realpython.com/lessons/python-pillow-numpy-animate/#t=172.1 |
| The image should loop by default, but on some systems, | https://realpython.com/lessons/python-pillow-numpy-animate/#t=172.1 |
| you’ll need to add the keyword argument loop=0 to .save() | https://realpython.com/lessons/python-pillow-numpy-animate/#t=174.78 |
| to make sure that it does. Now that you’ve seen what to do, | https://realpython.com/lessons/python-pillow-numpy-animate/#t=178.86 |
| you can experiment by trying to create your own animation using different shapes | https://realpython.com/lessons/python-pillow-numpy-animate/#t=183.22 |
| and different colors. But in the next section of the course, | https://realpython.com/lessons/python-pillow-numpy-animate/#t=187.1 |
| you’ll take a look back at what you’ve learned. | https://realpython.com/lessons/python-pillow-numpy-animate/#t=190.46 |
| Become a Member | https://realpython.com/account/join/ |
| https://realpython.com/lessons/python-numpy-create-image/ |
| Overview | https://realpython.com/courses/python-pillow/ |
| https://realpython.com/lessons/python-pillow-summary/ |
|
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