필터 지우기
필터 지우기

Reading the image sequency

조회 수: 1 (최근 30일)
Bipul Biswas
Bipul Biswas 2023년 10월 31일
댓글: Bipul Biswas 2023년 10월 31일
Hello,
In a folder, I have series of images and name of the first image is "Field on_1ms_4_8V_60sec-02-Deskew_t001z001c1-2". The file name is changing "t001z001c1-2" from here. Number after t and number after z and sometimes number after c. How can I read the sequence of images using a loop ?
  댓글 수: 5
Walter Roberson
Walter Roberson 2023년 10월 31일
To confirm, you would process in the order t001z001c1-2 then t001z002c1-2 then t001z003c1-2 and so on, then t002z001c1-2 t002z002c1-2 and so on ?
Bipul Biswas
Bipul Biswas 2023년 10월 31일
Thanks.. It works.

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

답변 (2개)

Image Analyst
Image Analyst 2023년 10월 31일

Walter Roberson
Walter Roberson 2023년 10월 31일
%sample name "Field on_1ms_4_8V_60sec-02-Deskew_t001z001c1-2"
projectdir = 'name/of/directory/data/files/are/in';
basefilename = 'Field*';
qualifiedname = fullfile(projectdir, basefilename);
dinfo = dir(qualifiedname);
filenames = fullfile({dinfo.folder}, {dinfo.name});
numfiles = length(filenames);
if numfiles == 0
error('No files found for "%s"', qualifiedname);
end
%extract the last component of the file names
[~, basenames] = fileparts(filenames);
lastparts = regexp(basenames, '(?<=.*_)[^_]+$', 'match', 'once');
%now for each one, extract the groups of digits, still as characters
numpart_strings = regexp(lastpart, '\d+', 'match'); %not 'once' !
%convert them to numbers
numpart_numerics = cellfun(@str2double, numpart_strings, 'uniform', 0);
%do not assume that we have the same number of groups for each.
%for example there might perhaps be t001z001c2 without a -* component
%so find the longest group and pad the others to that size.
longest_group = max(cellfun(@length, numpart_numerics));
numpart_numerics = cellfun(@(V) [V, zeros(1, longest_group - numel(V))], 'uniform', 0);
%having done that, create a numeric array in which each row is the groups
numpart_numerics = vertcat(numpart_numerics{:});
%the rule seems to be that each further component right is a subgroup of
%the one further left
[~, order_of_files] = sortrows(numpart_numerics);
%and reorder the filenames to match the wanted numeric order
filenames = filenames(order_of_files);
imgs = cell(numfiles, 1);
failed_files = false(numfiles,1);
%now we can loop over the files
for K = 1 : numfiles
thisfile = filenames{K};
try
img = imread(thisfile);
imgs{K} = img;
catch ME
fprintf(2, 'could not read image file: "%s"\n', thisfile);
failed_files(K) = true;
end
end
%all of the files are now read into "imgs".
%any failures have empty cell and failed_files is true at that location
%now what?

카테고리

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