%(c) Eamonn Keogh and Abdullah Mueen

function ts = im2ts(I)
RED(1:256) = 0;
BLUE(1:256) = 0;
GREEN(1:256) = 0;
if size(I,3) ~= 3 && size(I,1) ~= 32 && size(I,2) ~= 32 && size(I,3) ~= 3
    disp('Dimension should be 32X32X3');
    ts = [];
else
    for j = 1:size(I,1)
       for k = 1:size(I,2)
            %Since Matlab indexes from 1
            RED(I(j,k,1)+1) = RED(I(j,k,1)+1) + 1;
            BLUE(I(j,k,3)+1) = BLUE(I(j,k,3)+1) + 1;
            GREEN(I(j,k,2)+1) = GREEN(I(j,k,2)+1) + 1;
       end
    end
 
    RED = ( RED - mean(RED) ) / std(RED);
    BLUE = ( BLUE - mean(BLUE) ) / std(BLUE);
    GREEN = ( GREEN - mean (GREEN) ) / std(GREEN);
    ts = [RED,GREEN,BLUE];
end
