%   LCOD returns the Local Color Occurrence Descriptor of an image.
%   This code is written by Shiv Ram Dubey, IIIT Allahabad
%   This code can be used only for the academic and research purposes and can not be used for any commercial purposes.
%   Cite the paper 'Shiv Ram Dubey, Satish Kumar Singh, Rajat Kumar Singh, 
%		"Local Neighbourhood-based Robust Colour Occurrence Descriptor for Colour Image Retrieval," 
%		IET Image Processing (IET-IP), 9(7):578-586, 2015.',
%		In case you are using this code.

function des=LCOD(path_image)
%path_image='644000.jpg';
% path_image='datasets\corel-1k\art_dino\644000.jpg';
img=imread(path_image);
% figure;subplot(2,2,1);imshow(img,[]);
totalquant=4;
[row_img,col_img,chan_img]=size(img);
img=reshape(img,1,row_img*col_img*chan_img);
[hi, in]=histc(img, 0:255/totalquant:255);in(in==5)=4;
img=reshape(in-1,row_img,col_img,chan_img);
img=16*img(:,:,1)+4*img(:,:,2)+img(:,:,3)+1;
si=size(img);
% subplot(2,2,2);imshow(img,[]);

D=1;
bit=ceil(log2((2*D+1).^2));
des=zeros(1,bit*totalquant.^3);
t=0;
for i=-D:D
    for j=-D:D
        t=t+1;
        img1(:,:,t)=img(D+1+i:end-D+i, D+1+j:end-D+j);
    end
end
des=[];
for k=1:totalquant.^3
    des=[des sum(de2bi(sum(img1==k,3),bit))];
end

des=des/sum(des);
end 
