Matlab notes for image project % The imread command in Matlab is often useful for importing files such as % tiff, bmp, or jpg. % You may need to convert the data to type double after loading it. % For example: imfinfo('house.bmp') % gives information about image % If the ColorType is 'indexed', one need to read the image and colormap, [house,map]=imread('house.bmp','bmp'); figure; image(house);colormap(map) %% then convert it using ind2rgb or ind2gray : hg=ind2gray(house,map); %% use imshow or imagesc to show it: figure; imshow(hg) figure; imagesc(hg); colormap(gray) %% now can work with the file as with regular data file, for example: hgg=hg.*hg; figure; imagesc(hgg); colormap(gray) % Another example for truecolor image: imfinfo('boat.bmp') % gives information about image boat=imread('boat.bmp'); image(boat) % can use image, imagesc, imshow to see it size(boat) % gives file size - 200 x 200 x 3 in this case % because this is a truecolor image, take the first % component only (do not do that if your ColorType is 'indexed'): b1 = boat(:,:,1); % or use rgb2gray - it creates a grayscale intensity image from an RGB image: boat=rgb2gray(boat); % If you used rgb2gray or ind2gray to create a grayscale image file, % your data type is double, if not - % you may need to convert the file to double type: b1 = double(b1); % since MATLAB arithmetic operators cannot accept uint8 or uint16 data % % can use imagesc to see the image figure; imagesc(b1); colormap(gray); figure; image(b1,'CDataMapping','scaled'); colormap(gray); % now can work work with the file as with normal data file % for instance, square its elements: b_try=b1.*b1; figure; colormap(gray); imagesc(b_try) %%