Demo illustrating Circular Histogram Local Binary Pattern (chlbp)

 Circular Histogram Local Binary Pattern.
 Usage
 ------
 H = chlbp(I , [N] , [R] , [map] , [shiftbox] );
 Inputs
 -------
 I                                     Input image (ny x nx x P) in UINT8 format.
 N                                     Number of sampling points (1 x nR) (default [N=8])
 R                                     Vector of Radius (1 x nR) (default [R=1]) ny>2max(R)+1 & nx>2max(R)+1
 map                                   Mapping of the chlbp (2^Nmax x  nR) in double format (default map = (0 : 255))
 shiftbox                              Shifting box parameters shiftbox (2 x 2 x nR) where [by , bx ; deltay , deltax] x nR (default shiftbox = [ny , nx ; 0 , 0])
                                       by, bx denote the size of subwindows analysis, deltay, deltax represent the shift the subwindows analysis.
 Outputs
 -------
 H                                     chlbp features (bin*nH x P) int UINT32 format where nH = nR*max(floor((ny - shiftbox(1,1,:))./shiftbox(2,1,:)) + 1 , 1)*max(floor((nx - shiftbox(1,2,:))./shiftbox(2,2,:)) + 1 , 1)

Contents

First example : compute Uniform CHLBP Features with N =8 neighbours and Radius R = 1 with a subwindows analysis of 64x64 shifted by 16x16

clc,clear, close all,drawnow
I                  = (imread('rice.png'));
N                  = 8;
R                  = 1;
mapping            = getmapping(N,'u2');
map                = mapping.table';
shiftbox           = [64 , 64 ; 16 , 16];
H                  = chlbp(I , N  , R , map , shiftbox);
plot(H)
title(sprintf('Uniform CHLBP Histogram with N = %d, R = %d' , N , R))


disp('Press key to continue')
pause
Warning: Calling MEX-file 'C:\utilisateurs\SeBy\matlab\fdtool\chlbp.dll'.
MEX-files with .dll extensions will not execute in a future version of MATLAB. 
Press key to continue

Second example : compute CHLBP_{8;1}^u Features on Viola-Jones database

load viola_24x24
Ny                 = 24;
Nx                 = 24;
N                  = 8;
R                  = 1;
mapping            = getmapping(N,'u2');
map                = mapping.table';

H                  = chlbp(X , N , R , map);
imagesc(H)
title(sprintf('Uniform CHLBP Histogram with N = %d, R = %d' , N , R))

disp('Press key to continue')
pause
Press key to continue

Third example : compute CHLBP_{8;1}^u + CHLBP_{4;1} Features

Ny                 = 19;
Nx                 = 19;
X                  = uint8(ceil(256*rand(Ny , Nx)));

N                  = [8 , 4];
R                  = [1 , 1];
map                = zeros(2^max(N) , length(N));
mapping            = getmapping(N(1),'u2');
map(: , 1)         = mapping.table';
map(1:2^N(2) , 2)  = (0:2^N(2)-1)';
shiftbox           = cat(3 , [Ny , Nx ; 0 , 0] , [10 , 10 ; 4 , 4]);


H                  = chlbp(X , N , R , map , shiftbox);
plot(H)
title('CHLBP_{8;1}^u + CHLBP_{4;1} Histogram')

disp('Press key to continue')
pause
Warning: Out of range value converted to intmin('uint8') or intmax('uint8'). 
Press key to continue

Fourth example : compute CHLBP_{8;1}^u + CHLBP_{4;1} Features + Adaboosting with T weaklearners (Decision Stump)

load viola_24x24
Ny                         = 24;
Nx                         = 24;
N                          = [8 , 4];
R                          = [1 , 1];
map                        = zeros(2^max(N) , length(N));
mapping                    = getmapping(N(1),'u2');
map(1:2^N(1) , 1)          = mapping.table';
map(1:2^N(2) , 2)          = (0:2^N(2)-1)';
shiftbox                   = cat(3 , [Ny , Nx ; 1 , 1] , [16 , 16 ; 4 , 4]);

T                          = 50;


H                          = chlbp(X , N , R , map , shiftbox);
figure
imagesc(H)
title('CHLBP Features')
drawnow

y                          = int8(y);
indp                       = find(y == 1);
indn                       = find(y ==-1);


index                      = randperm(length(y));  %shuffle data to avoid numerical discrepancies with long sequence of same label


model                      = chlbp_adaboost_binary_model_cascade(H(: , index) , y(index) , T);
[yest_train , fx_train]    = chlbp_adaboost_binary_predict_cascade(H , model);

tp_train                   = sum(yest_train(indp) == y(indp))/length(indp)
fp_train                   = 1 - sum(yest_train(indn) == y(indn))/length(indn)
Perf_train                 = sum(yest_train == y)/length(y)

[dum , ind]               = sort(y , 'descend');
figure
plot(fx_train(ind))
title(sprintf('Output of the strong classifier for train data with T = %d' , T))



[tpp_train , fpp_train]    = basicroc(y , fx_train);

