Borrar filtros
Borrar filtros

Read images based on datetime

7 visualizaciones (últimos 30 días)
Siegmund
Siegmund el 27 de En. de 2023
Comentada: Siegmund el 2 de Feb. de 2023
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

Respuesta aceptada

Mathieu NOE
Mathieu NOE el 27 de En. de 2023
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 comentarios
Mathieu NOE
Mathieu NOE el 31 de En. de 2023
hello
Problem solved ?
Siegmund
Siegmund el 2 de Feb. de 2023
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.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Data Type Identification en Help Center y File Exchange.

Productos


Versión

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by