function lsl_rgb2gray()
%%%%%%%%%%%
彩色图像批量转灰度图像
%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%2009
年
6
月
29
日
%%%%%%%%%%%%%%%%%%%%%%
pathname=uigetdir(cd,'
请选择文件夹
');
if pathname==0
msgbox('
您没有正确选择文件夹
')
return
end
files=dir(strcat(pathname,'\*.bmp'));
len=length(files);
for ii=1:len
Filesname{ii}=strcat(pathname,'\',files(ii).name);
fname{ii}=files(ii).name;
page{ii}=imread(Filesname{ii});
page1{ii}= rgb2gray(page{ii});
% page2{ii}= double(
page1{ii}) / 255;
% figure,imshow(page{ii});
% figure,imshow( page1{ii});
end
%%%%%%%%%%%%%%%%
保存转换后的图片
%%%%%%%%%%%%%%%%%%%%%%%%%
for ii=1:len
FileName = strcat( Filesname{ii},'.bmp');
imwrite(page1{ii},FileName);
end
msgbox('
程序执行完毕
')