You are on page 1of 5

DE LA SALLE LIPA

COLLEGE OF INFORMATION TECHNOLOGY AND ENGINEERING


COMPUTER ENGINEERING DEPARTMENT
CONSYST – CONTROL SYSTEMS

LABORATORY EXERCISE #4: BASIC IMAGE PROCESSING USING MATLAB

I. OBJECTIVES

1. To introduce MATLAB platform.


2. To learn the basic MATLAB functions.
3. To learn basic MATAB programming.

II. DISCUSSIONS

IMAGES IN MATLAB

• Matlab is optimised for operating on matrices


• Images are matrices!
• Many useful built-in functions in the Matlab Image Processing Toolbox
• Very easy to write your own image processing functions

Figure 1.0 Loading and Displaying Image

REPRESENTATION OF IMAGES

• Images are just an array of numbers


>> I % ctrl+c to halt output!

• Intensity of each pixel is represented by the pixel element’s value in the red, green and blue
matrices

>> I(1,1,:) % RGB values of element (1,1)

25
DE LA SALLE LIPA
COLLEGE OF INFORMATION TECHNOLOGY AND ENGINEERING
COMPUTER ENGINEERING DEPARTMENT
CONSYST – CONTROL SYSTEMS

ans(:,:,1) =

135

ans(:,:,2) =

97

ans(:,:,3) =

33

INDEXES IMAGES

• An indexed image is where the pixel values are indices to elements in a colour map or colour
lookup table.
• The colour map will contain entries corresponding to red, green and blue intensities for each
index in the image.

Figure 2.0 Indexed Images

DISPLAYING INDEXED IMAGES


>> I2=I(:,:,2); % green values of I
Matlab considers I2 as an indexed image as it doesn’t contain
>> image(I2)
entries for red, green and blue entries
>> colorbar % display colourmap

26
DE LA SALLE LIPA
COLLEGE OF INFORMATION TECHNOLOGY AND ENGINEERING
COMPUTER ENGINEERING DEPARTMENT
CONSYST – CONTROL SYSTEMS

Index

Associated
Color

Color
Lookup
Table

Figure 3.0 Stock Image

Figure 4.0 Colomap

Useful Functions for Displaying Images


>> axis image % plot fits to data

>> h=axes('position', [0 0 0.5 0.5]);

>> axes(h);

>> imagesc(I2)

27
DE LA SALLE LIPA
COLLEGE OF INFORMATION TECHNOLOGY AND ENGINEERING
COMPUTER ENGINEERING DEPARTMENT
CONSYST – CONTROL SYSTEMS

HISTOGRAMS

• Frequency of the intensity values of the image


• Quantise frequency into intervals (called bins)
• (Un-normalised) probability density function of image intensities

Figure 5.0 Histogram

III. LABORATORY ACTIVITY

Instructions

1. Type the code in this handout in Matlab and investigate the results.
2. Do the exercises in the notes.
3. Create a grating2d.m function that generates a 2D steerable spatial frequency. Compute spatial
frequencies with an amplitude =1 and the following parameters

frequency = 1/50, 1/25, 1/10, 1/5 cycles per pixel,


phase= 0, pi/5, pi/4, pi/3, pi/2, pi theta
= 0, pi/5, pi/4, pi/3, pi/2, pi

The value for pi is returned by the in-built MatLab function pi. Display your gratings using the
inbuilt gray color map. (figure 1)

4. Create a superposition of two or more gratings with different frequencies and thetas and display
the result. You can do this by simply adding the images you generated with grating2d (figure 2)

frequency = (1/10 and 1/20), (1/20 and 1/30) theta


= (pi/2 and pi/5), (pi/10 and pi/2), (pi/2 and pi)

Make sure you examine combinations of different frequencies and theta values. (figure 4)
Visualise the intensity surface of the outputs that you have generated. (figure 4)

5. Write a MatLab function that segments a greyscale image based on a given threshold (i.e. display
pixels values greater than the threshold value, zero otherwise). The function should accept two
inputs, the image matrix, and the threshold value, and output the thresholded image matrix.

28
DE LA SALLE LIPA
COLLEGE OF INFORMATION TECHNOLOGY AND ENGINEERING
COMPUTER ENGINEERING DEPARTMENT
CONSYST – CONTROL SYSTEMS

Figure 6.0

29

You might also like