Skip to content

Commit d48e8d2

Browse files
authored
Update quantization.m
1 parent 4f303f5 commit d48e8d2

File tree

1 file changed

+6
-11
lines changed

1 file changed

+6
-11
lines changed

Quantization/quantization.m

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,16 @@
1-
function [ out_image ] = quantization( input_image,layers )
2-
%UNTITLED2 Summary of this function goes here
3-
% Detailed explanation goes here
4-
gray_scale=255;
5-
slide_size=gray_scale/layers;
1+
function [ out_image ] = quantization( input_image,levels,scale )
2+
%quantization Uniform scalar quantization
3+
if nargin==2, scale=256; end
4+
cluster_size=scale/levels;
65

76
out_image=zeros(size(input_image));
87

98
for i = 1:size(input_image,1)
109
for j = 1:size(input_image,2)
11-
aux=0;
12-
while(aux<input_image(i,j))
13-
aux = aux + slide_size;
14-
end
15-
out_image(i,j)=round(aux-slide_size/2);
10+
out_image(i,j) = round((input_image(i,j)/cluster_size-cluster_size)/2);
1611
end
1712
end
1813

19-
14+
out_image = uint8(out_image);
2015
end
2116

0 commit comments

Comments
 (0)