Phụ lục
315
end
if isa(a,'double')
img_dct=dct2(dvalue);
img_pow=(img_dct).^2;
img_pow=img_pow(:);
[B,index]=sort(img_pow);
B=flipud(B);
index=flipud(index);
compressed_dct=zeros(size(dvalue));
for ii=1:coeff
compressed_dct(index(ii))=img_dct(index(ii));
end
im=idct2(compressed_dct);
end
imwrite(im, outfile);
figure('Name','Output image');
imshow(im);
return;
end
3. svdcompr (Mục 13.3 chương 13)
function [im] = svdcompr (infile,singvals,outfile)
% IMCOMPR (infile,singvals,outfile)
% Image compression based on Singular Value Decomposition.
% Written by Luigi Rosa – L’Aquila - Italia
% infile is input file name present in the current directory
% singvals is the number of largest singular values (positive integer)
% outfile is output file name which will be created
% Compression ratio is equal to k(n+m+k) / n*m
% where k is the number of singular values (singvals)
% and [n,m]=size(input_image)
%*****************************************************************
if (exist(infile)==2)
a = imread(infile);
figure('Name','Input image');
imshow(a);
else
warndlg('The file does not exist.',' Warning ');
im=[];
return
end