You are on page 1of 3

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

Computer Technical Eng. Dept.


4th Class /2019-2020
Experiment No. 6
Image Conversion (part 2)
Objective:
 To learn how you can display image in different Data types.
Introduction:
We look more deeply at the use of the imshow function, and how spatial resolution and
quantization can affect the display and appearance of an image. In particular, we look at image
quality, and how that may be affected by various image attributes.
 Data types and conversions
Elements in Matlab matrices may have a number of different numeric data types; the most
common are listed in table 6.1. There are others; see the help for data types. These data
types are also
Table (6.1) Data types in Matlab program.

Functions, we can convert from one type to another. For example

Even though the variables a and b have the same numeric value, they are of different data
types. An important consideration (of which we shall more) is that arithmetic operations
are not permitted with the data types int8, int16, uint8 and uint16.
 Converting between double and uint8:
When you store an image, you should store it as a uint8 image
since this requires far less memory than double. When you are processing an
image (that is performing mathematical operations on an image) you should
convert it into a double. Converting back and forth between these classes is easy.

I=im2double(I); % Converts an image named I from uint8 to double.


I=im2uint8(I); % Converts an image named I from double to uint8.
We have seen that if x is a matrix of type uint8, then the command imshow(x) will display
x as an image. This is reasonable, since the data type uint8 restricts values to be integers
between 0 and 255. However, not all image matrices come so nicely bundled up into this data
type, and lots of Matlab image processing commands produces output matrices which are of
EXP. No. 6: Image Conversion (part 2) Page 24
Multimedia Computing Lab. Ruaa Hussam Al-Mallah/Lecturer Asst.
Computer Technical Eng. Dept.
4th Class /2019-2020
type double. We have two choices with a matrix of this type:
1- convert to type uint8 and then display, display the matrix directly
2- The second option is possible because imshow will display a matrix of type double as a
greyscale image as long as the matrix elements are between 0 and 1. Suppose we take an
image and convert it to type double
c=imread(’caribou.tif’);
cd=double(c);
imshow(c),figure,imshow(cd)

imshow(cd/255)
We can vary the display by changing the scaling of the matrix. Results of the commands:

EXP. No. 6: Image Conversion (part 2) Page 25


Multimedia Computing Lab. Ruaa Hussam Al-Mallah/Lecturer Asst.
Computer Technical Eng. Dept.
4th Class /2019-2020

Procedure:
1. Read the image from Matlab .
2. Convert the image from uint8 to double by using direct command im2double
3. Convert the image from uint8 to double by using indirect command by multiply 255
4. Display the result by imshow command.

Report:
1- Display image in the range from 0-1 and discussion the result?
2- Display image in the range from 0-2 and discussion the result?

EXP. No. 6: Image Conversion (part 2) Page 26

You might also like