📄 index_db.m
字号:
function [fe, fs] = index_db(namefile, imagedir, nlevels, filt, edge)
% INDEX_DB Wavelet-based feature extraction from database
%
% Input:
% namefile: the file contains the names of all images in database
% imagedir: the directory where all images are
% nlevels: (optional) number of wavelet pyramid levels (default 3)
% filt: (optional) string naming a standard filter
% (see wfilters, default 'haar')
% edge: (optional) specifies edge-handling
% (see dwtmode, default 'per')
%
% Output: (one column per image)
% fe: feature vectors based on mean energies
% of the wavelet coefficients
% fs: feature vectors based on generalized Gaussian pdf parameters
% (Maximum Likelihood Estimation)
%
% Note:
% To write the features into file that read from PC (little-endian
% format) then use:
%
% fid = fopen(indexfile, 'wb', 'ieee-le');
% fwrite(fid, fe, 'float');
%
% See also: WAVEFEAT, WAVEFEAT_ALL
% Checking inputs
if exist(namefile, 'file') == 0
error('Can not find namefile.');
end
if exist(imagedir, 'dir') == 0
error('Can not find imagedir.');
end
if exist('nlevels', 'var') == 0
nlevels = 3;
end
if exist('filt', 'var') == 0
filt = 'db4';
end
if exist('edge', 'var') == 0
edge = 'per';
end
% Filters from name
[LoF_D, HiF_D] = wfilters(filt, 'd');
% Set edge-handling mode
% dwtmode(edge);
st = dwtmode('status', 'nodisp');
if ~strcmp(st, edge)
dwtmode(edge);
end
% Initialize
fm = [];
fs = [];
cd(imagedir);
name_fid = fopen(namefile, 'rt');
% Main process
while 1
% Each image is in one line
line = fgetl(name_fid);
if ~isstr(line)
break;
end
% Image name is the first string
file = sscanf(line, '%s', 1);%Read string under format control %sfrom line , 1 data is read,
if exist(file, 'file') == 0
error('Bad: Image file not found.');
end
% Compute features
[fv1, fv2, fv3, w] = wavefeat(file, nlevels, LoF_D, HiF_D);
fm = [fm, fv1];
fs = [fs, fv3];
end
fclose(name_fid);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -