You are on page 1of 3

Multimedia Computing Lab. Ruaa Hussam Al-Mallah/Lecturer Asst.

Computer Technical Eng. Dept.


4th Class

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

EXP. No. 6: Basic Image Import, Processing, and Export Page 15


Multimedia Computing Lab. Ruaa Hussam Al-Mallah/Lecturer Asst.
Computer Technical Eng. Dept.
4th Class
The commands imread and imwrite support the formats given in the section "Image
formats supported by Matlab" above.

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.

3- Write the Adjusted Image to a Disk File: (imwrite)


Write the newly adjusted image I2 to a disk file, using the imwrite function. This
example includes the filename extension '.png' in the file name, so the imwrite
function writes the image to a file in Portable Network Graphics (PNG) format, but
you can specify other formats
View what imwrite wrote to the disk file, using the imfinfo function. The imfinfo
function returns information about the image in the file, such as its format, size,
width, and height.
4- Information about your image

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’

EXP. No. 6: Basic Image Import, Processing, and Export Page 16


Multimedia Computing Lab. Ruaa Hussam Al-Mallah/Lecturer Asst.
Computer Technical Eng. Dept.
4th Class
FormatSignature: [73 73 42 0]
ByteOrder: little-endian’
NewSubfileType: 0
BitsPerSample: 8 Compression: ’PackBits’
PhotometricInterpretation: ’RGB Palette’
StripOffsets: [16x1 double] SamplesPerPixel: 1
RowsPerStrip: 24 StripByteCounts: [16x1 double]
XResolution: 72
YResolution: 72
ResolutionUnit: ’Inch’
Colormap: [256x3 double]
PlanarConfiguration: ’Chunky’
TileWidth: [] TileLength: []
TileOffsets: []
TileByteCounts: []
Orientation: 1
FillOrder: 1 GrayResponseUnit: 0.0100
MaxSampleValue: 255 MinSampleValue: 0
Thresholding: 1

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.

EXP. No. 6: Basic Image Import, Processing, and Export Page 17

You might also like