Chapter 2
Images Files and File Types
We shall see that matrices can be handled very efficiently in MATLAB, Octave and Python.
Images may be considered as matrices whose elements are the pixel values of the image.
In this chapter we shall investigate how the matrix capabilities of each system allow us to
investigate images and their properties.
2.1 Opening and Viewing Grayscale Images
Suppose you are sitting at your computer and have started your system. You will have
a prompt of some sort, and in it you can type:
MATLAB/Octave
>> w = imread(’wombats.png’);
or from the io module of skimage
Python
In : import skimage.io as io
In : w = io.imread(’wombats.png’)
This takes the gray values of all the pixels in the grayscale image wombats.png and puts
them all into a matrix
w. This matrix w is now a system variable, and we can perform
various matrix operations on it. In general, the
imread function reads the pixel values from
an image file, and returns a matrix of all the pixel values.
Two things to note about this command:
1. If you are using MATLAB or Octave, end with a semicolon; this has the effect of not
displaying the results of the command to the screen. As the result of this particular
command is a matrix of size 256 ×256, or with 65,536 elements, we do not really want
all its values displayed. Python, however, does not automatically display the results
of a computation.
2. The name
wombats.png is given in quotation marks. Without them, the system
would assume that
wombats.png was the name of a variable, rather than the name
of a file.
Now we can display this matrix as a grayscale image. In MATLAB:
MATLAB
>> figure,imshow(w),impixelinfo
19