bop 发表于 2009-5-4 15:35

【求助】批量读取图像(子文件夹)问题

在坛子里看到一个批量读取图像的函数。但是函数用到的是当前工作文件夹。
请问如果图像在工作路径下面的子文件夹里面,该如何设置?

例如当前工作路径为matlab\, 图像是在matlab\Image\front\ 下, 请问该如何设置?

clear
dList=dir('Image\front\*.tif');
k=length(dList);
for i=1:k
Image_data{i}=imread(dList(i).name); %请问这里该如何设置路径? 这样设置的话,imread(Image\front\dList(i).name) 。没有输出
end

如果源程序在matlab\code下面,图像在matlab\Image\front\下面,又该如何设置呢?

非常感谢谢

ChaChing 发表于 2009-5-4 16:17

Image_data{i}=imread(['Image\front\',dList(i).name]);

bop 发表于 2009-5-4 16:48

原帖由 ChaChing 于 2009-5-4 16:17 发表 http://www.chinavib.com/forum/images/common/back.gif
Image_data{i}=imread(['Image\front\',dList(i).name]);
多谢ChaChing,问题解决了。

再问一个延伸性的问题,如果想把该code写为一个函数,当调用该函数时,变量是路径,输出是image_data{i}
请问该如何处理?

再次感谢

ChaChing 发表于 2009-5-4 21:39

function Image_data=ReadImage(DirName)
dList=dir(); k=length(dList);
for i=1:k, Image_data{i}=imread(); end

bop 发表于 2009-5-20 16:42

原帖由 ChaChing 于 2009-5-4 21:39 发表 http://www.chinavib.com/forum/images/common/back.gif
function Image_data=ReadImage(DirName)
dList=dir(); k=length(dList);
for i=1:k, Image_data{i}=imread(); end

非常感谢
:@)
页: [1]
查看完整版本: 【求助】批量读取图像(子文件夹)问题