Skip to content

Commit 1414c85

Browse files
committed
Fixed quantizator for negative numbers and refactored haar transform
1 parent e05fca8 commit 1414c85

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

Codec/codec.m

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@
8989
h_sub23 = numel(huffmanCode(q_sub23))/numel(q_sub23);
9090

9191
% We need to "stitch" all the pieces of q_lena together
92+
q_lena = zeros(size(lena_gray_512,1),size(lena_gray_512,2));
9293
q_lena(1:128,1:128) = q_sub11;
9394
q_lena(1:128,129:256) = q_sub12;
9495
q_lena(129:256,1:128) = q_sub13;
@@ -117,6 +118,7 @@
117118
entropies
118119

119120
%%%%%%%% SYNTHESIS %%%%%%%%%%%%%
121+
dq_lena = zeros(size(lena_gray_512,1),size(lena_gray_512,2));
120122
dq_lena(1:128,1:128) = q_lena(1:128,1:128);
121123
dq_lena(1:128,129:256) = dequantize_matrix(q_lena(1:128,129:256),7,8);
122124
dq_lena(129:256,1:128) = dequantize_matrix(q_lena(129:256,1:128),7,8);
@@ -126,6 +128,7 @@
126128
dq_lena(257:512,257:512) = dequantize_matrix(q_lena(257:512,257:512),4,8);
127129

128130
synth_lena = haar_reverse_multilevel(dq_lena,2);
131+
figure
129132
imshow(synth_lena,[0,255])
130133

131134
%%%%%%%% PSNR calculation %%%%%%%%

Quantization/quantize_matrix.m

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,9 @@
99

1010
function quantization = quantize(pixel, new_bytesize)
1111
dif_levels = 2^(8-new_bytesize);
12-
quantization=floor(double(pixel)/dif_levels);
12+
if(pixel >= 0 )
13+
quantization=floor(double(pixel)/dif_levels);
14+
else
15+
quantization=ceil(double(pixel)/dif_levels);
16+
end
1317
end

Transformation/haar_transform.m

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@
1818
i = 1;
1919
for col = 1:2:size(matrix,2)
2020
haar_matrix(row,i) = (double(matrix(row,col)) + double(matrix(row,col+1)))/2.0;
21-
c = (double(matrix(row,col)) - double(matrix(row,col+1)))/2.0;
22-
haar_matrix(row,i+half_col) = c ;
21+
haar_matrix(row,i+half_col) = (double(matrix(row,col)) - double(matrix(row,col+1)))/2.0; ;
2322
i = i + 1;
2423
end
2524
end

0 commit comments

Comments
 (0)