Kimia_simple

Introductory PR experiment on blob images. It loads the images, computes features, creates scatterplot and estimates the nearest neighbor classification error.

PRTools and PRDataFiles should be in the path

Download the m-file from here. See http://37steps.com/prtools for more.

Contents

Section 1 Check availablity of toolboxes

PRTools and PRDataFiles should be in the path

if exist('ldc',         'file') ~= 2, error('PRTools not in path'); end
if exist('kimia_images','file') ~= 2, error('PRDataFiles not in path'); end
delfigs; % delete all figures to avoid clutter

Section 2 load datafile

Show all images, class sizes and class names

A = kimia_images; % accept downloading again, neglect warnings,
figure; show(A,12);
classnames(A)
     12  bone    
     12  van     
     12  elephant
     12  head    
     12  fork    
     12  fountain
     12  hammer  
     12  key     
     12  ray     
     12  turtle  
     12  glass   
     12  heart   
     12  misk    
     12  bird    
     12  brick   
     12  camel   
     12  car     
     12  children

Section 3 Select two classes

B = selclass(A,char('camel','elephant'));
figure; show(B,6);

Section 4 Compute features

Compute for every object its - area (sum of pixels inside) - perimeter (sum of pixels on the contour)

feat1 = im_stat([],'sum');
feat2 = filtim('bwperim')*im_stat([],'sum');
C = B*[feat1 feat2]*datasetm;
C = setfeatlab(C,{'Size','Perimenter'});
disp(+C);
        5455         726
        6209         692
        6489         594
        7145         621
        6169         742
        6333         542
        6749         675
        4830         605
        7194         516
        6900         623
        7244         558
        5443         597
        6337         538
        5464         566
        5597         526
        4793         485
        5000         493
        4632         499
        4766         515
        5923         612
        6299         576
        5783         572
        5895         553
        5004         520

Section 5 Scatterplots

Show the original scatterplot, after normalization on variance, and with a classifier

figure; scatterd(C,'legend'); axis equal; fontsize(14);
% Some tricky statements to get non-matching NN labels
[~,nn] = min(distm(C)+1e100*eye(size(C,1)));
hold on; scatterd(C(labcmp(getlab(C),getlab(C(nn,:))),:),'ko');
fontsize(14);

D = C*mapex(scalem,'variance');
figure; scatterd(D,'legend'); axis equal; fontsize(14);
% Some tricky statements to get non-matching NN labels
[~,nn] = min(distm(D)+1e100*eye(size(D,1)));
hold on; scatterd(D(labcmp(getlab(D),getlab(D(nn,:))),:),'ko');
fontsize(14);

figure; scatterd(D,'legend'); axis equal; fontsize(14);
plotc(knnc(D,1),'col');
fontsize(14);

Section 6 First classification

Compute the nearest neighbor errors for the two scatterplots

fprintf('LOO NN error of original features %4.2f\n',testk(C,1));
fprintf('LOO NN error of rescaled features %4.2f\n',testk(D,1));
LOO NN error of original features 0.29
LOO NN error of rescaled features 0.21