-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquantizeImg.m
More file actions
38 lines (33 loc) · 815 Bytes
/
quantizeImg.m
File metadata and controls
38 lines (33 loc) · 815 Bytes
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
function quantizeImg(img,bits)
L = 2^bits;
stepUnrounded = 255/L;
step = round(stepUnrounded);
steps = [0];
for l = 1 : L
steps(end+1) = steps(end) + step;
end
for i=1:size(img,1)
for j=1:size(img,2)
pix=img(i,j);
if pix <= steps(1)
pixl = steps(1);
elseif pix > steps(L)
pixl = steps(L);
else
for k = 1 : L
if pix >= steps(k) && pix < steps(k+1)
pixl = steps(k);
end
end
end
new_img(i,j)=pixl;
end
end
figure()
subplot(1,2,1)
imshow(img,[])
title('Original Image')
subplot(1,2,2)
imshow(new_img,[])
title('Quantized Image')
end