0
我是一个使用Matlab编写有损图像压缩脚本的新手。使用Haar变换的图像压缩
我的第一步是对图像进行完整级别的处理,我正在使用以下脚本进行处理。
clearvars all;
N = 256;
A=imread('test.jpg');
A=double(rgb2gray(A));
A=imresize(A,[N,N],'bicubic');
image(A);axis equal;colormap hsv;%gray(256) ;% display matrix as density plot
B = A;
while N>1
Q = [1 1;1 -1];
I = eye(N/2);
T = 1.414 * kron(I,Q);
II=eye(N)
I1= II(1:2:N,:);
I2=II(2:2:N,:);
P= [I1;I2];
%create transfer matrix N X N
B(1:N,1:N) = P*T*A(1:N,1:N)*T'*P';
%AR(1:N,1:N) = T'*P'*B(1:N,1:N)*P'*T
N = N/2;
end
imagesc(B);
drawnow;
此外,我想申请量化和对数阈值,并根据同时保留那些在顶部5%的增加的绝对值排序的元素。
下面的脚本这是否: -
cutoff = 80;
% Decide what fraction of coeffs you want to set to % zero,
% this fraction is the variable ?cutoff?. .....
%(1);imagesc(A);colormap gray(256)
len = 7;
% Wavelet transform A -> B
X = sort(abs(B(:)));
thresh = X(ceil(cutoff*len^2));
maximum=X(len^2);
lmaxt= log2(maximum/thresh);
% Thresholding & Quantization
for i = 1:len
for j = 1:len
if(abs(B(i,j)) > thresh)
sign = B(i,j)/abs(B(i,j));
ln = log2(abs(B(i,j))/thresh);
q = ceil(127*ln/lmaxt); Bq(i,j) = sign*q;
else
Bq(I,j) = 0;
end
end
end
figure;(2); spy(Bq)
现在,我想逆转这一过程,并设置为70%的哈尔系数得到原始图像。
任何指针都会很棒。