Practical 1 AIM: Point Processing CODE: 1. Digital Negative

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 11

Practical 1

AIM: Point processing

CODE: 1. Digital Negative


clc
clear all
f=imread('cameraman.tif');
[row,col]= size(f);
for x=1:1:row
for y=1:1:col
g(x,y)=255-f(x,y);
end
end
figure(1)
imshow(f)
figure(2)
imshow(g)

OUTPUT:

2. Thresholding
clc
clear all
f=imread('cameraman.tif');
[row,col]= size(f);
for x=1:1:row
for y=1:1:col
if f(x,y)<=55
g(x,y)=0;
else
g(x,y)=255;
end
end
end
figure(1)
imshow(f)
figure(2)
imshow(g)

OUTPUT:

3. Grey Slicing
(i) Grey Slicing Without Background
clc
clear all
f=imread('cameraman.tif');
[row,col]= size(f);
r1=100, r2=150
for x=1:1:row
for y=1:1:col
if r1<f(x,y) && f(x,y)<r2
g(x,y)=255;
else
g(x,y)=0;
end
end
end
figure(1)
imshow(f)
figure(2)
imshow(g)

OUTPUT:

(ii) Grey Slicing With Background


clc
clear all
f=imread('cameraman.tif');
[row,col]= size(f);
r1=100, r2=150
for x=1:1:row
for y=1:1:col
if r1<f(x,y) && f(x,y)<r2
g(x,y)=255;
else
g(x,y)=f(x,y);
end
end
end
figure(1)
imshow(f)
figure(2)
imshow(g)

OUTPUT:
Practical 2
AIM: Histogram Stretching
CODE: 1. Histogram Stretching
%histogram stretching
clc
clear all
f=imread('pout.tif');
[row,col]= size(f);
rmin=min(min(f));
rmax=max(max(f));
smin=0;
smax=255;

for x=1:1:row
for y=1:1:col
g(x,y)=((smax-smin)/(rmax-rmin))*(f(x,y)-rmin)+smin;
end
end
figure(1)
imshow(f)
figure(2)
imhist(f)
figure(3)
imshow(g)
figure(4)
imhist(g)%histogram of stretched image
%%%%Hist equilization

f=imread('pout.tif');
g1=histeq(f);
figure(5)
imshow(g1)
figure(6)
imhist(g1) %histogram of equilization image

OUTPUT:
Practical 3
AIM: Low Pass Averaging (spatial domain)

CODE: 1. low pass averaging filter


clc
clear all
f1=imread('cameraman.tif');
f=imnoise(f1,'gaussian');
f=double(f);
[r,c]= size(f);
w=[1 1 1;1 1 1;1 1 1]/9;
for x=2:1:r-1
for y=2:1:c-1
g(x,y)= f(x-1,y-1)*w(1,1)+f(x-1,y)*w(1,2)+f(x-1,y+1)*w(1,3)+...
f(x,y-1)*w(2,1)+f(x,y)*w(2,2)+f(x,y-1)*w(2,3)+...
f(x+1,y-1)*w(3,1)+f(x+1,y)*w(3,2)+f(x+1,y+1)*w(3,3);
end
end
figure(1)
imshow(f1)
figure(2)
imshow(uint8(f))
figure(3)
imshow(uint8(g))

OUTPUT:
Practical 4
AIM: Low Pass Median Filter

CODE: 1.Low Pass Median Filter


clc
clear all
f1=imread('cameraman.tif');
f=imnoise(f1,'salt & pepper');
f=double(f);
[r,c]= size(f);
g=f;
for x=2:1:r-1
for y=2:1:c-1
temp=[f(x-1,y-1) f(x-1,y) f(x-1,y+1);+...
f(x,y-1) f(x,y) f(x,y+1);+...
f(x+1,y-1) f(x+1,y) f(x+1,y+1)];
temp1=sort(temp);
g(x,y)= temp1(5);
end
end

figure(1)
imshow(uint8(f))
figure(2)
imshow(uint8(g))

OUTPUT:
Practical 5
AIM: High Pass Filter

CODE: 1.High Pass Filter


clc
clear all
f=imread('cameraman.tif');
%f=imnoise(f1,'gaussian');
f=double(f);
[r,c]= size(f);
w=[-1 -1 -1;-1 8 -1;-1 -1 -1];
for x=2:1:r-1
for y=2:1:c-1
g(x,y)= f(x-1,y-1)*w(1,1)+f(x-1,y)*w(1,2)+f(x-1,y+1)*w(1,3)+...
f(x,y-1)*w(2,1)+f(x,y)*w(2,2)+f(x,y+1)*w(2,3)+...
f(x+1,y-1)*w(3,1)+f(x+1,y)*w(3,2)+f(x+1,y+1)*w(3,3);
end
end
% figure(1)
% imshow(f1)
figure(2)
imshow(uint8(f))
figure(3)
imshow(uint8(g))

OUTPUT:
Practical 6
AIM: High Boost

CODE: 1.High Boost


clc
clear all
f=imread('cameraman.tif');
%f=imnoise(f1,'gaussian');
f=double(f);
[r,c]= size(f);
w=[-1 -1 -1;-1 8.9 -1;-1 -1 -1];
for x=2:1:r-1
for y=2:1:c-1
g(x,y)= f(x-1,y-1)*w(1,1)+f(x-1,y)*w(1,2)+f(x-1,y+1)*w(1,3)+...
f(x,y-1)*w(2,1)+f(x,y)*w(2,2)+f(x,y-1)*w(2,3)+...
f(x+1,y-1)*w(3,1)+f(x+1,y)*w(3,2)+f(x+1,y+1)*w(3,3);
end
end
% figure(1)
% imshow(f1)
figure(2)
imshow(uint8(f))
figure(3)
imshow(uint8(g))

OUTPUT:-

You might also like