I am working with a huge set of image stacks. Instead of importing 100 images 1 by 1, I want to do this programmatically. I would like to either:
1) create a variable with the image name i.e. traces01, traces 02, ... traces 99. similiar to the command below
traces01 = imread('traces01.tif');
2) bring all images into a struct similiar to below
images.traces01 = imread('traces01.tif');
I have successfully created a ImportName variable with all 100 image names through the sprintf command using a for loop. I just cannot figure out how to now move to using a for loop to accomplish
images.ImportName(i) = imread(ImportName(i));
thanks for anyone's help.

 採用された回答

Voss
Voss 2022 年 4 月 15 日

1 投票

If ImportName is a cell array of character vectors, like this:
ImportName = sprintfc("traces%02d",1:5)
ImportName = 1×5 cell array
{'traces01'} {'traces02'} {'traces03'} {'traces04'} {'traces05'}
Then building that images struct might look like this:
for ii = 1:numel(ImportName)
images.(ImportName{ii}) = imread([ImportName{ii} '.tif']);
end
Or if ImportName is a string array, like this:
ImportName = string(sprintfc('traces%02d',1:5))
ImportName = 1×5 string array
"traces01" "traces02" "traces03" "traces04" "traces05"
Then building the images struct might look like this:
for ii = 1:numel(ImportName)
images.(ImportName(ii)) = imread([ImportName(ii) + ".tif"]);
end
However, it may be more convenient for your purpose (I don't know) to build a struct array, each element of which contains the name of an image file ...
(if ImportName is a cell array of character vectors:)
images = struct('file_name',ImportName); % struct array
(if ImportName is a string array:)
images = struct('file_name',cellstr(ImportName)); % struct array
... and the image data ...
for ii = 1:numel(images)
images(ii).image_data = imread(images(ii).file_name);
end
... and any other information you want to associate with each image/image file.

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeConvert Image Type についてさらに検索

製品

リリース

R2019a

質問済み:

2022 年 4 月 14 日

回答済み:

2022 年 4 月 15 日

Community Treasure Hunt

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

Start Hunting!

Translated by