在MATLAB中批量保存具有不同文件名的图像文件

时间:2012-10-22 16:39:44

标签: image matlab batch-file save

我正在对图像文件集进行一些批处理,要求文件应该在文件名末尾附加一个“_corrected”字符串保存,例如'IMG_001.tif'应该在处理后保存。 'IMG_001_corrected.jpg'。

这是我的代码:

FileList = dir('srgb8bit/*.tif');
N = size(FileList,1);

for k = 1:N

   % get the file name:
   filename = FileList(k).name;
   I = imread(filename);
   Icorr = CorrectedRetinexFM(I,8);
   ** Here should go the save command**

最好能够选择不同的目录来保存它们。怎么可能?

非常感谢你的帮助!

1 个答案:

答案 0 :(得分:4)

使用fileparts拆分文件名及其扩展名:

[pathstr, name, ext] = fileparts(FileList(k).name);

请注意pathstr是“”,因为您已经剥离了它。

然后像这样imwrite

imwrite(Icorr, [name '_corrected.jpg']);
相关问题