Read images based on datetime

조회 수: 5 (최근 30일)
Siegmund
Siegmund 2023년 1월 27일
댓글: Siegmund 2023년 2월 2일
I have +1000 images (in 'Struct') and would only like to use 'imread' on the images that equal the datetime in 'week1'.
How can I use a for loop (or other option) that only read the images during these certain times?
Thanks a lot for your suggestions

채택된 답변

Mathieu NOE
Mathieu NOE 2023년 1월 27일
hello Sigmund
this is a starter ....
In the middle of my brainstorming I was momentary worried that in 'Struct' the filename and date field seemed not to be consistent
like the first value are :
Timex(1).name = 'T_1_202110010600.jpeg' (and we could interpret that as 01 oct 2021 , 06:00 AM)
but date field gives :
Timex(1).date = '01-Oct-2021 08:14:06'
so after a few seconds of doubt I continued my work assuming that date field is correct and I should not take into account what Timex.name could suggest
Back to the code :
seems that both mat files will give two datenum arrays that do not really match 100% so there is a certain time gap between the two (if plot both you will see it)
now what i wanted to do is :
  • find the nearest element in Struct for each element in Week
  • remove the elements that are two far apart in terms of time laps ; NB the minimal time delta found here is 52 seconds , so up to you to decide the time tolerance
here I opted to keep only what is below 60 seconds of difference
you simply have to add your own code after imread ;
% load data
load('Week1.mat')
load('Struct.mat')
dd = datenum(start); % datetime data from file 'Week1.mat'
tt = [Timex.datenum]; % datetime data from file 'Struct.mat'
for ci = 1:numel(dd)
[v(ci),struct_idx(ci)] = min(abs(dd(ci) - tt));
delta_seconds(ci) = v(ci) * 24 * 60 * 60; % time delta between nearest datetime in 'Struct.mat' for a given datetime in 'Week1.mat'
end
% plot(delta_seconds)
min(delta_seconds)
% keep only files index for time delta below a certain threshold (in seconds)
week_ix = find(delta_seconds<=60);
struct_idx = struct_idx(week_ix);
% create list of files to read in 'Struct'
for ck = 1:numel(struct_idx)
ind = struct_idx(ck);
folder = Timex(ind).folder;
filename = Timex(ind).name;
Fdate = Timex(ind).date;
F = fullfile(folder,filename);
% your own code here
A = imread(F);
end
  댓글 수: 2
Mathieu NOE
Mathieu NOE 2023년 1월 31일
hello
Problem solved ?
Siegmund
Siegmund 2023년 2월 2일
Hey Mathieu, thanks a lot for your input and apologies for the late reply.
You almost did too much work (but I should've made it clearer in my initial question).
The datetime in 'Week1' (written as yyyy-mm-dd HH:MM:SS) is normally always equal to the datetime in 'Struct' (written as T_1_yyyymmddHHMM).
So normally if I can find the datetime of Week1 in Struct, and then read those images that are equal.
I was trying to use 'find' in a loop but that seems a bit complicated as well.
Thanks again for your help.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Data Type Identification에 대해 자세히 알아보기

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by