-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathenhancement.m
156 lines (137 loc) · 2.8 KB
/
enhancement.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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
%NEGATION OF IMAGE
clc;
clear all;
close all;
myImage=imread('your_image_path');
myGrayImage=rgb2gray(myImage);
myImage1= imresize(myGrayImage,[255,255]);
imshow(myImage1);
maxgraylevel = max(max(myImage1));
display(maxgraylevel);
myImage2 = maxgraylevel - myImage1;
imshow(myImage2);
%THRESHOLDING OF IMAGE
clc;
clear all;
close all;
myImage=imread('your_image_path');
myGrayImage=rgb2gray(myImage);
myImage1= imresize(myGrayImage,[255,255]);
imshow(myImage1);
figure;
t = 120;
for i=1:255
for j=1:255
if myImage1(i,j)<t
myImage1(i,j)=0;
end
if myImage1(i,j)>t
myImage1(i,j)=255;
end
end
end
imshow(myImage1);
%CONTRAST STRETCHING OF IMAGE
clc;
clear all;
close all;
myImage=imread('your_image_path');
myGrayImage=rgb2gray(myImage);
myImage1= imresize(myGrayImage,[255,255]);
imshow(myImage1);
figure;
a=0.4;
b=1.4;
g=0.6;
r1=60;
r2=130;
s1=65;
s2=140;
for i=1:255
for j=1:255
if myImage1(i,j)<=r1
myImage1(i,j)=myImage1(i,j)*a;
elseif myImage1(i,j)>r1 && myImage1(i,j)<=r2
myImage1(i,j)=b*(myImage1(i,j)-r1)+s1;
else
myImage1(i,j)=g*(myImage1(i,j)-r2)+s2;
end
end
end
imshow(myImage1);
title('Contrast stretched image');
%GRAY LEVEL SLICING OF IMAGE WITH AND WITHOUT BACKGROUND
clc;
clear all;
close all;
myImage=imread('your_image_path');
myGrayImage=rgb2gray(myImage);
myImage1= imresize(myGrayImage,[255,255]);
myImage2=myImage1;
imshow(myImage1);
figure;
a=80;
b=170;
%Gray level slicing without background
for i=1:255
for j=1:255
if myImage1(i,j)>=a && myImage1(i,j)<=b
myImage1(i,j)=255;
else
myImage1(i,j)=0;
end
end
end
imshow(myImage1);
title('Gray level slicing without background');
figure;
%Gray level slicing with background
for i=1:255
for j=1:255
if myImage2(i,j)>=a && myImage2(i,j)<=b
myImage2(i,j)=255;
end
end
end
imshow(myImage2);
title('Gray level slicing with background');
%BIT PLANE SLICING OF IMAGE
clc;
clear all;
close all;
myImage=imread('your_image_path');
myGrayImage=rgb2gray(myImage);
myImage1= imresize(myGrayImage,[255,255]);
imshow(myImage1);
figure;
c1= bitget(myImage1,1);
c2= bitget(myImage1,2);
c3= bitget(myImage1,3);
c4= bitget(myImage1,4);
c5= bitget(myImage1,5);
c6= bitget(myImage1,6);
c7= bitget(myImage1,7);
c8= bitget(myImage1,8);
imshow(logical(c1));
title('Bit plane 1');
figure;
imshow(logical(c2));
title('Bit plane 2');
figure;
imshow(logical(c3));
title('Bit plane 3');
figure;
imshow(logical(c4));
title('Bit plane 4');
figure;
imshow(logical(c5));
title('Bit plane 5');
figure;
imshow(logical(c6));
title('Bit plane 6');
figure;
imshow(logical(c7));
title('Bit plane 7');
figure;
imshow(logical(c8));
title('Bit plane 8');