ºÝºÝߣ

ºÝºÝߣShare a Scribd company logo
COMPUTER GRAPHICS AND
IMAGE PROCESSING
Assignment of Lab
Abstract
A complete practiceand a well-defined documentation of the tasks thatare to be performed as
an assignment
Name: M AMIR FAROOQ
RegistrationNo. 2014-CS-03
Submitted To: MAM URSOOSA
1
Assignment of Computer Graphics & Image Processing (Lab)
Question # 9
Sobel Operators
Answer
Command: img =imread('E:hello.jpg','jpg');
figure(1),imshow(img);
filter1=[-1 -2 -1;0 0 0;1 2 1];
filter2=[-1 0 1;-2 0 2;-1 0 1];
res1=imfilter(img,filter1);
figure(2),imshow(res1);
res2=imfilter(img,filter2);
figure(3),imshow(res2);
figure(4),imshow(res1+res2);
Output:
2
Question # 10
Prewitt Operators
Answer
Command: img=imread('E:hello.jpg','jpg');
figure(1),imshow(img);
filter1=[-1 -1 -1;0 0 0;1 1 1]
filter2=[-1 0 1;-1 0 1;-1 0 1]
res1=imfilter(img,filter1);
figure(2),imshow(res1);
res2=imfilter(img,filter2);
figure(3),imshow(res2);
figure(4),imshow(res1+res2);
Output:
3
Question # 11
Guassian Filter
Answer
Command: img=imread('E:hello.jpg','jpg');
figure(1),imshow(img);
filter1=fspecial('gaussian',[7 7],2)
res=imfilter(img,filter1);
figure(2),imshow(res)
Output:
4
Question # 12
Median Filter
Answer
Command: img=imread('E:hello.jpg','jpg');
figure(1),imshow(img);
res=imnoise(img,'salt & pepper',0.01);
figure(2),imshow(res)
figure(3),imshow(medfilt2(temp));
Output:
Question # 13
Average Filter
Answer
Command: img=imread('E:hello.jpg','jpg');
figure(1),imshow(img);
temp1=fspecial('average',[7 7]);
figure(2),imshow(imfilter(img,temp1));
5
Output:
Question # 14
Laplacian Filter
Answer
Command: img=imread('E:hello.jpg','jpg');
figure(1),imshow(img);
a=fspecial('laplacian');
figure(2),imshow(imfilter(img,a));
Output:
6
Question # 15
Robert Opertor
Answer
Command: img=imread('E:hello.jpg','jpg');
figure(1),imshow(img);
temp1=[-1 0;0 -1];
temp2=[0 1;-1 0];
res1=imfilter(img,temp1);
figure(2),imshow(res1);
res2=imfilter(img,temp2);
figure(3),imshow(res2);
figure(4),imshow(res1+res2);
Output:
Q 16: Low Pass Filter
7
Thisfilterisusedforsmoothinginfrequencydomain.
Code:
img=imread('E:hello.jpg','jpg');
img1=rgb2gray(img);
filt=[11 1
1 1 1
1 1 1]/9
image=imfilter(img1,filt);
filtered_img=img1-image;
subplot(1,2,1),imshow(img1);title('Orignal Image');
subplot(1,2,2),imshow(filtered_img);title('LowPassFilter');
Q 17: HighPass Filter
Code:
img=imread('E:hello.png','png');
img1=rgb2gray(img);
8
filt=[11 1
1 1 1
1 1 1]/9;
image=imfilter(img1,filt);
filtered_img=2*img1-image;
subplot(1,2,1),imshow(img1);title('Orignal Image');
subplot(1,2,2),imshow(filtered_img);title('After ApplyingHighPassFilter');
Q 18: HighBoost Filter
Code:
img=imread('E:hello.jpg,',jpg');
img1=rgb2gray(img);
filt=[11 1
1 1 1
1 1 1]/9;
image=imfilter(img1,filt);
9
filtered_img=2*img1-image;
subplot(1,2,1),imshow(b);title('OrignalImage');
subplot(1,2,2),imshow(filtered_img);title('HighBoostImage');
Q 19: Horizental and Vertical Edges Using Prewitt Filter
Code:
img=imread('C:UsersAppleDesktop1','jpg');
img1=rgb2gray(img);
edges_of_image=edge(img1,'prewitt');
subplot(1,2,1)
imshow(img1);title('Orignal Image');
subplot(1,2,2),
10
imshow(edges_of_image);title('Horizental &Vertical Edges');

More Related Content

Manual of image processing lab

  • 1. COMPUTER GRAPHICS AND IMAGE PROCESSING Assignment of Lab Abstract A complete practiceand a well-defined documentation of the tasks thatare to be performed as an assignment Name: M AMIR FAROOQ RegistrationNo. 2014-CS-03 Submitted To: MAM URSOOSA
  • 2. 1 Assignment of Computer Graphics & Image Processing (Lab) Question # 9 Sobel Operators Answer Command: img =imread('E:hello.jpg','jpg'); figure(1),imshow(img); filter1=[-1 -2 -1;0 0 0;1 2 1]; filter2=[-1 0 1;-2 0 2;-1 0 1]; res1=imfilter(img,filter1); figure(2),imshow(res1); res2=imfilter(img,filter2); figure(3),imshow(res2); figure(4),imshow(res1+res2); Output:
  • 3. 2 Question # 10 Prewitt Operators Answer Command: img=imread('E:hello.jpg','jpg'); figure(1),imshow(img); filter1=[-1 -1 -1;0 0 0;1 1 1] filter2=[-1 0 1;-1 0 1;-1 0 1] res1=imfilter(img,filter1); figure(2),imshow(res1); res2=imfilter(img,filter2); figure(3),imshow(res2); figure(4),imshow(res1+res2); Output:
  • 4. 3 Question # 11 Guassian Filter Answer Command: img=imread('E:hello.jpg','jpg'); figure(1),imshow(img); filter1=fspecial('gaussian',[7 7],2) res=imfilter(img,filter1); figure(2),imshow(res) Output:
  • 5. 4 Question # 12 Median Filter Answer Command: img=imread('E:hello.jpg','jpg'); figure(1),imshow(img); res=imnoise(img,'salt & pepper',0.01); figure(2),imshow(res) figure(3),imshow(medfilt2(temp)); Output: Question # 13 Average Filter Answer Command: img=imread('E:hello.jpg','jpg'); figure(1),imshow(img); temp1=fspecial('average',[7 7]); figure(2),imshow(imfilter(img,temp1));
  • 6. 5 Output: Question # 14 Laplacian Filter Answer Command: img=imread('E:hello.jpg','jpg'); figure(1),imshow(img); a=fspecial('laplacian'); figure(2),imshow(imfilter(img,a)); Output:
  • 7. 6 Question # 15 Robert Opertor Answer Command: img=imread('E:hello.jpg','jpg'); figure(1),imshow(img); temp1=[-1 0;0 -1]; temp2=[0 1;-1 0]; res1=imfilter(img,temp1); figure(2),imshow(res1); res2=imfilter(img,temp2); figure(3),imshow(res2); figure(4),imshow(res1+res2); Output: Q 16: Low Pass Filter
  • 8. 7 Thisfilterisusedforsmoothinginfrequencydomain. Code: img=imread('E:hello.jpg','jpg'); img1=rgb2gray(img); filt=[11 1 1 1 1 1 1 1]/9 image=imfilter(img1,filt); filtered_img=img1-image; subplot(1,2,1),imshow(img1);title('Orignal Image'); subplot(1,2,2),imshow(filtered_img);title('LowPassFilter'); Q 17: HighPass Filter Code: img=imread('E:hello.png','png'); img1=rgb2gray(img);
  • 9. 8 filt=[11 1 1 1 1 1 1 1]/9; image=imfilter(img1,filt); filtered_img=2*img1-image; subplot(1,2,1),imshow(img1);title('Orignal Image'); subplot(1,2,2),imshow(filtered_img);title('After ApplyingHighPassFilter'); Q 18: HighBoost Filter Code: img=imread('E:hello.jpg,',jpg'); img1=rgb2gray(img); filt=[11 1 1 1 1 1 1 1]/9; image=imfilter(img1,filt);
  • 10. 9 filtered_img=2*img1-image; subplot(1,2,1),imshow(b);title('OrignalImage'); subplot(1,2,2),imshow(filtered_img);title('HighBoostImage'); Q 19: Horizental and Vertical Edges Using Prewitt Filter Code: img=imread('C:UsersAppleDesktop1','jpg'); img1=rgb2gray(img); edges_of_image=edge(img1,'prewitt'); subplot(1,2,1) imshow(img1);title('Orignal Image'); subplot(1,2,2),