Phụ lục
303
PHUÏ LUÏC
A. CAÙC HAØM SÖÛ DUÏNG TRONG SAÙCH KHOÂNG COÙ SAÜN TRONG MATLAB
Sau đây là các hàm được đề cập trong sách nhưng không được MATLAB cung cấp sẵn (hàm
tự viết):
1. btcode (Phần 13.1)
function [out] = btcode (infile,bx,by,outfile)
% BTCODE (infile,singvals,outfile)
% Image Compression Using Block Truncation Coding.
% Written by Luigi Rosa – L’Aquila - Italia
% infile is input file name present in the current directory
% bx is a positive integer (x block size)
% by is a positive integer (y block size)
% outfile is output file name which will be created
%*****************************************************************
if (exist(infile)==2)
a = imread(infile);
figure('Name','Input image');
imshow(a);
else
warndlg('The file does not exist.',' Warning ');
out=[];
return
end
%------------------------------------------------------
if isgray(a)
dvalue = double(a);
dx=size(dvalue,1);
dy=size(dvalue,2);
% if input image size is not a multiple of block size image is resized
modx=mod(dx,bx);
mody=mod(dy,by);
dvalue=dvalue(1:dx-modx,1:dy-mody);
% the new input image dimensions (pixels)
dx=dx-modx;
dy=dy-mody;
% number of non overlapping blocks required to cover
% the entire input image