Download as pdf or txt
Download as pdf or txt
You are on page 1of 10

DIGITAL IMAGE PROCESSING

LAB REPORT # 04

Submitted To:

Sir Inzamam Mashood

Submitted By:

Wajeeha Anum

Reg No:

17-CS-077

Section:

“A”
Lab #04

GRAY LEVEL TRANSFORMATIONS

Objectives:
• To study the Image Enhancement Basics
• To Observe the variation of image contrast and intensity using a MATLAB Simulation
• To enhance images using gray level transformations

Software tools:
• Matlab

Theory:
Enhancing an image provides better contrast and a more detailed image as compare to non-
enhanced image. Image enhancement has very applications. It is used to enhance medical images,
images captured in remote sensing, images from satellite. The transformation function has been
given below

s = T (r)

Where r is the original gray level of a pixel and s is the resulting gray level after processing. T is
a transformation function that maps each value of r to each value of s. Image enhancement can be
done through gray level transformations, which are discussed below.

Point operations are also referred to as gray-level transformations or spatial transformations.


Point operations are usually treated as simple mapping operations whereby the new pixel value at
a certain location depends only on the original pixel value at the same location and the mapping
function. In other words, the resulting image does not exhibit any change in size, geometry, or
local structure if compared with the original image. Point transformations maybe linear (e.g.,
identity, negative), or nonlinear (log, inverse log, power—also known as gamma—, and nth root)
transformation functions.

Procedure:
Task 01:

Why were we required to use I+1 when performing the Identity transformation instead of just I?

Answer:
We use I+1 to stay in bound otherwise we will get an error (Array indices must be positive integers
or logical values) so that is why we use I+1 when performing identity transformations in matlab.

Task 02:

How can we show that the adjusted image and the original image after applying Identity
transformation are equivalent?

Code:

After applying the identity transformations, we can say that the image is equivalent to the
original image’s complement, we can take the complement of original image and if we compare
that with the adjusted image, they will be equivalent.

Task 03:

How did we create the negative transformation function without using built-in command?

Code:

We used the following commands for creating negative transformations of an image without using
built in command:

➢ y = uint8(255:-1:0); I_neg = y(I + 1);


➢ figure, subplot(1,3,1), plot(y);
➢ title('Transformation Function'), xlim([0 255]), ylim([0 255]);
➢ subplot(1,3,2), imshow(I), title('Original Image');
➢ subplot(1,3,3), imshow(I_neg), title('Negative Image');}

Output:
Task 04:

Why does the log-transformed image display the hidden detail in the moon.tif image, but the
brightened image does not?

Solution:

This is because during log transformation, the dark pixels in an image are expanded as compare to
the higher pixel values. The higher pixel values are kind of compressed in log transformation. This
result in following image enhancement. If we brighten up the image then the effect is removed
because all of the pixels are brighten up so we cannot see those hidden details here is the output:

Output:
Task 05:

How does the shape of the curve for n-root function change if we were to use a different value
for n? Show for n=2, n=4, n=8.

Code:

n=2:

x = 0:255; n = 2; c = 255 / (255 ^ n);


root = nthroot((x/c), n);
figure, plot(root), title('2nd-root transformation'), axis tight, axis square;

Output:
n=4:

x = 0:255; n = 4; c = 255 / (255 ^ n);


root = nthroot((x/c), n);
figure, plot(root), title('4th-root transformation'), axis tight, axis square;

Output:

n=8:

x = 0:255; n = 8; c = 255 / (255 ^ n);


root = nthroot((x/c), n);
figure, plot(root), title('8th-root transformation'), axis tight, axis square;
Output:

Task 06:
Write MATLAB Code to perform all gray level transformations studied in this lab on
“cameraman.tif” and submit codes along with results.
Solution:
Identity Transformation:
Code:
x = uint8(0:255);
plot(x); xlim([0 255]); ylim([0 255]);
I = imread('cameraman.tif');
I_adj = x(I + 1);
figure, subplot(1,2,1), imshow(I), title('Original Image');
subplot(1,2,2), imshow(I_adj), title('Adjusted Image');

Output:

Log Transformations:

Code:

x = 0:255; c = 255 / log(256);


y = c * log(x + 1);
figure, subplot(2,2,1), plot(y);
title('Log Mapping Function'), axis tight, axis square

I = imread('cameraman.tif');
I_log = uint8(y(I + 1));
subplot(2,2,2), imshow(I), title('Original Image');
subplot(2,2,3), imshow(I_log), title('Adjusted Image');

I_br = imadd(I,100);
subplot(2,2,4), imshow(I_br), title('Original Image Scaled');
Output:

Power Transformations:
Code:
x = 0:255; n = 2; c = 255 / (255 ^ n);
root = nthroot((x/c), n);
figure, subplot(2,2,1), plot(root), title('2nd-root transformation'), axis tight, axis square;

I = imread('cameraman.tif');
I_root = uint8(root(I + 1));
subplot(2,2,2), imshow(I), title('Original Image');
subplot(2,2,[3 4]), imshow(I_root), title('Nth Root Image');
Output:

Conclusion:
In this lab we learned about basics of matlab transformations, we used matlab image toolbox to
perform different transformation operation on images and we understood their working and
benefits.

======================================================

You might also like