You are on page 1of 8

Pi increase

t = -pi:0.008:pi;
s= sin(t);
c= cos(t);
figure;
plot(c+t,s+c);

Output:

Sine wave:
c = -pi:0.008:pi;
m= sin(c);
n= cos(c);
z=tan(c);
k=sec(c);
figure;
plot(m);

Output:

Grayscale image:
clc
clear
a = imread('C:\Users\Arnab\Pictures\zlatan_bicycle.jpg');
b = rgb2gray(a);
subplot(1,2,1)
imshow(a);
subplot(1,2,2)
imshow(b);

Output:

Binary image:
clc
clear
a = imread('C:\Users\Arnab\Pictures\zlatan_bicycle.jpg');
b = rgb2gray(a);
[r,c]=size(b);
d=zeros(size(b));
for i=1:r
for j=1:c
if b(i,j)>115
d(i,j)=1;
end
end
end
subplot(1,2,1)
imshow(b);
subplot(1,2,2);
imshow(d);

Output:

Negative Image:
clc
clear
a = imread('C:\Users\Arnab\Pictures\zlatan_bicycle.jpg');
b = rgb2gray(a);
[r,c]=size(b);
d=b;
for i=1:r
for j=1:c
d(i,j)=255-b(i,j);
end
end
subplot(1,2,1)
imshow(b);
subplot(1,2,2)
imshow(d);

Output:

Horizontal flip:
clc
clear
a = imread('C:\Users\Arnab\Pictures\zlatan_bicycle.jpg');
b = rgb2gray(a);
[r,c]=size(b);
d=b;for i=1:r
for j=1:c
d(i,c+1-j)=b(i,j);
end
end
subplot(1,2,1)
imshow(b);
subplot(1,2,2)
imshow(d);

Output:

Vertical flip:
clc
clear
a = imread('C:\Users\Arnab\Pictures\zlatan_bicycle.jpg');
b = rgb2gray(a);
[r,c]=size(b);
d=b;
for i=1:r
for j=1:c
d(r+1-i,j)=b(i,j);
end
end
subplot(1,2,1)
imshow(b);
subplot(1,2,2)
imshow(d);

Output:

Brighten Image:
clc
clear
x = input('Enter the range=');
a=imread('C:\Users\Arnab\Pictures\zlatan_bicycle.jpg');
b=rgb2gray(a);
d=b;
[r, c]=size(b);
for i=1:r
Enter the range=50
for j=1:c
b(i,j)=b(i,j)+x;
end
end
subplot(1,2,1);
imshow(d);
subplot(1,2,2);
imshow(b);

Output:

Chessboard:
clc
clear
a=zeros(64,64);
for i=1:64
for j=1:64
if mod(j+i,2)== 0
a(i,j)=1;
end
end
end
imshow(a);

Output:

Creating Blackspot On An Image:


clc
clear
e=input('Enter the thickness = ');
f=input('Enter the width = ');
g=input('Enter the row position= ');
h=input('Enter the column position = ');
a=imread('C:\Users\Arnab\Pictures\zlatan_bicycle.jpg');
b=rgb2gray(a);
d=b;
Output:
[r,c]=size(b);
m=ones(e,f);
Enter the thickness = 50
for i=1:e
Enter the width = 60
for j=1:f
Enter the row position= 100
b(g+i-1,j+h-1)=m(i,j);
Enter the column position = 100
end
end
subplot(1,2,1);
imshow(d);
subplot(1,2,2);
imshow(b);

Histrogram:
clc
clear
z=zeros(1,256);
a=imread('C:\Users\Arnab\Pictures\zlatan_bicycle.jpg');
b=rgb2gray(a);
[r ,c]=size(b);
for i=1:r
for j=1:c
m=b(i,j);
z(1,m+1)=z(1,m+1)+1;
end
end
subplot(1,3,1);
imshow(b);
subplot(1,3,2);
imhist(b);
subplot(1,3,3),
bar(z);

Output:

