function imgray=rgbim2gray(im)
    im=double(im);
    r=im(:,:,1);g=im(:,:,2);b=im(:,:,3);
    imgray=0.2126*r+0.7152*g+0.0722*b;