img = imread('face.bmp'); %Assume the 'face.bmp' is in the current directory %You can even do this. img = imread('http://www.cse.ucsd.edu/classes/sp04/cse152/hw0/face.bmp'); img2 = rgb2gray(img); %Convert to grayscale img2 = 255 - double(img2); %You can add/subtract/multiply/divide a matrix with scalar. %Note that you need to convert the matrix %to double. Try remove the conversion and %see what happen. img2 = imresize(img2,0.5,'bicubic'); %Resize the image using bicubic interpolation. imwrite(uint8(img2),'face_small.bmp'); %Save the image. You need to convert it back to uint8. The reason can be seen in the function help: %help imwrite; % %... % %Data types % ---------- % Most of the supported image file formats store uint8 % data. PNG and TIFF additionally support uint16 data. For % grayscale and RGB images, IF THE DATA ARRAY IS DOUBLE, THE % ASSUMED DYNAMIC RANGE IS [0,1]. THE DATA ARRAY IS % AUTOMATICALLY SCALED BY 255 BEFORE BEING WRITTEN OUT AS % uint8. If the data array is uint8 or uint16, then it is % written out without scaling as uint8 or uint16, % respectively. NOTE: If logical data is written to a BMP, % PNG or TIFF file, it is assumed to be a binary image and % will be written with a bitdepth of 1. % % For indexed images, if the index array is double, then the % indices are first converted to zero-based indices by % subtracting 1 from each element, and then they are written % out as uint8. If the index array is uint8 or uint16, % then it is written out without modification as uint8 or % uint16, respectively. % % .... %Another way to do. img2 = rgb2gray(img); img2 = im2double(img2); %The function 'im2double' is used here %instead of 'double'. Note the different : %IM2DOUBLE takes an image as input, and returns an image of %class double. If the input image is of class double, the %output image is identical to it. If the input image is of %class logical, uint8 or uint16, im2double returns the %equivalent image of class double, rescaling or offsetting %the data as necessary. %DOUBLE Convert to double precision. %DOUBLE(X) returns the double precision value for X. %If X is already a double precision array, DOUBLE has %no effect. img2 = 1 - img2; img2 = imresize(img2,0.5,'bicubic'); imwrite(img2,'face_small.bmp') %Now, just for fun, try this one line solution imwrite(imresize(1-im2double(rgb2gray(imread('http://www.cse.ucsd.edu/classes/sp04/cse152/hw0/face.bmp'))),0.5,'bic'),'face_small.bmp');