Previously, i wrote a code for Local Binary Pattern(LBP) and Obtained a LBP image and histogram. Now i would like to divide the image into 6×6 matrixes and obtain the LBP image and histogram for each 6×6 matrix. I written the code below. But it doesnt work that well.
I2=imread('CropF.jpg');
m=size(I2,1);
n=size(I2,2);
counter = 1;
for i=2:6:m-1
for j=2:6:n-1
for k=i:i+6
for l=j:j+6
J0=I2(k,l);
I3(k-1,l-1)=I2(k-1,l-1)>J0;
I3(k-1,l)=I2(k-1,l)>J0;
I3(k-1,l+1)=I2(k-1,l+1)>J0;
I3(k,l+1)=I2(k,l+1)>J0;
I3(k+1,l+1)=I2(k+1,l+1)>J0;
I3(k+1,l)=I2(k+1,l)>J0;
I3(k+1,l-1)=I2(k+1,l-1)>J0;
I3(k,l-1)=I2(k,l-1)>J0;
LBP(k,l)=I3(k-1,l-1)*2^7+I3(k-1,l)*2^6+I3(k-1,l+1)*2^5+I3(k,l+1)*2^4+I3(k+1,l+1)*2^3+I3(k+1,l)*2^2+I3(k+1,l-1)*2^1+I3(k,l-1)*2^0;
end
end
LBP=uint8(LBP);
LBPv=reshape(LBP,1,size(LBP,1)*size(LBP,2));
Hist=hist(LBPv,0:255);
Hist1(counter,:)= Hist;
fname = sprintf('HistInf%03d.mat', counter);
save(fullfile(BASE_DIR,fname), 'Hist');
counter = counter + 1;
end
end
save('C:\Users\Lakshmen\Documents\MATLAB\HistInfMain','Hist1');
I have an error like this : ??? Index exceeds matrix dimensions.
Morever, the value for m and n I get is 394 and 330. Hence the value i should get for counter is 55 which is what i get but I get the error said above.
I guess you are still working on the problem from your previous questions.
I am assuming that
mandndenote the size of theI2matrix. If that is the case, then the issue here is with the two inner loops for thekandlvariables. They go from the current values ofiandjand go up toi+6andj+6. Butiandjthemselves can reachm-1andn-1respectively thus you get “out of bound” errors.If I am correct, you need to change the upper bounds of the
i,jfor-loops: