Amity University Haryana: Digital Image Processing Lab Practical File
Amity University Haryana: Digital Image Processing Lab Practical File
B.Tech CSE(Sec - A)
A50105211003
Program No. 1(a)
Q. Write a program to display an image as a grayscale image.
CODE:
a = imread('C:\Users\Student\Desktop\cc.jpg');
i = rgb2gray(a)
subplot(2,2,1)
imshow(a)
subplot(2,2,2)
imshow(i)
Program No. 1(b)
Q. Write a program to display any image as a histogram.
CODE:
a = imread('C:\Users\Student\Desktop\cc.jpg');
w = im2double(i)
subplot(2,2,3)
imshow(w)
subplot(2,2,4)
imhist(i)
OUTPUT(1(a) & 1(b)):
Program No. 2(a)
Q. Write a program to find the negative of an image using the imcomplement
function and the script code.
CODE:
w = imread('C:\Users\Student\Desktop\Balloons21.jpg');
subplot(2,2,1);
imshow(w)
subplot(2,2,2)
y = rgb2gray(w);
imshow(y)
title('GrayScale Image');
z = imcomplement(w);
subplot(2,2,3)
imshow(z)
title('imcomplement Image');
c = size(w);
for i = 1:c(1)
for j = 1:c(2)
for k= 1:c(3)
end
end
end
subplot(2,2,4)
imshow(w)
title('Negative Image');
OUTPUT:
Program No. 3
Q. WAP to display an image in RED, Grayscale, GREEN and blue.
CODE:
w = imread('C:\Users\Student\Desktop\cc.jpg');
subplot(3,3,1)
imshow(w);
a = rgb2gray(w);
subplot(3,3,2)
imshow(a);
subplot(3,3,3)
b = w(:,:,1);
c = w(:,:,2);
d = w(:,:,3);
just_red = cat(3,b, s, s)
just_green = cat(3,s,c,s)
just_blue = cat(3,s,s,d)
imshow(just_red)
subplot(3,3,4)
imshow(just_blue)
subplot(3,3,5)
imshow(just_green)
OUTPUT:
Program No. 4
Q. WAP to apply linear and power log transformation functions on an image.
CODE:
w = imread('C:\Users\Student\Desktop\dip.jpg');
subplot(3,3,1)
imshow(w);
c = rgb2gray(w);
subplot(3,3,2)
imshow(c)
y = 2 * w;
subplot(3,3,3)
imshow(y)
y2 = w * (2^2);
subplot(3,3,4)
imshow(y2)
z = imadjust(w);
subplot(3,3,5)
imshow(z)
OUTPUT:
Program No. 5
Q. WAP to enhance an image properties using combination of spatial filters.
CODE:
w = imread('C:\Users\Student\Desktop\dip.jpg');
subplot(3,3,1)
imshow(w);
c = rgb2gray(w);
subplot(3,3,2)
imshow(c)
y = 2 * w;
subplot(3,3,3)
imshow(y)
d = w(:,:,3);
just_blue = cat(3,s,s,d)
subplot(3,3,4)
imshow(just_blue)
z = imadjust(w);
subplot(3,3,8)
imshow(z)
z = imcomplement(w);
subplot(2,2,7)
imshow(z)
OUTPUT:
Program No. 6
Q. WAP to illustrate the effect of square averaging of different masks on an
image.
CODE:
I = imread('C:\Users\Student\Desktop\bb.jpg');
subplot(3,3,1);imshow(I);title('Original Image');
H = fspecial('average',3);
MotionBlur = imfilter(I,H,'replicate');
subplot(3,3,2)
imshow(MotionBlur);
title('Average 3X3');
H = fspecial('average',5);
MotionBlur = imfilter(I,H,'replicate');
subplot(3,3,3)
imshow(MotionBlur);
title('Average 5X5');
H = fspecial('average',9);
MotionBlur = imfilter(I,H,'replicate');
subplot(3,3,4)
imshow(MotionBlur);
title('Average 9X9');
H = fspecial('average',15);
MotionBlur = imfilter(I,H,'replicate');
subplot(3,3,5)
imshow(MotionBlur);
title('Average 15X15');
OUTPUT:
PROGRAM 7
Q. WAP to observe the effect of median filtered on an image corrupted by salt
and pepper method.
CODE:
A= imread('C:\Users\Student\Desktop\bb.jpg');
I = rgb2gray(A);
subplot(2,2,1);
imshow(I);
title('Original Image');
subplot(2,2,2)
imshow(w)
K = medfilt2(w);
subplot(2,2,3)
imshow(K)
title('Filtered Image')
m = medfilt2(K);
subplot(2,2,4)
imshow(m)
title('Filtered Image2')
OUTPUT:
PROGRAM 8
Q. WAP to show Image Enhancement using various filter “SOBEL”, “PREVIT” and
“LAPLACIAN”.
CODE:
I = imread('C:\Users\Student\Desktop\bb.jpg');
subplot(2,2,1);imshow(I);title('Original Image');
H = fspecial('prewitt');
MotionBlur = imfilter(I,H,'replicate');
subplot(2,2,2);imshow(MotionBlur);title('Prewitt Image');
H = fspecial('sobel');
MotionBlur = imfilter(I,H,'replicate');
subplot(2,2,3);imshow(MotionBlur);title('Sobel Image');
H = fspecial('Laplacian',0.2);
MotionBlur = imfilter(I,H,'replicate');
subplot(2,2,4);imshow(MotionBlur);title('Laplacian Image');
OUTPUT: