You are on page 1of 6

COMSATS Institute of Information Technology

Electrical Engineering Department

Digital Image Processing BCE-B9
Lab 3
Total Marks 30
Time for Tasks: 90 Minutes
Roll No: _____________ Name: ________________ Marks:
Spatial Transforms


Save all your work in different M-files. You will have to show the all the work and
processing at time of evaluation. Homework and any pending tasks have to be submitted no
later than Monday 4:00PM sharp.


 Resize, rotate and crop images

 Contrast Adjustment and Histogram Equalization, Gamma Correction
 Bit Planes
 Linear Filters

4.1: Resizing Images

When you resize an image, you specify the image to be resized and the magnification factor. To
enlarge an image, specify a magnification factor greater than 1. To reduce an image, specify a
magnification factor between 0 and 1.

Task 1: (1 Mark)

1. Read an image into Matlab workspace.

2. Resize the image using Matlab function imresize

3. Display the image using the function imshow or imview

I = imread('circuit.tif');
J = imresize(I,[100 150]);
figure, imshow(J)
Task 2: (1 Mark)

1. Now use another variant of the imresize function and repeat the above tasks.

J = imresize(I,[100 150]);

4.2: Rotating Images

When you rotate an image, you specify the image to be rotated and the rotation angle, in degrees.
If you specify a positive rotation angle, imrotate rotates the image counterclockwise; if you
specify a negative rotation angle, imrotate rotates the image clockwise

Task 3: (1 Mark)

1. Use imrotate function to replace an image by 45, 90 and 135 degrees.

J = imrotate(I,35);

4.3: Cropping Images

To extract a rectangular portion of an image, use the imcrop function. Using imcrop, you can
specify the crop region interactively using the mouse or programmatically by specifying the
size and position of the crop region.

Task 4: (1 Mark)

1. Use imcrop function to crop an image interactively using mouse.

I = imread('circuit.tif')
J = imcrop(I);

Task 5: (1 Mark)

1. Now crop an image by specifying the rectangular part you need to capture.

I = imread('circuit.tif')
J = imcrop(I,[60 40 100 90]);
4.4: Histogram Equalization

The function imhist(I) displays a histogram for the intensity image I above a grayscale colorbar.
The number of bins in the histogram is specified by the image type. If I is a grayscale image,
imhist uses a default value of 256 bins. If I is a binary image, imhist uses 2 bins.

Task 6: (1 Mark)

1. Display the histogram of an image using the function.

2. Now use histeq function to equalize the histogram and display it.

I = imread('pout.tif');

4.5: Complement of an Image

You can either use the function imcomplement to get the photographic negative of an image or
use the transformation: s = L – 1 – r.

Task 7: (1 Mark)

1. Run the following Matlab script and show the output.

2. Repeat the same operation with the function imcomplement.

orig = imread('blurry_moon.tif');
title('Original Image');

comp = 255 - orig;

title('Complement of Original Image');

4.6: Contrast Adjustment

J = imadjust(I,[low_in; high_in],[low_out; high_out]) maps the values in intensity image I to

new values in J such that values between low_in and high_in map to values between low_out and
high_out. Values below low_in and above high_in are clipped; that is, values below low_in map
to low_out, and those above high_in map to high_out. You can use an empty matrix ([]) for
[low_in high_in] or for [low_out high_out] to specify the default of [0 1].
Task 8: (2 Marks)

1. Run the following Matlab script and show the output.

2. What opearation was performed? Observe the histograms and note down your comments


a = imread('cameraman.tif');
flood_eq = imadjust(a , [0 0.12], [0.6 1.0]);

4.7: Gamma Correction

Imadjust can also accept an additional argument that specifies the gamma correction factor.
Depending on the value of gamma, the mapping between values in the input and output images
might be nonlinear. Gamma can be any value between 0 and infinity. If gamma is 1 (the default),
the mapping is linear. If gamma is less than 1, the mapping is weighted toward higher (brighter)
output values. If gamma is greater than 1, the mapping is weighted toward lower (darker) output

Task 9: (3 Marks)

1. Run the following Matlab script and show the output.

2. Repeat for the gamma values 4 and 5.

3. Apply imadjust to fractured_spine.tif but with negative values of gamma.

4. Note down your observations.

orig = imread('washed_out_aerial_image.tif');
title('Original Image');

b = imadjust(orig,[],[],3);
title('Gamama = 3');