Resizing images
In this recipe, we will load a sample image of Lena, which is available in the SciPy distribution, into an array. This chapter is not about image manipulation, by the way; we will just use the image data as an input.
Note
Lena Soderberg appeared in a 1972 Playboy magazine. For historical reasons, one of those images is often used in the field of image processing. Don't worry; the picture in question is completely safe for work.
We will resize the image using the repeat
function. This function repeats an array, which in practice means resizing the image by a certain factor.
Getting ready
A prerequisite for this recipe is to have SciPy, Matplotlib, and PIL installed. Have a look at the corresponding recipes in this chapter and the previous chapter.
How to do it...
Load the Lena image into an array.
SciPy has a
lena
function, which can load the image into a NumPy array:lena = scipy.misc.lena()
Some refactoring has occurred since version 0.10, so if you are using an older version, the...