function mmwrite( f, filename ) % MMWRITE Write a gray-scale image into a commercial file format. % % MMWRITE( F, FILENAME ) % % Input: % F - Gray-scale (uint8 or uint16) or binary image (logical uint8). % FILENAME - String. Name of the file. Possible extensions: tif, % hdf, jpg, bmp, pcx, xwd. % % MMWRITE writes the image F in the file FILENAME. This function % calls the MATLAB function IMWRITE. If the format generated is BMP, % PCX or XWD, a colormap is created to keep the compatibility with % IMWRITE. % % Examples % -------- % % a= uint8( ones(5,5) ); % mmwrite(a, 'ones5.bmp'); % b = mmreadgray('ones5.bmp') % % See also MMREADGRAY. % begin of the default argument automatic treatment % end of the default argument automatic treatment 1 if isa(f,'uint16') disp('Error: 16 bit images not supported'); return; end if (size(f,3) == 3) imwrite(f,filename); return; elseif (size(f,3) ~= 1) disp('Error: wrong number of image planes'); end % Look for EXTENSION part mext = []; ind = find(filename == '.'); if isempty(ind) mext = ''; else mext = filename(ind:end); end switch mext case {'.xwd','.XWD','.pcx','.PCX','.bmp','.BMP'} if (mmisbinary(f)) map(1,1:3) = 0; map(2,1:3) = 1; elseif isa(f, 'uint8') map = gray(256); elseif isa(f, 'uint16') map = gray(65535); else disp('Error: non supported image pixel type'); end imwrite(f,map,filename); otherwise % other formats, tif, hdf, jpg imwrite(f,filename); end % Copyright (c) 1998-2001 by SDC Information Systems.