function [imX,imMAP,sFile]=loadimg(sArgument,iShowOn); %% -------------------------------------------------------------------- %% % Function: 加载一个图像文件。 % if 参数为空 % 打开当前目录选择一个图像文件; % else % if 参数以'\'结尾 % 打开该参数特定目录选择一个图像文件; % else % 打开该参数特定文件; % end % end % Argument: sArgument: 输入参数 % imX: image data % imMAP: colormap % sFile: 文件名 % Example: imCover = loadimg('d:\images\lena.bmp'); % 特定文件 % imCover = loadimg('d:\temp\'); % 特定目录,注意以'\'结尾 % imCover = loadimg; % 当前目录 % Version: 2.10.20081231,2.02.20080625,1.03.20070912 % Email: weiweimin@hotmail.com % Web: http://www.TrueMark.cn %% -------------------------------------------------------------------- %% imX = []; imMAP = []; sFile = ''; % 支持的图像文件名后缀, 参考imread, 不常用的格式: HDF,XWD,RAS,PBM,PGM,PPM sFileType = '*.bmp;*.jpg;*.jpeg;*.gif;*.tif;*.tiff;*.png;*.ico;*.cur;*.pcx'; if( ~exist('sArgument') ) % 当前目录 sFilterSpec = sFileType; else if sArgument(length(sArgument)) == '\' % 特定目录 sFilterSpec = [sArgument,sFileType]; else sFile = sArgument; % 特定文件 end end if isempty(sFile) sDialogTitle = 'Please select an image file'; [filename, pathname] = uigetfile(sFilterSpec, sDialogTitle); if isequal(filename,0) || isequal(pathname,0) % User pressed Cancel disp('User pressed Cancel'); return; end sFile=[pathname filename]; end if( ~exist('iShowOn') ) iShowOn = 1; end try [imX,imMAP]=imread(sFile); catch disp(['Error: Can not open file [',sFile,']']); return; end [iH iW iL]=size(imX); if iShowOn == 1 disp(['Loaded image [',num2str(iH),'*',num2str(iW),'*',num2str(iL),']: ',sFile]); end %% -------------------------------------------------------------------- %%