Matlab 在多个映像上运行M-file并写入输出映像
我写了一个M文件。我想在多个图像上运行此M文件,然后通过单独命名写入output.tif图像。有没有简单的方法可以做到这一点Matlab 在多个映像上运行M-file并写入输出映像,matlab,Matlab,我写了一个M文件。我想在多个图像上运行此M文件,然后通过单独命名写入output.tif图像。有没有简单的方法可以做到这一点 谢谢大家最佳做法是编写函数: function img( inputName, outputName ) if ~iscell(inputName) img( {inputName}, {outputName} ); return; end for ii = 1:numel(inputName
谢谢大家最佳做法是编写函数:
function img( inputName, outputName )
if ~iscell(inputName)
img( {inputName}, {outputName} );
return;
end
for ii = 1:numel(inputName)
im = imread(inputName{ii});
...
[do operations on im]
...
imwrite(im, outputName{ii}, 'tiff');
end
end
您可以从脚本、类、函数或命令窗口调用它,如下所示:
img(...
{'file1.bmp', 'file2.bmp', ...},...
{'file1.tif', 'file2.tif', ...}...
);
[filename, pathname] = uigetfile( ...
{'*.bmp','bitmap-files (*.bmp)'; ...
'*.*', 'All Files (*.*)'}, ...
'Pick a file', ...
'MultiSelect', 'on');
您可以获得如下输入文件名:
img(...
{'file1.bmp', 'file2.bmp', ...},...
{'file1.tif', 'file2.tif', ...}...
);
[filename, pathname] = uigetfile( ...
{'*.bmp','bitmap-files (*.bmp)'; ...
'*.*', 'All Files (*.*)'}, ...
'Pick a file', ...
'MultiSelect', 'on');
所以你可以用
if filename ~= 0
img(...
[char(pathname) char(filename)],
{'file1.tif', 'file2.tif', ...}...
);
else
error('No file selected.');
end
这已经表明您可以更好地回收输入文件名:
function img( fileNames )
... % function's mostly the same, except:
[pth,fname] = fileparts(fileNames{ii});
imwrite(im, [pth filesep fname '.tif'], 'tiff');
end
或者,为了在使用uigetfile
时更加方便
if filename ~= 0
img(pathname, filename);
else
error('No file selected.');
end
与
对你能告诉我输入文件是如何存储的,处理过程是怎样的,你希望输出结果是怎样的吗?对不起,我是matlab的新手。我可以在命令行上调用函数,逐个在单个图像上运行。我知道matlab非常灵活,可以同时在多个图像上运行函数。但我不知道怎么做。你能告诉我一些想法吗?要运行程序文件,使用2组2006年到2009年的月度图像作为输入来计算这些函数。这两组图像存储在两个不同的文件夹中。例如:“TMP”文件夹包含名为TMP_2006_4.tif、TMP_2006_5.tif…TMP_2009_10的文件,“rnf”文件夹包含rnf_2006_4、rnf_2006_5…rnf_2009_10的文件。当我在命令行上调用程序文件时,我一个接一个地输入图像。我不要这个。我想在2006-2009年的所有月度图像上以单个命令或单个程序文件的形式运行该程序。我想要的输出应该是clc_2006_4,clc_2006_5…clc_2009_10。谢谢Rody,我有两个问题。1.如何输入第二组输入数据。我是否需要在程序文件中输入此代码2次?在输入两个时间序列图像2之后。我如何告诉matlab在同一月份和同一年份的图像上运行这个程序。例如:;该程序首次在2006年4月的图像上运行。(tmp_2006_4和rnf_2006_4),然后输出clc_2006_4,第二次用于下个月的图像(tmp_2006_5和rnf_2006_5)等