function [imgray] = convert2gray(image,colormap,string)

imgray = zeros(length(image(:,1,1)),length(image(1,:,1)));
h = waitbar(0,strcat('Processing image',string));
for i = 1:length(image(:,1,1))
    for j= 1:length(image(1,:,1))
        for k = 1:length(colormap(:,1));
            if image(i,j,1) == colormap(k,1)
                if image(i,j,2) == colormap(k,2)
                    if image(i,j,3) == colormap(k,3)
                    imgray(i,j) = k;
                    break
                    end                    
                end
            end
        end
    end
    waitbar(i/length(image(:,1,1)));
end
close(h);