You are on page 1of 6

# COMSATS Institute of Information Technology

## Electrical Engineering Department

Digital Image Processing BCE-B9
Lab 3
Total Marks 30
Roll No: _____________ Name: ________________ Marks:
_______________
Spatial Transforms

Note:

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.

Objectives:

##  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.

## 3. Display the image using the function imshow or imview

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

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

## 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.

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

J = imcrop(I);
Imshow(J);

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

J = imcrop(I,[60 40 100 90]);
Imshow(J);
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.

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

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

imhist(I)

## 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.

## 2. Repeat the same operation with the function imcomplement.

subplot(2,2,1)
imshow(orig);
title('Original Image');

## comp = 255 - orig;

subplot(2,2,2)
imshow(comp);
title('Complement of Original Image');

## 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].

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

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

_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________
____

subplot(2,2,1)
imshow(a);
subplot(2,2,2)
imhist(a)
flood_eq = imadjust(a , [0 0.12], [0.6 1.0]);
subplot(2,2,3)
imshow(flood_eq);
subplot(2,2,4)
imhist(flood_eq);

## 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
values.

## 4. Note down your observations.

_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________
____