【问题标题】:Batch save image files with different filename in MATLAB在 MATLAB 中批量保存不同文件名的图像文件
【发布时间】:2012-10-12 12:33:53
【问题描述】:

我正在对图像文件集进行一些批处理,这要求文件应在文件名末尾附加一个“_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**

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

非常感谢您的帮助!

【问题讨论】:

  • 您读取图像的代码不起作用,因为 file.name 字段仅包含文件的名称,而不包含文件的路径。你需要filename = ['srgb8bit/' FileList(k).name];。你可以用同样的方法创建你想要保存的文件。

标签: image matlab batch-file save


【解决方案1】:

使用fileparts分割文件名和扩展名:

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

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

然后像这样imwrite

imwrite(Icorr, [name '_corrected.jpg']);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-06-27
    • 2015-09-17
    • 1970-01-01
    • 2019-05-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多