12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- clear all
- close all
- clc
- addpath('../Functions');
- imgSz=28; % Lateral Image pixel size
- imgSzSq=imgSz^2; % Square Image pixel size
- Ntr=6e4; % Number of pictures train set
- Ntests=1e4; % Number of pictures test set
- fileOffsetPic=16; % Bytes of pictures file offset
- fileOffsetLab=8; % Bytes of label file offset
- ENNSon=0; %
- %% Reading Binary Training Images and Labels
- [XSet, XLab]=ReadingPicSetLabSet(imgSz, Ntr, fileOffsetPic, '../Data/train-images.idx3-ubyte',...
- fileOffsetLab, '../Data/train-labels.idx1-ubyte', 0);
- %% Reading Binary Testing Images and Labels
- [YSet, YLab]=ReadingPicSetLabSet(imgSz, Ntests, fileOffsetPic, '../Data/t10k-images.idx3-ubyte',...
- fileOffsetLab, '../Data/t10k-labels.idx1-ubyte', 0);
- %% Computing NNS with Euclidean Distance
- if(ENNSon)
- fprintf('Computing Euclidean NNS: ... ');
- dEuc=zeros(1,Ntr);
- indmin=zeros(1,Ntests);
- for ii=1:Ntests
- for jj=1:Ntr
- Xjj=XSet(imgSzSq*(jj-1)+1:imgSzSq*jj);
- Yii=YSet(imgSzSq*(ii-1)+1:imgSzSq*ii);
- dEuc(jj)=sum((Xjj-Yii).^2);
- end
- [~,indmin(ii)]=min(dEuc);
- fprintf('\b\b\b\b\b\b%3.2f %%',ii/Ntests*100);
- end
- else
- fprintf('Loading Euclidean NNS results ...');
- load('indminEuNNS.mat')
- end
- %% Plot some of the matches
- %Nstart=9983;
- %for kk=Nstart+1:Nstart+10%Ntests
- %subplot(2,10,kk-Nstart)
- %imshow255(0,imgSz,YSet')
- %xlabel(int2str(YLab(kk)));
- %title('Test Image')
- %subplot(2,10,kk-Nstart+10)
- %figure()
- %imshow255(0,imgSz,XSet(indmin(1))')
- %xlabel(int2str(XLab(indmin(kk))));
- %title('Match Image')
- %end
- NErrors=Ntests-sum(XLab(indmin)==YLab(1:length(indmin)));
- Performances=100-NErrors/Ntests*100
|