How integral image influence the result of local binary pattern or center symmetric local binary pattern

I know this looks somehow not related to code errors and development but I want to know if someone can understand these codes of integral image and local binary pattern, and tell me how they affect the resulting histograms.

Before the use of integral image the output histogram is normal, but after applying the integral image method I found that most of the histogram changed to zeros. To clarify things, the expected benefit from the use of an integral image is to speed up the process of lbp method. In fact, I haven't seen this before because I'm trying it for the first time. Does anybody who knows about this may help me please?

These are the codes of every method:

Integral image

function [outimg] = integral( image )
[y,x] = size(image);
outimg = zeros(y+1,x+1);
disp(y);
for a = 1:y+1
    for  b = 1:x+1
        rx = b-1;
        ry = a-1;
        while ry>=1
            while rx>=1  
                outimg(a,b) = outimg(a,b)+image(ry,rx);
                rx = rx-1;
            end
            rx = b-1;
            ry = ry-1;
        end
        % outimg(a,b) = outimg(a,b)-image(a,b);
    end   
end
% outimg(1,1) = image(1,1);
disp('end loop');
end

CS-LBP

function h = CSLBP(I)
%% this function takes patch or image as input and return Histogram of
%% CSLBP operator. 
h = zeros(1,16);
[y,x] = size(I);
T = 0.1; % threshold given by authors in their paper
for i = 2:y-1
    for j = 2:x-1
        % keeping I(j,i) as center we compute CSLBP
        % N0 - N4
        a = ((I(i,j+1) - I(i, j-1) > T ) * 2^0 );        
        b = ((I(i+1,j+1) - I(i-1, j-1) > T ) * 2^1 );
        c = ((I(i+1,j) - I(i-1, j) > T ) * 2^2 );
        d = ((I(i+1,j-1) - I(i - 1, j + 1) > T ) * 2^3 );
        e = a+b+c+d;
        h(e+1) = h(e+1) + 1;
    end
end
end

Upvotes: 0

Views: 198

Answers (1)

Tapio
Tapio

Reputation: 1642

Matlab has an inbuilt function for creating integral images, integralimage(). If you don't want to use the computer vision system toolbox you can achieve the same result by calling:

IntIm = cumsum(cumsum(double(I)),2);

Possibly adding padding if needed. You should check out that the image is not saturated, they do that sometimes. Calculating the cumulative sum goes to integers way above the range of uint8 and uint16 quickly, I even had it happen with a double once!

Upvotes: 1

Related Questions