0% found this document useful (0 votes)
65 views

Amity University Haryana: Digital Image Processing Lab Practical File

The document contains code for 8 programs to perform various image processing tasks like converting an image to grayscale, displaying the histogram of an image, finding the negative of an image, separating an image into red, green and blue channels, applying linear and logarithmic transformations, using spatial filters to enhance images, observing the effect of average filtering with different mask sizes, removing salt and pepper noise using median filtering, and applying Prewitt, Sobel and Laplacian filters for image enhancement. The programs were written to complete an assignment for the Digital Image Processing lab course.

Uploaded by

Ekansh Singh
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
65 views

Amity University Haryana: Digital Image Processing Lab Practical File

The document contains code for 8 programs to perform various image processing tasks like converting an image to grayscale, displaying the histogram of an image, finding the negative of an image, separating an image into red, green and blue channels, applying linear and logarithmic transformations, using spatial filters to enhance images, observing the effect of average filtering with different mask sizes, removing salt and pepper noise using median filtering, and applying Prewitt, Sobel and Laplacian filters for image enhancement. The programs were written to complete an assignment for the Digital Image Processing lab course.

Uploaded by

Ekansh Singh
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 20

AMITY UNIVERSITY HARYANA

Digital Image Processing Lab


Practical File

Submitted to: Submitted By:

Mr. Sunny Chugh Shubham Mohan Sharma

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)

title('Orignal Colored Image');

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)

w(i,j,k) = 255 - w(i,j,k);

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);

s = zeros(size(w, 1), size(w, 2));

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');

w = imnoise(I,'salt & pepper',0.2);

subplot(2,2,2)

imshow(w)

title('Salt and Pepper Noise');

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:

You might also like