Professional Documents
Culture Documents
Experiment No. 6
Basic Image Import, Processing, and Export
Introduction
This worksheet is an introduction on how to handle images in Matlab. When working with
images in Matlab, there are many things to keep in mind such as loading an image, using the
right format, saving the data as different data types, how to display an image, conversion
between different image formats, etc. This worksheet presents some of the commands
designed for these operations. A digital image is composed of pixels which can be thought of
as small dots on the screen. A digital image is an instruction of how to color/gray level each
pixel. A typical size of an image is 512-by-512 pixels. It is convenient to let the dimensions
of the image to be a power of 2. For example, 29 = 512. In the general case we say that an
image is of size M-by-N if it is composed of M pixels in the vertical direction and N pixels in
the horizontal direction.The following image formats are supported by Matlab:
Most images you find on the Internet are JPEG-images which is the name for one of the most
widely used compression standards for images. An image named myimage.jpg is stored in the
JPEG format.
Procedure:
1-Reading and writing image files Images are usually in form of a file (for example, if
you download an image from the web, it is usually stored as a JPEG-file). Once processing
has been done, the image may be written back to a JPEG-file. This can be done by imread
and imwrite commands.
Matlab Command Operation
Imread ( name of image Read an image. (Within the parenthesis you type the
with extention ) name of the image file you wish to read. Put the file
name within single quotes ' '.)
Imwrite( , ) Write an image to a file. (As the first argument within
the parenthesis you type the name of the image you
have worked with. As a second argument within the
parenthesis you type the name of the file and format
that you want to write the image to. Put the file name
within single quotes ' '.)
iminfo Display information image
Results:
1- Reading Image Data
Read an image into the workspace, using the imread command. The example reads one of
the sample images included with the toolbox, an image of a young girl in a file named
pout.tif , and stores it in an array named I . imread infers from the file that the graphics
file format is Tagged Image File Format (TIFF).
Description
A = imread(filename,fmt) reads a grayscale or color image from the file specified by the
string filename, where the string fmt specifies the format of the file. If the file is not in the
current directory or in a directory in the MATLAB path, specify the full pathname of the
location on your system.
2- Display the image, using the imshow function. You can also view an image in the Image
Viewer app. The imtool function opens the Image Viewer app which presents an
integrated environment for displaying images and performing some common image
processing tasks. The Image Viewer app provides all the image display capabilities of
imshow but also provides access to several other tools for navigating and exploring
images, such as scroll bars, the Pixel Region tool, Image Information tool, and the
Contrast Adjustment tool.
A great deal of information can be obtained with the imfinfo function. For example, suppose
we take our indexed image emu.tif from above.
imfinfo(’emu.tif’)
ans:
Filename: ’emu.tif’ FileModDate: ’26-Nov-2002 14:23:01’
FileSize: 119804 Format: ’tif’
FormatVersion: [] Width: 331 Height: 384
BitDepth: 8 ColorType: ’indexed’
Report:
1- Read image which named ‘cameraman’ from Mat lab’s image .
2- Display the image in step 1
3- Write image in drive D:
4- Display information of image .
5- Discuss all steps.