Skip to content

Commit fcc3804

Browse files
committed
Working version Quatizer and Haar transform
1 parent 326c44a commit fcc3804

16 files changed

+104
-91
lines changed

Documents/TD2016.pdf

238 KB
Binary file not shown.

Quantization/dequantization.m

Lines changed: 0 additions & 15 deletions
This file was deleted.

Quantization/dequantize_matrix.m

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
% dequantize_matrix:
2+
% Uniformly proyects a matrix with a number of levels (2^old_bytesize)
3+
% into a new matrix with a number of levels (2^new_bytesize)
4+
%
5+
% Correct behaviour only when:
6+
% new_bytesize >= old_bytesize
7+
function dequantized_matrix = dequantize_matrix(matrix, old_bytesize, new_bytesize)
8+
delta = 2^(new_bytesize-old_bytesize);
9+
dequantized_matrix = zeros(size(matrix,1),size(matrix,2),'uint8');
10+
for row = 1:size(matrix,1)
11+
for col = 1:size(matrix,2)
12+
dequantized_matrix(row,col) = dequantize(matrix(row,col), delta);
13+
end
14+
end
15+
end
16+
17+
function dequantization = dequantize(pixel, delta)
18+
% Operation avg*Pixel+avg changed to:
19+
dequantization = delta*(double(pixel) + 0.5);
20+
end

Quantization/quantization.m

Lines changed: 0 additions & 20 deletions
This file was deleted.

Quantization/quantization2.m

Lines changed: 0 additions & 13 deletions
This file was deleted.

Quantization/quantize_matrix.m

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
function quantized_matrix = quantize_matrix(matrix, new_bytesize)
2+
quantized_matrix = zeros(size(matrix,1),size(matrix,2),'uint8');
3+
for row = 1:size(matrix,1)
4+
for col = 1:size(matrix,2)
5+
quantized_matrix(row,col) = quantize(matrix(row,col), new_bytesize);
6+
end
7+
end
8+
end
9+
10+
function quantization = quantize(pixel, new_bytesize)
11+
dif_levels = 2^(8-new_bytesize);
12+
quantization=floor(double(pixel)/dif_levels);
13+
end

Test-images/cameraman.tif

257 KB
Binary file not shown.

Test-images/lena_gray_512.tif

256 KB
Binary file not shown.

Test-images/mandril_gray.tif

257 KB
Binary file not shown.

Transformation/ HaarWavelet.m

Lines changed: 0 additions & 22 deletions
This file was deleted.

Transformation/ReverseHaar.m

Lines changed: 0 additions & 21 deletions
This file was deleted.

Transformation/haar_reverse.m

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
% haar_reverse:
2+
% Given an input haar_transform image of 256 levels, undo the transform.
3+
function haar_matrix = haar_reverse(original_matrix)
4+
temp_matrix = transpose(original_matrix);
5+
temp_matrix = revert_haar(temp_matrix);
6+
temp_matrix = transpose(temp_matrix);
7+
haar_matrix = revert_haar(temp_matrix);
8+
end
9+
10+
function haar_matrix = revert_haar(matrix)
11+
haar_matrix = zeros(size(matrix,1),size(matrix,2));
12+
half_col = size(matrix,2)/2;
13+
for row = 1:size(matrix,1)
14+
i = 1;
15+
for col = 1:half_col
16+
haar_matrix(row,i) = matrix(row,col) + matrix(row,col + half_col);
17+
haar_matrix(row,i+1) = matrix(row,col) - matrix(row,col + half_col);
18+
i = i + 2;
19+
end
20+
end
21+
end
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
function haar_matrix = haar_reverse_multilevel(original_matrix, n_transforms)
2+
haar_matrix = original_matrix;
3+
for i = n_transforms-1:-1:0
4+
rows = 1:(size(haar_matrix,1)/2^i);
5+
columns = 1:(size(haar_matrix,1)/2^i);
6+
haar_matrix(rows,columns) = haar_reverse(haar_matrix(rows,columns));
7+
end
8+
end
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
function haar_matrix = haar_reverse_multilevel2(original_matrix, n_transforms)
2+
haar_matrix = original_matrix;
3+
for i = n_transforms:1
4+
rows = 1:(size(haar_matrix,1)/2^i);
5+
columns = 1:(size(haar_matrix,1)/i);
6+
haar_matrix(rows,columns) = haar_reverse(haar_matrix(rows,columns));
7+
end
8+
end

Transformation/haar_transform.m

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
% haar_transform:
2+
% Given an input greyscale image of 256 levels, apply the harr transform
3+
% to it.
4+
% Will apply the transform first to the rows and then to the columns
5+
% Parameteres:
6+
% matrix: the image to be transformed
7+
function haar_matrix = haar_transform(original_matrix)
8+
temp_matrix = haar_pass(original_matrix);
9+
temp_matrix = transpose(temp_matrix);
10+
temp_matrix = haar_pass(temp_matrix);
11+
haar_matrix = transpose(temp_matrix);
12+
end
13+
14+
function haar_matrix = haar_pass(matrix)
15+
haar_matrix = zeros(size(matrix,1),size(matrix,2));
16+
half_col = size(matrix,2)/2;
17+
for row = 1:size(matrix,1)
18+
i = 1;
19+
for col = 1:2:size(matrix,2)
20+
haar_matrix(row,i) = (double(matrix(row,col))+ double(matrix(row,col+1)))/2;
21+
c = (double(matrix(row,col)) - double(matrix(row,col+1)))/2;
22+
haar_matrix(row,i+half_col) = c ;
23+
i = i + 1;
24+
end
25+
end
26+
end
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
function haar_matrix = haar_transform_multilevel(original_matrix, n_transforms)
2+
haar_matrix = original_matrix;
3+
for i = 1:n_transforms
4+
rows = 1:size(haar_matrix,1)/i;
5+
columns = 1:size(haar_matrix,1)/i;
6+
haar_matrix(rows,columns) = haar_transform(haar_matrix(rows,columns));
7+
end
8+
end

0 commit comments

Comments
 (0)