Displaying Graphics Images
Image Types and Display Methods
To display a graphics file image, use either image
or imagesc
.
For example, read the image ngc6543a.jpg to a variable RGB and
display the image using the image
function. Change
the axes aspect ratio to the true ratio using axis
command.
RGB = imread('ngc6543a.jpg'); image(RGB); axis image;
This table summarizes display methods for the three types of images.
Image Type | Display Commands | Uses Colormap Colors |
---|---|---|
Indexed |
|
|
Intensity |
|
|
RGB (truecolor) |
|
|
Controlling Aspect Ratio and Display Size
The image
function displays the image in
a default-sized figure and axes. The image stretches or shrinks to
fit the display area. Sometimes you want the aspect ratio of the display
to match the aspect ratio of the image data matrix. The easiest way
to do this is with the axis
image
command.
For example, these commands display the earth
image
using the default figure and axes positions:
load earth image(X) colormap(map)
The elongated globe results from stretching the image display
to fit the axes position. Use the axis
image
command
to force the aspect ratio to be one-to-one.
axis image
The axis
image
command
works by setting the DataAspectRatio
property of
the axes object to [1 1 1]. See axis
and axes
for more information on how to control
the appearance of axes objects.
Sometimes you want to display an image so that each element in the data matrix corresponds to
a single screen pixel. To display an image with this one-to-one
matrix-element-to-screen-pixel mapping, use imshow
. For example, this command
displays the earth image so that one data element corresponds to one screen
pixel:
imshow(X,map)