% colourfeature
% usage: colourfeature1D(pic,numbins,colourlist)
% read a jpeg image and split into three RGB components
% return picture with colors in the 3D bins specified by colorlist
% pic is the name of a jpg file given in 'filename.jpg' format
% typically the component images will be returned as matrices of byte-sized unsigned integers
% allowing 256 levels for each colour, i.e., 24 bit colour
% Rmap, Gmap and Bmap are colormaps for showing the R,G,B components
function colourfeature(pic,numbins,colourlist);
% load picture
[R,G,B,Rmap,Gmap,Bmap] = jpg2rgb(pic,'nopic');
% show initial image
figure(1)
clf
imshow(cat(3,R,G,B));
pause
% compute featue
X = double(R(:));
Y = double(G(:));
Z = double(B(:));
mX = min(X);
MX = max(X);
mY = min(Y);
MY = max(Y);
mZ = min(Z);
MZ = max(Z);
numpix = length(X);
X = ceil((numbins/(MX-mX))*(X-mX));
J = find(X<1);
X(J) = 1;
J = find(X>numbins);
X(J) = numbins;
Y = ceil((numbins/(MY-mY))*(Y-mY));
J = find(Y<1);
Y(J) = 1;
J = find(Y>numbins);
Y(J) = numbins;
Z = ceil((numbins/(MZ-mZ))*(Z-mZ));
J = find(Z<1);
Z(J) = 1;
J = find(Z>numbins);
Z(J) = numbins;
R1 = uint8(zeros(size(R)));
G1 = R1;
B1 =R1;
for j= 1:size(colourlist,1)
I = find(X==colourlist(j,1) & Y==colourlist(j,2) & Z==colourlist(j,3));
R1(I) = R(I);
G1(I) = G(I);
B1(I) = B(I);
end;
% show feature
figure(2)
clf
imshow(cat(3,R1,G1,B1));