-
Notifications
You must be signed in to change notification settings - Fork 2
/
set1q6.m
105 lines (95 loc) · 2.49 KB
/
set1q6.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
close all
clear all
im=imread('einstein.tif');
[row,col]=size(im);
a=double(im);
figure, subplot(1,3,1), imshow(im),title ('original image')
% Brightness
b=im+100;
b=uint8(b);
subplot(1,3,2),imshow(b),title ('Brightness Enhanced')
%contrast
alpha=.1;
beta=2;
gamma=.1;
low=80;
high=170;
out1=alpha*a.*(a<low);
out2=beta*(a-low).*(low<a<high)+out1;
out3=gamma*(a-high).*(high<a)+out2;
con=out1+out2+out3;
subplot(1,3,3),imshow(uint8(con)),title ('Contrast Enhanced')
%complement
im2=imread('mars_moon_phobos.tif');
figure, subplot(1,2,1), imshow(im2),title ('original image')
d=256-im2;
subplot(1,2,2),imshow(d),title ('Complement of Image')
%binary contrast image
im3=imread('spot_shaded_text_image.tif');
figure, subplot(1,2,1), imshow(im3),title ('original image')
t=25;
e=255*(im3>t);
subplot(1,2,2),imshow(e),title ('Binary Image Enhancement')
%brightness slicing
im4=imread('kidney.tif');
figure, subplot(1,3,1), imshow(im4),title ('original image')
lo=180;
hi=250;
fst=(lo<im4);
lst=(im4<hi);
rng=(fst==lst);
f=rng*255;
subplot(1,3,2),imshow(uint8(f)),title ('Brightness Slicing without background')
fb=f+double(im4);
subplot(1,3,3),imshow(uint8(fb)),title('Brightness Slicing with background')
%lowpass filtering
im5=imread('cameraman.tif');
[row,col]=size(im5);
figure, subplot(1,2,1), imshow(im5),title ('original image')
lpf=zeros(row,col);
ws=11;
avg=ones(ws,ws)/(ws*ws);
pd=(ws-1)/2;
start=ws-pd;
f=padarray(im5,[pd pd],'replicate');
[r,c]=size(f);
for i=start:r-pd
for j=start:c-pd
window=f(i-pd:i+pd,j-pd:j+pd);
su=0;
for s=1:ws
for t=1:ws
su=su+avg(s,t)*window(s,t);
end
end
lpf(i-start+1,j-start+1)=su;
end
end
out=lpf;
subplot(1,2,2),imshow(uint8(out)),title ('Low Pass Filtered Image')
%highpass filtering
im6=imread('blurry_moon.tif');
[row,col]=size(im6);
figure, subplot(1,2,1), imshow(im6),title ('original image')
im6=double(im6);
ws=3;
pd=(ws-1)/2;
lap=-1*ones(ws,ws);
lap(pd+1,pd+1)=-1*sum(lap(:));
start=ws-pd;
f=padarray(im6,[pd pd],'replicate');
[r,c]=size(f);
for i=start:r-pd
for j=start:c-pd
window=f(i-pd:i+pd,j-pd:j+pd);
su=0;
for s=1:ws
for t=1:ws
su=su+lap(s,t)*window(s,t);
end
end
hpf(i-start+1,j-start+1)=su;
end
end
asd=uint8(hpf);
subplot(1,2,2),imshow(uint8(hpf)),title ('High Pass Filtered Image')