load jensen_24x24

y                          = int8(y);
indp                       = find(y == 1);
indn                       = find(y ==-1);


H                          = chlbp(X , N , R , map , shiftbox);
[yest_test , fx_test]      = chlbp_adaboost_binary_predict_cascade(H , model);

tp_test                    = sum(yest_test(indp) == y(indp))/length(indp)
fp_test                    = 1 - sum(yest_test(indn) == y(indn))/length(indn)
Perf_test                  = sum(yest_test == y)/length(y)

[dum , ind]               = sort(y , 'descend');
figure
plot(fx_test(ind))
title(sprintf('Output of the strong classifier for test data with T = %d' , T))



[tpp_test , fpp_test]    = basicroc(y , fx_test);


figure
plot(fpp_train , tpp_train , fpp_test , tpp_test , 'r' , 'linewidth' , 2)
axis([-0.02 , 1.02 , -0.02 , 1.02])
title(sprintf('ROC for CHLBP features with T = %d' , T))
legend('Train' , 'Test' , 'Location' , 'SouthEast')



disp('Press key to continue')
pause
Warning: Calling MEX-file 'C:\utilisateurs\SeBy\matlab\fdtool\chlbp_adaboost_binary_model_cascade.dll'.
MEX-files with .dll extensions will not execute in a future version of MATLAB. 
Warning: Calling MEX-file 'C:\utilisateurs\SeBy\matlab\fdtool\chlbp_adaboost_binary_predict_cascade.dll'.
MEX-files with .dll extensions will not execute in a future version of MATLAB. 

tp_train =

    0.9463


fp_train =

    0.0351


Perf_train =

    0.9578


tp_test =

    0.9642


fp_test =

    0.0340


Perf_test =

    0.9657

Press key to continue

Fifth example : compute CHLBP_{8;1}^u + CHLBP_{4;1} + CHLBP_{12;2}^u Features + Gentleboosting with T weaklearners (Decision Stump)

load viola_24x24
Ny                         = 24;
Nx                         = 24;
N                          = [8 , 4 , 12];
R                          = [1 , 1 , 2];
map                        = zeros(2^max(N) , length(N));

mapping                    = getmapping(N(1),'u2');
map(1:2^N(1) , 1)          = mapping.table';
map(1:2^N(2) , 2)          = (0:2^N(2)-1)';
mapping                    = getmapping(N(3),'u2');
map(1:2^N(3) , 3)          = mapping.table';
shiftbox                   = cat(3 , [Ny , Nx ; 1 , 1] , [16 , 16 ; 4 , 4] , [Ny , Nx ; 1 , 1]);

T                          = 50;

H                          = chlbp(X , N , R , map , shiftbox);
figure
imagesc(H)
title('CHLBP Features')
drawnow

y                          = int8(y);
indp                       = find(y == 1);
indn                       = find(y ==-1);

index                      = randperm(length(y));  %shuffle data to avoid numerical discrepancies with long sequence of same label

model                      = chlbp_gentleboost_binary_model_cascade(H(: , index) , y(index) , T);
[yest_train , fx_train]    = chlbp_gentleboost_binary_predict_cascade(H , model);

tp_train                   = sum(yest_train(indp) == y(indp))/length(indp)
fp_train                   = 1 - sum(yest_train(indn) == y(indn))/length(indn)
Perf_train                 = sum(yest_train == y)/length(y)

[dum , ind]               = sort(y , 'descend');
figure
plot(fx_train(ind))
title(sprintf('Output of the strong classifier for train data with T = %d' , T))


[tpp_train , fpp_train]    = basicroc(y , fx_train);

load jensen_24x24

y                          = int8(y);
indp                       = find(y == 1);
indn                       = find(y ==-1);

H                          = chlbp(X , N , R , map , shiftbox);
[yest_test , fx_test]      = chlbp_gentleboost_binary_predict_cascade(H , model);

tp_test                    = sum(yest_test(indp) == y(indp))/length(indp)
fp_test                    = 1 - sum(yest_test(indn) == y(indn))/length(indn)
Perf_test                  = sum(yest_test == y)/length(y)

[dum , ind]               = sort(y , 'descend');
figure
plot(fx_test(ind))
title(sprintf('Output of the strong classifier for test data with T = %d' , T))


[tpp_test , fpp_test]    = basicroc(y , fx_test);


figure
plot(fpp_train , tpp_train , fpp_test , tpp_test , 'r' , 'linewidth' , 2)
axis([-0.02 , 1.02 , -0.02 , 1.02])
title(sprintf('ROC for CHLBP features with T = %d' , T))
legend('Train' , 'Test', 'Location' , 'SouthEast')

disp('Press key to continue')
pause
Warning: Calling MEX-file 'C:\utilisateurs\SeBy\matlab\fdtool\chlbp_gentleboost_binary_model_cascade.dll'.
MEX-files with .dll extensions will not execute in a future version of MATLAB. 
Warning: Calling MEX-file 'C:\utilisateurs\SeBy\matlab\fdtool\chlbp_gentleboost_binary_predict_cascade.dll'.
MEX-files with .dll extensions will not execute in a future version of MATLAB. 

