Creating Images With NumPy
00:00 Using NumPy to Create Images. Having seen how to manipulate images using NumPy and Pillow, you can go further and create them from scratch. You can start by creating a grayscale image. On-screen, you’ll see how to create a simple image containing a square, but you can create more elaborate images in the same way.
You create a 600x600 array containing zeros everywhere, and then you set the value of a set of pixels at the center of the array to
255. You can index NumPy arrays using both rows and columns. In this example, the first slice of
200:400 represents the rows
You’ve created a grayscale image containing a square. The mode of the image is inferred automatically when you use
Image.fromarray(). In this case, mode
"F" is used, which corresponds to an image with 32-bit floating-point pixels.
01:37 You can go further and create a color image. The process is repeated to create three images: one corresponding to the red, one to the green, and a final one corresponding to the blue channel. Once more, you create a square in each, but in different locations.
Become a Member to join the conversation.