Saving Output to Specified Folder Location

6 次查看(过去 30 天)
Hello, I currently have a code that creates 18 arrays and saves them as .tif files. The .tif files are saved in the same folder path where my input and my code are found. However, my end goal would be to save each array to a new folder. Any help would be greatly appreciated!
  4 个评论
Image Analyst
Image Analyst 2017-10-9
编辑:Image Analyst 2017-10-9
For example
imageFolder = 'D:/whatever';
baseFileNameWithExtension = 'awesome.PNG';
fullFileName = fullfile(imageFolder, baseFileNameWithExtension);
% Convert any numerical array to uint8.
uint8Image = uint8(255 * mat2gray(array));
% Write to disk.
imwrite(uint8Image, fullFileName);
Did you see Walter's solution below before you posted the question?

请先登录,再进行评论。

回答(1 个)

Walter Roberson
Walter Roberson 2017-10-6
projectdir = 'TheParentDirectory\whatever';
for idx = 1 : 18
... generate YourArray
subdir = fullfile(projectdir, sprintf('ImageDir_%02d', idx));
if ~exist(subdir, 'dir')
mkdir(subdir);
end
filename = sprintf('Output_file_%02d.tif', idx);
fullname = fullfile(subdir, filename);
imwrite(YourArray, fullname);
end

类别

Help CenterFile Exchange 中查找有关 Convert Image Type 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by