0% found this document useful (0 votes)
79 views9 pages

Astha Singh - 19419MCA017 Assignment-3

The document describes a series of image processing operations performed on an image: 1. It applies Laplacian, Sobel gradient, and averaging filters to the image. 2. It generates a sharpened image by adding the original and filtered images. 3. It further sharpens the image using a mask generated from the sharpened and smoothed images, and applies a power law transformation.

Uploaded by

Knowledge flood
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
79 views9 pages

Astha Singh - 19419MCA017 Assignment-3

The document describes a series of image processing operations performed on an image: 1. It applies Laplacian, Sobel gradient, and averaging filters to the image. 2. It generates a sharpened image by adding the original and filtered images. 3. It further sharpens the image using a mask generated from the sharpened and smoothed images, and applies a power law transformation.

Uploaded by

Knowledge flood
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

IMAGE PROCESSING

ASSIGNMENT-3
SUBMITTED TO- ANKITA VAISH MA’AM
SUBMITTED BY- ASTHA SINGH
Roll No. – 19419MCA017

Q-1 Write a program to perform smoothing on an image with square


averaging filters of size 3, 5, 9, 15 and 35.
Sol- Smoothing on an Image with averaging filters-
x=imread("peppers.tiff");
a=ones(3,3)/9; % averaging filter of size 3
b=ones(5,5)/25; % averaging filter of size 5
c=ones(9,9)/81; % averaging filter of size 9
d=ones(15,15)/(15*15); % averaging filter of size 15
e=ones(35,35)/(35*35); % averaging filter of size 35
ax=filter2(a,x,'same');
bx=filter2(b,x,'same');
cx=filter2(c,x,'same');
dx=filter2(d,x,'same');
ex=filter2(e,x,'same');
subplot(3,2,1);imshow(x);title('original image');
subplot(3,2,2);imshow(ax/255);title('smoothing image with filter of size 3');
subplot(3,2,3);imshow(bx/255);title('smoothing image with filter of size 5');
subplot(3,2,4);imshow(cx/255);title('smoothing image with filter of size 9');
subplot(3,2,5);imshow(dx/255);title('smoothing image with filter of size 15');
subplot(3,2,6);imshow(ex/255);title('smoothing image with filter of size 35');
Smoothing on an Image with averaging filters

Q-2 Write a program to perform smoothing using a median filter of


size 3 * 3.
Sol- Smoothing using median filter -
clc
a=imread('my1.jpg');
I=imnoise(a,'salt & pepper',0.2);
I_filtered=medfilt3(I,[3,3,3]); %median filter of size 3*3
subplot(1,2,1);imshow(I);title('Image with Slat & Pepper Noise');
subplot(1,2,2);imshow(I_filtered);title('Filtered Image');
Smoothing using median filter

Q-3 Write a program for sharpening an image using unsharp masking


and highboost filtering.
Sol- Sharpening of an Image using unsharp masking and highboost
filtering-
clc
a=imread('peppers1.tiff');
f=fspecial('average',[5,5]);
ax=imfilter(a,f);
g=imsubtract(a,ax);
h=3*imsubtract(a,ax);
unsharp=imadd(a,g);
high=imadd(a,h);
subplot(3,2,1);imshow(a);title('original image');
subplot(3,2,3);imshow(g);title('unsharp mask');
subplot(3,2,4);imshow(h);title('high boost');
subplot(3,2,5);imshow(unsharp);title('sharpening using unsharp masking');
subplot(3,2,6);imshow(high);title('sharpening using highboost filtering');
Sharpening of an Image using Unsharp masking and highboost filtering

Q-4 Write a program for sharpening an image using Gradient


operator.
Sol- Sharpening an image using Gradient operator-
clc;
img=imread('peppers.tiff');
subplot(3,1,1);
imshow(img);
title('Original image');
[m,n] = size(img);
T = 20;

%Sobel operator
imgs = zeros(m,n);
for i=2:m-1
for j=2:n-1
imgs(i,j)= abs(img(i-1,j+1)+2*img(i,j+1)+img(i+1,j+1)-img(i-1,j-1)-2*img(i,j-
1)-img(i+1,j-1)) + abs(img(i+1,j-1)+2*img(i+1,j)+img(i+1,j+1)-img(i-1,j-1)-
2*img(i-1,j)-img(i-1,j+1));
if imgs(i,j)<T
imgs(i,j) = 0;
else
imgs(i,j) = 255;
end
end
end
subplot(3,1,2);
imshow(imgs);
title('Sobel operator image');

%Roberts operator
imgr = zeros(m,n);
for i=2:m-1
for j=2:n-1
imgr(i,j)= abs(img(i,j)-img(i+1,j+1)) + abs(img(i+1,j)-img(i,j+1));
if imgr(i,j)<T
imgr(i,j) = 0;
else
imgr(i,j) = 255;
end
end
end
subplot(3,1,3);
imshow(imgr);
title('Roberts operator image');

Sharpening an image using Gradient operator


Q-5 Write a program to perform following operations:
a. Take an image 
b. Apply Laplacian
c. Obtain sharpen image by adding ‘a’ and ‘b’
d. Apply sobel gradient on ‘a’
e. Smoothen ‘d’ using 5 *5 averaging filter
f. Obtain mask image as product of ‘c’ and ‘e’.
g. Sharpen the image using the sum of a and f.
h. Apply power law transformation on g.

Sol-

clc;
a=imread('bone.jpg');
a=rgb2gray(a);
subplot(4,2,1);
imshow(a);
title('Original image a');
[m,n] = size(a);
T=20;

%Laplace operator
b = uint8(zeros(m,n));
for i=2:m-1
for j=2:n-1
b(i,j)= abs(a(i+1,j)+a(i-1,j)+a(i,j+1)+a(i,j-1)-4*a(i,j));
if b(i,j)<T
b(i,j) = 0;
else
b(i,j) = 255;
end
end
end
subplot(4,2,2);
imshow(b);
title('Laplace operator image');

%obtain sharpen image by adding a and b


c=a+b;
subplot(4,2,3);
imshow(c);
title('sharpen image of a and b');

%sobel gradient on a
d = uint8(zeros(m,n));
for i=2:m-1
for j=2:n-1
d(i,j)= abs(a(i-1,j+1)+2*a(i,j+1)+a(i+1,j+1)-a(i-1,j-1)-2*a(i,j-1)-a(i+1,j-1)) +
abs(a(i+1,j-1)+2*a(i+1,j)+a(i+1,j+1)-a(i-1,j-1)-2*a(i-1,j)-a(i-1,j+1));
if d(i,j)<T
d(i,j) = 0;
else
d(i,j) = 255;
end
end
end
subplot(4,2,4);
imshow(d);
title('Sobel operator on a');

%Smoothen ‘d’ using 5 *5 averaging filter


sm=ones(5,5)/25;
e=uint8(filter2(sm,d,'same'));
e=e/255;
subplot(4,2,5);
imshow(e);
title('smoothening of d');

%mask image of c and e


f=immultiply(c,e);
subplot(4,2,6);
imshow(e);
title('mask image of c and e');

%sharpen the image using sum of a and f


g=imadd(a,f);
subplot(4,2,7);
imshow(g);
title('sharpening the image using a and f');
%power law transformation on g
x=im2double(g);
factor=2;
h=x;
[r,s]=size(x);
for i=1:r
for j=1:s
h(i,j)=factor*x(i,j).^5.0;
end
end
subplot(4,2,8);
imshow(h);
title('power law transformation on g');
Full Screen Output

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy