0% found this document useful (0 votes)
30 views3 pages

Lab 1

The document discusses reading, writing, and representing images in MATLAB. It explains how to read an image file, display the image, and write it to a new file. It also demonstrates how images can be represented numerically as arrays and displayed using different color maps. Methods covered include imread, imwrite, imagesc, and rgb2gray. Exercises are provided to practice these skills and understand image representation and conversion between color and grayscale images.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
0% found this document useful (0 votes)
30 views3 pages

Lab 1

The document discusses reading, writing, and representing images in MATLAB. It explains how to read an image file, display the image, and write it to a new file. It also demonstrates how images can be represented numerically as arrays and displayed using different color maps. Methods covered include imread, imwrite, imagesc, and rgb2gray. Exercises are provided to practice these skills and understand image representation and conversion between color and grayscale images.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 3

OBJECTIVE:

To understand how to read/write an image


To understand how an image can be represented

THEORY:
Image Reading/Writing:
 Read and display image information
imfinfo('Fig0221(a)(ctskull-256).tif')
or
imfinfo('rice.png')

Image = imread('Fig0221(a)(ctskull-256).tif');
or
Image = imread('rice.png');

 Display image size and file


size(Image)
or
figure, imshow(Image)
or
figure, imagesc(Image), colormap gray, axis image

 Write image to file


imwrite(Image, 'Ex1-1.png');

Exercise 1: Read, display, and write three random images


Image representation:
 Read image file
Image = imread('Fig0221(a)(ctskull-256).tif');
 Display part of the image as a numerical array.
Image(80:90, 80:90)

The output is displayed in Figure 1.1

1
Fig.1.1 Numerical image representation

Display by different color maps

figure, imagesc(Image), axis image, colormap gray, colorbar

figure, imagesc(Image), axis image, colormap jet, colorbar

figure, imagesc(Image), axis image, colormap hot, colorbar

The output is displayed in Figure 1.2

Fig.1.2 Displaying images using gray, jet and hot color maps from left to right

Exercise 2: Use MATLAB help function to find the number of available color-maps.
Why should we use one over the other?

2
Color converted to grayscale image:
 Read color image file
RGB = imread('saturn.png');
 Convert to grayscale.
GrayImage = rgb2gray(RGB);
 Display part of the image as a numerical array.
GrayImage(80:90, 80:90)
 Display image
figure, imagesc(GrayImage), axis image, colormap gray, colorbar
The color image and the converted to grayscale are displayed in Figure 1.3

Fig.1.3 Displaying a color image and the converted to grayscale image from left to right

Exercise 3: Use MATLAB surf and mesh functions to display the grayscale image as
a surface.
Exercise 4: Use MATLAB figure functionalities to read the RGB values of specific
pixels

Conclusion:

You might also like