Chapter 4. Image Tensors
“But he who dares not grasp the thornShould never crave the rose.”
—Anne Brontë
In the previous chapter, you created and destroyed simple tensors. However, our data was minuscule. As you might guess, printing tensors can take you only so far and in so many dimensions. You’re going to need to learn how to deal with large tensors, which are more common. This is, of course, true in the world of images! This is an exciting chapter because you’ll start working with real data, and we’ll be able to see the effects of your tensor operations immediately.
We’ll also get to utilize some existing best practices. As you recall, in the previous chapter, you converted a tic-tac-toe game to tensors. During this exercise with a simple 3 x 3 grid, you identified one method for converting a game’s state, but another person might have come up with a completely different strategy. We’ll need to identify some common practices and tricks of the trade, so you don’t have to reinvent the wheel every time.
We will:
-
Identify what makes a tensor an image tensor
-
Build some images by hand
-
Use fill methods to create large tensors
-
Convert existing images to tensors and back
-
Manipulate image tensors in useful ways
When you finish this chapter, you’ll be confident in managing real-world image data, and a lot of this knowledge will apply to managing tensors in general.
Visual Tensors
You might assume that when an image is converted into a tensor, that resulting tensor will ...