Aim:- Logical Operations
MSc Computer Science Image Processing Practical No. 12
Index of all Practicals ~ Click Here
Code:- Logical_opera.m
Output:-
Code:- Not.m
Output:-
Code:- Hist.m
Output:-
Code:- Salt_And_Pepper.m
Output:-
MSc Computer Science Image Processing Practical No. 12
Index of all Practicals ~ Click Here
Code:- Logical_opera.m
clc;clear all;close all;
% Question:
% Performing various logical operations on an input image: AND, OR, XOR, NOT
f = imread('moon.tif');
g = imnoise(f,'salt & pepper',0.05);
BW1 = im2bw(f);
BW2 = im2bw(g);
BW3 = ~BW1;
figure;
subplot(1,2,1), imshow(BW1);title('A');
subplot(1,2,2), imshow(BW3);title('NOT A');
BW3 = BW1 & BW2;
figure;
subplot(1,3,1), imshow(BW1);title('A');
subplot(1,3,2), imshow(BW2);title('B');
subplot(1,3,3), imshow(BW3);title('A AND B');
BW3 = BW1 | BW2;
figure;
subplot(1,3,1), imshow(BW1);title('A');
subplot(1,3,2), imshow(BW2);title('B');
subplot(1,3,3), imshow(BW3);title('A OR B');
BW3 = xor(BW1,BW2);
figure;
subplot(1,3,1), imshow(BW1);title('A');
subplot(1,3,2), imshow(BW2);title('B');
subplot(1,3,3), imshow(BW3);title('A XOR B');
% Question:
% Performing various logical operations on an input image: AND, OR, XOR, NOT
f = imread('moon.tif');
g = imnoise(f,'salt & pepper',0.05);
BW1 = im2bw(f);
BW2 = im2bw(g);
BW3 = ~BW1;
figure;
subplot(1,2,1), imshow(BW1);title('A');
subplot(1,2,2), imshow(BW3);title('NOT A');
BW3 = BW1 & BW2;
figure;
subplot(1,3,1), imshow(BW1);title('A');
subplot(1,3,2), imshow(BW2);title('B');
subplot(1,3,3), imshow(BW3);title('A AND B');
BW3 = BW1 | BW2;
figure;
subplot(1,3,1), imshow(BW1);title('A');
subplot(1,3,2), imshow(BW2);title('B');
subplot(1,3,3), imshow(BW3);title('A OR B');
BW3 = xor(BW1,BW2);
figure;
subplot(1,3,1), imshow(BW1);title('A');
subplot(1,3,2), imshow(BW2);title('B');
subplot(1,3,3), imshow(BW3);title('A XOR B');
Output:-
Code:- Not.m
% Performing Not of an image
a=imread('southwest.tif');
b=double(a);
s=255-b;
figure(1);
imshow(a);
figure(2);
imshow(uint8(s));
a=imread('southwest.tif');
b=double(a);
s=255-b;
figure(1);
imshow(a);
figure(2);
imshow(uint8(s));
Output:-
Code:- Hist.m
**** PLOTTING HISTOGRAM ****
clc;
clf;
close all;
clear all;
a=imread('tire.tif');
r=double(a);
[row col]=size(r);
w=[1 1 1;1 1 1;1 1 1 ];
for x=2:row-1
for y=2:col-1
b(x,y)=[r(x-1,y-1)*w(1)+r(x-1,y)*w(2)+r(x-1,y+1)*w(3)+r(x,y-1)*w(4)+r(x,y)*w(5)+r(x,y+1)*w(6)+r(x+1,y-1)*w(7)+r(x+1,y)*w(8)+r(x+1,y+1)*w(9)];
end
end
figure(1);
imshow(a);
figure(2);
imshow(uint8(b));
clc;
clf;
close all;
clear all;
a=imread('tire.tif');
r=double(a);
[row col]=size(r);
w=[1 1 1;1 1 1;1 1 1 ];
for x=2:row-1
for y=2:col-1
b(x,y)=[r(x-1,y-1)*w(1)+r(x-1,y)*w(2)+r(x-1,y+1)*w(3)+r(x,y-1)*w(4)+r(x,y)*w(5)+r(x,y+1)*w(6)+r(x+1,y-1)*w(7)+r(x+1,y)*w(8)+r(x+1,y+1)*w(9)];
end
end
figure(1);
imshow(a);
figure(2);
imshow(uint8(b));
Output:-
Code:- Salt_And_Pepper.m
%**** Adding salt n pepper noise to an image ****
a=imread('Ranch house.jpg');
%r1=double(a);
r2=imnoise(a,'salt & pepper');
r=double(r2);
[row col]=size(r);
for x=2:row-1
for y=2:col-1
b=[r(x-1,y-1) r(x-1,y) r(x-1,y+1) r(x,y-1) r(x,y) r(x,y+1) r(x+1,y-1) r(x+1,y) r(x+1,y+1)];
s=sort(b);
t=s(5);
d(x,y)=t;
end
end
figure(1);
imshow(uint8(d));
figure(2);
imshow(uint8(r));
a=imread('Ranch house.jpg');
%r1=double(a);
r2=imnoise(a,'salt & pepper');
r=double(r2);
[row col]=size(r);
for x=2:row-1
for y=2:col-1
b=[r(x-1,y-1) r(x-1,y) r(x-1,y+1) r(x,y-1) r(x,y) r(x,y+1) r(x+1,y-1) r(x+1,y) r(x+1,y+1)];
s=sort(b);
t=s(5);
d(x,y)=t;
end
end
figure(1);
imshow(uint8(d));
figure(2);
imshow(uint8(r));
Output:-
0 comments:
Confused? Feel free to ask
Post a Comment