Saving Output to Specified Folder Location

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

Why can't you just include the path as part of the name when you save the files?
RB
RB 2017년 10월 9일
This would be ideal! Currently I am saving files using: imwrite (logical(array), 'filename', 'Compression', 'none); How would I go about adding the file path to this code to save the array? Thank you!
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?
... just like I showed below.

댓글을 달려면 로그인하십시오.

답변 (1개)

Walter Roberson
Walter Roberson 2017년 10월 6일

0 개 추천

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

카테고리

도움말 센터File Exchange에서 Convert Image Type에 대해 자세히 알아보기

질문:

RB
2017년 10월 6일

댓글:

2017년 10월 9일

Community Treasure Hunt

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

Start Hunting!

Translated by