tp_train =

    0.9585


fp_train =

    0.0227


Perf_train =

    0.9701


tp_test =

    0.9804


fp_test =

    0.0244


Perf_test =

    0.9765

Press key to continue

Sith example : CHLBP_{8;1}^u versus CHLBP_{8;1} Features + Gentleboosting with T weaklearners (Decision Stump)

load viola_24x24

y                          = int8(y);
indp                       = find(y == 1);
indn                       = find(y ==-1);

Ny                         = 24;
Nx                         = 24;
N                          = 8;
R                          = 1;
map                        = zeros(2^max(N) , length(N));

mapping                    = getmapping(N(1),'u2');
map0                       = mapping.table';
map1                       = (0:2^N-1)';

T                          = 50;

H0                         = chlbp(X , N , R , map0);
H1                         = chlbp(X , N , R , map1);



figure
imagesc(H0)
title(sprintf('Uniform CHLBP Features with N = %d, R = %2.1f' , N , R))
drawnow



figure
imagesc(H1)
title(sprintf('CHLBP Features with N = %d, R = %2.1f' , N , R))
drawnow



index                      = randperm(length(y));  %shuffle data to avoid numerical discrepancies with long sequence of same label

model0                     = chlbp_gentleboost_binary_model_cascade(H0(: , index) , y(index) , T);
[yest0_train , fx0_train]  = chlbp_gentleboost_binary_predict_cascade(H0 , model0);


model1                     = chlbp_gentleboost_binary_model_cascade(H1(: , index) , y(index) , T);
[yest1_train , fx1_train]  = chlbp_gentleboost_binary_predict_cascade(H1 , model1);


tp0_train                  = sum(yest0_train(indp) == y(indp))/length(indp)
fp0_train                  = 1 - sum(yest0_train(indn) == y(indn))/length(indn)
Perf0_train                = sum(yest0_train == y)/length(y)


tp1_train                  = sum(yest1_train(indp) == y(indp))/length(indp)
fp1_train                  = 1 - sum(yest1_train(indn) == y(indn))/length(indn)
Perf1_train                = sum(yest1_train == y)/length(y)


[dum , ind]               = sort(y , 'descend');

figure
plot((1:length(y)) , fx0_train(ind) , (1:length(y)) , fx1_train(ind) , 'r')
title(sprintf('Output of the strong classifier for train data with T = %d' , T))
legend('Uniform CHLBP' , 'CHLBP')


[tpp0_train , fpp0_train]  = basicroc(y , fx0_train);
[tpp1_train , fpp1_train]  = basicroc(y , fx1_train);


load jensen_24x24

y                          = int8(y);
indp                       = find(y == 1);
indn                       = find(y ==-1);


H0                         = chlbp(X , N , R , map0);
H1                         = chlbp(X , N , R , map1);

[yest0_test , fx0_test]    = chlbp_gentleboost_binary_predict_cascade(H0 , model0);
[yest1_test , fx1_test]    = chlbp_gentleboost_binary_predict_cascade(H1 , model1);


tp0_test                   = sum(yest0_test(indp) == y(indp))/length(indp)
fp0_test                   = 1 - sum(yest0_test(indn) == y(indn))/length(indn)
Perf0_test                 = sum(yest0_test == y)/length(y)


tp1_test                   = sum(yest1_test(indp) == y(indp))/length(indp)
fp1_test                   = 1 - sum(yest1_test(indn) == y(indn))/length(indn)
Perf1_test                 = sum(yest1_test == y)/length(y)


[dum , ind]                = sort(y , 'descend');

figure
plot((1:length(y)) , fx0_test(ind) , (1:length(y)) , fx1_test(ind) , 'r')
title(sprintf('Output of the strong classifier for test data with T = %d' , T))
legend('Uniform CHLBP' , 'CHLBP')


[tpp0_test , fpp0_test]   = basicroc(y , fx0_test);
[tpp1_test , fpp1_test]   = basicroc(y , fx1_test);


figure
plot(fpp0_train , tpp0_train , 'b' , fpp0_test , tpp0_test , 'r' , fpp1_train , tpp1_train , 'b--' , fpp1_test , tpp1_test , 'r--' , 'linewidth' , 2)
axis([-0.02 , 1.02 , -0.02 , 1.02])
title(sprintf('ROC for U-CHLBP and CHLBP features with T = %d' , T))
legend('Train U-CHLBP' , 'Test U-CHLBP' , 'Train CHLBP' , 'Test CHLBP' , 'Location' , 'SouthEast')
tp0_train =

    0.9203


fp0_train =

    0.0591


Perf0_train =

    0.9330


tp1_train =

    0.9146


fp1_train =

    0.0535


Perf1_train =

    0.9342


tp0_test =

    0.9430


fp0_test =

    0.0428


Perf0_test =

    0.9547


tp1_test =

    0.9446


fp1_test =

    0.0515


Perf1_test =

    0.9478