数字图像处理实验6 冈萨雷斯
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
实验六图像压缩(同预习)
一、实验目的
1、理解有损压缩和无损压缩的概念;
2、理解图像压缩的主要原则和目的;
3、利用MATLAB 程序进行图像压缩。
二、实验内容
1、Huffman 编码
使用mat2huff,huff2mat 实现Huffman 编解码,并应用imratio 计算编码后信号的压缩率。
2、编写无损预测编解码(lossless predictive coding)程序,使p313 Figure 8.7 (c)
图具有更低的熵(5.4436)。显示预测误差(prediction error)图。用解码程序解码,并验证解码是否正确(compare)。
3、参考p319-323,实现16×16分块离散余弦(DCT)编码,用zigzag方式保留每一
块的前10个和前21个系数,再进行进行DCT解码。编写程序并分别显示解码后的两个图。
实验程序:
实验1:
i=imread('Fig0804(a)(Tracy).tif'); i1=mat2huff(i);
cr1=imratio(i,i1);%cr1,压缩率
i2=huff2mat(i1);
rmse1=compare(i,i2);
figure,imshow(i);
figure,imshow(i2);
实验2:
子程序1:
function y = mat2lpc2(x, f)
%本程序改自课本上那个程序,可实现更高压缩率!
error(nargchk(1, 2, nargin)); % Check input arguments
if nargin < 2 % Set default filter if omitted
f = 1;
end
x = double(x); % Ensure double for computations [m, n] = size(x); % Get dimensions of input matrix
p = zeros(m, n); % Init linear prediction to 0
xs = x; zc = zeros(1,n); % Prepare for input shift and pad for j = 1:length(f) % For each filter coefficient ...
xs = [zc; xs(1:end - 1,:)]; % Shift and zero pad xga改加一行 p = p + f(j) * xs; % Form partial prediction sums
end
y = x - round(p); % Compute the prediction error
子程序2:
function x = lpc2mat2(y, f)
% 本程序改自课本上那个程序,可以解压
error(nargchk(1, 2, nargin)); % Check input arguments
if nargin < 2 % Set default filter if omitted
f = 1;
end
y=y';
f = f(end:-1:1); % Reverse the filter coefficients
[m, n] = size(y); % Get dimensions of output matrix order = length(f); % Get order of linear predictor
f = repmat(f, m, 1); % Duplicate filter for vectorizing
x = zeros(m, n + order); % Pad for 1st 'order' column decodes
% Decode the output one column at a time. Compute a prediction based % on the 'order' previous elements and add it to the prediction
% error. The result is appended to the output matrix being built.
for j = 1:n
jj = j + order;
x(:, jj) = y(:, j) + round(sum(f(:, order:-1:1) .* ...
x(:, (jj - 1):-1:(jj - order)), 2));
end
x = x(:, order + 1:end); % Remove left padding
x=x';
总程序:
f=imread('Fig0807(c)(Aligned).tif');
e=mat2lpc2(f);
figure,imshow(mat2gray(e));
h=entropy(e);
c=lpc2mat2(e);
figure,imshow(c,[]);
rmse=compare(f,c);
实验三:
i=imread('Fig0804(a)(Tracy).tif');
i=im2double(i);
mask1=[1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0
1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0
1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0
1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ];
mask2=[1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0
1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0