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%的哈爾係數得到原始圖像。
任何指針都會很棒。