Im= imread('C:\Documents and Settings\All Users\Documents\My Pictures\Sample Pictures\Sunset.jpg');
Gray_Im=uint8(zeros(size(Im,1),size(Im,2)));

%[r,c]=size(Im);

%GIm=uint8(zeros(r,c));

for i=1:size(Im,1)
      for j=1:size(Im,2)
          Gray_Im(i,j)=0.2989*Im(i,j,1)+0.5870*Im(i,j,2)+0.1140*Im(i,j,3);
      end
end

subplot(1,2,1);imshow(Im);
subplot(1,2,2);imshow(Gray_Im);