classData=tableRead('class.txt', 2); for i=1:length(classData) items=split(classData(i).filename, '-'); classData(i).range=[eval(items{1}), eval(items{2})]; end % Get image data imageData=recursiveFileList('D:\users\jang\books\dcpr\appNote\leafId\Leaves', 'jpg'); for i=1:length(imageData) [~, imageData(i).mainName]=fileparts(imageData(i).name); imageData(i).mainName=eval(imageData(i).mainName); end % Assign class label allMainName=[imageData.mainName]; for i=1:length(classData) range=classData(i).range; for j=range(1):range(2); index=find(allMainName==j); if length(index)~=1, keyboard; end imageData(index).output=i; end end % Feature extraction if ~exist('ds.mat', 'file') for i=1:length(imageData) fprintf('%d/%d: imFile=%s\n', i, length(imageData), imageData(i).path); imageData(i).fea=feaExtract(imageData(i).path); end ds.input=[imageData.fea]; ds.output=[imageData.output]; ds.inputName={'a/p', 'eccentricity', 'major/minor', 'a/ca', 'mean', 'variance'}; ds.outputName={classData.CommonName}; save ds ds else load ds.mat end [classSize, classLabel]=dsClassSize(ds, 1); rr=knncLoo(ds); fprintf('rr=%g%% for ds\n', rr*100); figure; dsProjPlot2(ds); ds2=ds; ds2.input=inputNormalize(ds2.input); figure; dsProjPlot2(ds2); [rr, computed]=knncLoo(ds2); fprintf('rr=%g%% for ds2\n', rr*100); confMat=confMatGet(ds2.output, computed); opt=confMatPlot('defaultOpt'); opt.className=ds.outputName; opt.mode='both'; figure; confMatPlot(confMat, opt); figure; inputSelectSequential(ds2, inf, 'knnc', 1); % Exhaustive search of classifiers opt=perfCv4classifier('defaultOpt'); opt.foldNum=10; tic; [perfData, bestId]=perfCv4classifier(ds2, opt, 1); toc structDispInHtml(perfData, 'Performance of various classifiers via cross validation'); % === Display the confusion matrix confMat=confMatGet(ds.output, perfData(bestId).bestComputedClass); opt=confMatPlot('defaultOpt'); opt.className=ds.outputName; figure; confMatPlot(confMat, opt);