Apostolos Fanakis
6 years ago
7 changed files with 57695 additions and 22 deletions
@ -0,0 +1,18 @@ |
|||||
|
function x = imagedequant(q, w1, w2, w3) |
||||
|
%imagedequant dequantizes the pixel values of a tri-chromatic image |
||||
|
% Usage x = imagedequant(q, w1, w2, w3), where: |
||||
|
% Inputs |
||||
|
% - q is the input image who's values are going to be dequantized |
||||
|
% - w1 is the quantization step size for the first channel (red) |
||||
|
% - w2 is the quantization step size for the second channel (green) |
||||
|
% - w3 is the quantization step size for the third channel (blue) |
||||
|
% |
||||
|
% Output |
||||
|
% - x is the image with the dequantized values |
||||
|
|
||||
|
x = struct; |
||||
|
x.red = mydequant(q.red, w1); |
||||
|
x.green = mydequant(q.green, w2); |
||||
|
x.blue = mydequant(q.blue, w3); |
||||
|
end |
||||
|
|
@ -0,0 +1,17 @@ |
|||||
|
function q = imagequant(x, w1, w2, w3) |
||||
|
%imagequant quantizes the pixel values of a tri-chromatic image |
||||
|
% Usage q = imagequant(x, w1, w2, w3), where: |
||||
|
% Inputs |
||||
|
% - x is the input image who's values are going to be quantized |
||||
|
% - w1 is the quantization step size for the first channel (red) |
||||
|
% - w2 is the quantization step size for the second channel (green) |
||||
|
% - w3 is the quantization step size for the third channel (blue) |
||||
|
% |
||||
|
% Output |
||||
|
% - q is the image with the quantized values |
||||
|
|
||||
|
q = struct; |
||||
|
q.red = myquant(x.red, w1); |
||||
|
q.green = myquant(x.green, w2); |
||||
|
q.blue = myquant(x.blue, w3); |
||||
|
end |
@ -0,0 +1,14 @@ |
|||||
|
function x = mydequant(q, w) |
||||
|
%Implementation of a uniform, symmetric dequantizer without a dead zone |
||||
|
% Usage x = mydequant(q, w), where: |
||||
|
% Inputs |
||||
|
% - q is the input that is going to be dequantized, this can be a |
||||
|
% scalar, a column or row vector or a matrix |
||||
|
% - w is the quantization step size |
||||
|
% |
||||
|
% Output |
||||
|
% - x holds the quantized value(s), depending on the input this may |
||||
|
% be a scalar, a column or row vector or a matrix |
||||
|
|
||||
|
x = (2 * q .* w + w) / 2; |
||||
|
end |
@ -0,0 +1,14 @@ |
|||||
|
function q = myquant(x, w) |
||||
|
%Implementation of a uniform, symmetric quantizer without a dead zone |
||||
|
% Usage q = myquant(x, w), where: |
||||
|
% Inputs |
||||
|
% - x is the input that is going to be quantized, this can be a |
||||
|
% scalar, a column or row vector or a matrix |
||||
|
% - w is the quantization step size |
||||
|
% |
||||
|
% Output |
||||
|
% - q holds the quantized value(s), depending on the input this may |
||||
|
% be a scalar, a column or row vector or a matrix |
||||
|
|
||||
|
q = floor(x ./ w); |
||||
|
end |
@ -0,0 +1,47 @@ |
|||||
|
function saveasppm(x, filename, K) |
||||
|
%saveasppm encodes an image as PPM and saves it to the disk |
||||
|
% Usage saveasppm(x, filename, K), where: |
||||
|
% Inputs |
||||
|
% - x is the input image |
||||
|
% - filename is the path and filename of the file where the resulting |
||||
|
% PPM image is going to be saved |
||||
|
% - K is the maximum value of brightness |
||||
|
|
||||
|
file = fopen(filename, 'wt+'); |
||||
|
|
||||
|
fwrite(file, 'P6'); |
||||
|
fwrite(file, ' '); |
||||
|
fwrite(file, int2str(size(x.red, 1))); |
||||
|
fwrite(file, ' '); |
||||
|
fwrite(file, int2str(size(x.red, 2))); |
||||
|
fwrite(file, ' '); |
||||
|
fwrite(file, int2str(K)); |
||||
|
fwrite(file, newline); |
||||
|
|
||||
|
if K < 256 |
||||
|
precision = 'integer*1'; |
||||
|
precisionBytes = 1; |
||||
|
machinefmt = 'l'; |
||||
|
else |
||||
|
precision = 'integer*2'; |
||||
|
precisionBytes = 2; |
||||
|
machinefmt = 'b'; |
||||
|
end |
||||
|
|
||||
|
for row = 1:size(x.red, 1) |
||||
|
for column = 1:size(x.red, 2) |
||||
|
fwrite(file, x.red(row, column), precision, machinefmt); |
||||
|
fwrite(file, ' '); |
||||
|
fwrite(file, x.green(row, column), precision, machinefmt); |
||||
|
fwrite(file, ' '); |
||||
|
fwrite(file, x.blue(row, column), precision, machinefmt); |
||||
|
fwrite(file, ' '); |
||||
|
end |
||||
|
end |
||||
|
|
||||
|
% combined = B(:,[1;1]*(1:size(B,2))); |
||||
|
% combined(:,1:2:end) = A; |
||||
|
|
||||
|
fclose(file); |
||||
|
end |
||||
|
|
File diff suppressed because it is too large
Loading…
Reference in new issue