A=imread('elephant.pgm');  %read grayscale image from file
B=double(A)/255;           %convert to double values in 0-1 range.
imagesc(B);                %display image, with range scaling
colormap gray;             %set colormap to graylevels
B(50:60,20:30) = 0;        %change the image
B(70:80,20:30) = 0.5;
B(100:120,20:30) = 1;
imwrite(B,'test.pgm');     %save grayscale image to file
