Images will be fit to the screen, which may distort their aspect ratio. Grayscale images will display using a default palette, which can be changed via the colormap command: Showing images on the screen is most easily accomplish using the image function: Since I often make multiple calculations on images, I typically convert the data type to double-precision real (double) and scale to 0.0 - 1.0 (though this will slow calculation): Note that image data has been store in MATLAB as unsigned 8-bit integers (uint8). This image is 942 pixels vertical by 1680 pixels horizontal, with 3 color planes (red, green and blue). The basic parameters are the location of the image file and the file format: In MATLAB, images are read from disk using the imread function. Also, brightness values are often stored in files as integers, such as 0 - 255 instead of 0.0 to 1.0.
Note that when all three color values are the same, the resulting color is a shade of gray.įor the reader's knowledge, there are also index images which will not be covered here, but which are full of index numbers (integers) which do not represent colors directly, but instead indicate locations in a palette.
As with grayscale images, values in the RGB color planes represent brightness of each color. Color images are similar to grayscale images, but are most often stored as a 3-dimensional array, which is really a stack of three 2-dimensional color planes: one for each primary color: red, green and blue ("RGB"). Typically, grayscale images are stored as a 2-dimensional array, representing 1 color plane with values of 0.0 indicating black, 1.0 indicating white and intermediate values indicating various shades of gray. Raster images always have 2 spatial dimensions (horizontal and vertical), and 1 or more color planes. Raster images, being arrays of numbers, are a natural fit for MATLAB, and indeed MATLAB is a convenient tool for applications such as image processing. This article will concentrate on the much more common raster form.
A raster image is simply a 2-dimensional array of colored pixels (represented by numbers). Vector images store images as line drawings (dots, line segments, polygons) defined by the spatial coordinates of their end points or vertices, and are most often used these days in artistic settings.
Images are nearly always stored in digital computers in one of two forms: vector or raster. This article will serve as a brief introduction to the use of image data within MATLAB.
If I write image-handling code in MATLAB, I know that every other MATLAB user on Earth can run my code without modification or the need for extra header files, libraries, etc. While it's true that one can find code libraries to perform these functions for other programming languages, like C++, the MATLAB model offers several advantages, not the least of which is standardization. The base MATLAB product provides routines for the loading from disk, manipulation, display and storing to disk of raster images. An excellent example of this is its support for images. One nice feature of MATLAB is its provision of handy functions which are not part of the programming language proper.