Histrogram Equalization:
clc
clear
myhist=zeros(1,256);
data = imread('C:\Users\Arnab\Pictures\zlatan_bicycle.jpg');
if(size(data,3)==3)
data=rgb2gray(data);
end
subplot(2,2,1);imshow(data);title('Original Image');
[r,c]=size(data);
for i=1:r
for j=1:c
m=data(i,j);
myhist(1,m+1)=myhist(1,m+1)+1;
end
end
subplot(2,2,2);bar(myhist);title('Histogram of original image');
sum_of_hist=zeros(1,256);
sum=0;
for i=1:256
sum=sum+myhist(i);
sum_of_hist(i)=sum;
end
area = r*c;
dm=256;
for i=1:r
for j=1:c
n=double(data(i,j));
data(i,j)=sum_of_hist(n+1)*dm/area;
end
end
for i=1:r
for j=1:c
m=double(data(i,j));
myhist(m+1)=myhist(m+1)+1;
end
end
subplot(2,2,3);bar(myhist);title('Equalized Histogram');subplot(2,2,4);
imshow(data);title('Image after histogram equalisation');

Output:

And Operation
clc
clear
a=imread('C:\Users\Arnab\Pictures\circle_black.jpg');
b=im2bw(a);
o=imread('C:\Users\Arnab\Pictures\circle_white.jpg');
p=im2bw(o);
[r c]=size(b);
[u v]=size(p);
if(size(b)==size(p))
k=zeros(r,c);
for i=1:r
for j=1:c
if((b(i,j)==1 && p(i,j)==1))
k(i,j)=1;
else
k(i,j)=0;
end
end
end
end
subplot(1,3,1);
imshow(b);
subplot(1,3,2);
imshow(p);
subplot(1,3,3);
imshow(k);

Output

Or Operation
clc
clear
a=imread('C:\Users\Arnab\Pictures\circle_black.jpg');
b=im2bw(a);
o=imread('C:\Users\Arnab\Pictures\circle_white.jpg');
p=im2bw(o);
[r c]=size(b);
[u v]=size(p);
if(size(b)==size(p))
k=zeros(r,c);
for i=1:r
for j=1:c
if((b(i,j)==0 && p(i,j)==0))
k(i,j)=0;
else
k(i,j)=1;
end
end
end
end
subplot(1,3,1);
imshow(b);
subplot(1,3,2);
imshow(p);
subplot(1,3,3);
imshow(k);

Output

Xor Operation
clc
clear
a=imread('C:\Users\Arnab\Pictures\circle_black.jpg');
b=im2bw(a);
o=imread('C:\Users\Arnab\Pictures\circle_white.jpg');
p=im2bw(o);
[r c]=size(b);
[u v]=size(p);
if(size(b)==size(p))
k=zeros(r,c);
for i=1:r
for j=1:c
if((b(i,j)==1 && p(i,j)==1)||(b(i,j)==0 && p(i,j)==0))
k(i,j)=0;
else
k(i,j)=1;
end
end
end
end
subplot(1,3,1);
imshow(b);
subplot(1,3,2);
imshow(p);
subplot(1,3,3);
imshow(k);

Output

Salt & Pepper Noise


clc
clear
a=imread('C:\Users\Arnab\Pictures\zlatan_bicycle.jpg');
a=rgb2gray(a);
subplot(2,2,1);
imshow(a);
b=imnoise(a,'Salt & Pepper',0.10);
subplot(2,2,2);
imshow(b);
k=medfilt2(b);
subplot(2,2,3);
imshow(k);

Output

Salt & Pepper Noise without Using Function


clc
clear
a=imread('C:\Users\Arnab\Pictures\zlatan_bicycle.jpg');
a=rgb2gray(a);
[r, c]=size(a);
b=randint(r,c,[0,255]);
f=input('Enter the lower noise limit =');
g=input('Enter the higher noise limit =');
subplot(2,2,1);
imshow(a);
k=r*c;
u=0;
for i=1:r
for j=1:c
if b(i,j)<=f
a(i,j)=0;
u=u+1;
else if b(i,j)>=g
a(i,j)=255;
u=u+1;
end
end
end
end
subplot(2,2,2);
imshow(a);
modifyA=zeros(size(a)+2);
B=zeros(size(a));
for x=1:size(a,1)
for y=1:size(a,2)
modifyA(x+1,y+1)=a(x,y);
end
end
for i=1:size(modifyA,1)-2
for j=1:size(modifyA,2)-2
window=zeros(9,1);
inc=1;
for x=1:3
for y=1:3
window(inc)=modifyA(i+x-1,j+y-1);
inc=inc+1;
end
end
med=sort(window);
B(i,j)=med(5);
Enter the lower noise limit = 50
end
Enter the higher noise limit = 200
end
subplot(2,2,3);
imshow(B,[]);

Output