create image from timeseries data
이전 댓글 표시
Hi,
I have time stamp (in microseconds) of the image data stored in array AA and arrays x,y and I contains x,y co-ordinats and intensity. I need to accumulate the data over 200 microseconds to create each image.
x pixel size - 1280;
y pixel size - 720;
댓글 수: 2
Turbulence Analysis
2024년 1월 25일
채택된 답변
추가 답변 (1개)
Turbulence Analysis
2024년 1월 25일
0 개 추천
댓글 수: 15
Mathieu NOE
2024년 1월 25일
ok, I was missing this information (or I didn't read carefully somehow) , so instaed of taking buffers of 200 samples , you simply need to take now 6105 samples (no code modification need)
and yes the result looks now like a flow animation !!
% I have time stamp (in microseconds) of the image data stored in array AA and arrays x,y and I contains x,y co-ordinats and intensity. I need to accumulate the data over 200 microseconds to create each image.
% x pixel size - 1280;
% y pixel size - 720;
% NB : 200 microseconds = 6105 samples
load('matlab1.mat')
data = cd_data.AA;
x = cd_data.x;
y = cd_data.y;
intensity = cd_data.I;
samples = numel(data);
x = x+1 ; % x range must be changed from (0:1279) to (1:1280)
y = y+1 ; % x range must be changed from (0:719) to (1:720)
dt = 1; % sample rate (micro s)
t = dt*(0:samples-1); % time vector
buffer_size = 6105; % how many samples
overlap = 0; % overlap expressed in samples
shift = buffer_size-overlap; % nb of samples between 2 contiguous buffers
nb_of_loops = fix((samples-buffer_size)/shift +1);
im_empty = zeros(1280,720);
for k=1:nb_of_loops
start_index = 1+(k-1)*shift;
stop_index = min(start_index+ buffer_size-1,samples);
xx = x(start_index:stop_index);
yy = y(start_index:stop_index);
Intens = intensity(start_index:stop_index);
im = im_empty; % init im with zeros
% now use the data
for m = 1:buffer_size
im(xx(m),yy(m),k) = Intens(m);
end
% display (optionnal)
imshow(im(:,:,k))
end
Turbulence Analysis
2024년 1월 26일
Mathieu NOE
2024년 1월 26일
we coud certainly make the code more robust but we need the time stamps values
I don't see any new mat file attached
Turbulence Analysis
2024년 1월 26일
Mathieu NOE
2024년 1월 29일
hello again
try this :
% x pixel size : 1280;
% y pixel size : 720;
% first 200 micro seconds the buffer size is 4533 (i.e. rows 1 to 4533 --> 69142-68942 = 200)
% and for next 200 micro seconds (i.e. 69143 to 69343) is reprsented by rows 4534 to 8829, the buffer size here is 4295
load('matlab.mat')
x = cd_data.x;
y = cd_data.y;
intensity = cd_data.p;
t = cd_data.ts; % time vector
samples = numel(t);
buffer_duration = 200; % microseconds
nb_of_loops = fix((t(end) - t(1))/buffer_duration);
start_index(1) = 1; % first 200 microsecond buffer starts right at the 1st sample
for k=1:nb_of_loops
stop_index(k) = find((t - t(1))==(k)*buffer_duration,1,'last');
end
start_index(2:nb_of_loops) = stop_index(1:nb_of_loops-1)+1; % second to last value of start_index is simply former stop_index + 1
buffer_size = stop_index - start_index +1;
x = x+1 ; % x range must be changed from (0:1279) to (1:1280)
y = y+1 ; % x range must be changed from (0:719) to (1:720)
im = zeros(1280,720,nb_of_loops); % init im with zeros
for k=1:nb_of_loops
xx = x(start_index(k):stop_index(k));
yy = y(start_index(k):stop_index(k));
Intens = intensity(start_index(k):stop_index(k));
% now use the data
for m = 1:buffer_size(k)
im(xx(m),yy(m),k) = Intens(m);
end
% display (optionnal)
imshow(im(:,:,k))
end
Turbulence Analysis
2024년 1월 29일
Turbulence Analysis
2024년 1월 29일
Mathieu NOE
2024년 1월 30일
hello again
I see the point
there are some times when the time vector has no time stamp corresponding to exactly a 200 microsecond spaced grid so that will throw this error message
what I have done is to take the previous time stamp available , which , I think , is a reasonnable compromise
so this line
stop_index(k) = find((t - t(1))==(k)*buffer_duration,1,'last');
get's replaced by :
stop_index(k) = find((t- t(1) - k*buffer_duration)<=0,1,'last');
just FYI, as the number of images is now quite high (9868) , I had a memory issue due to the initialization of im
im = zeros(1280,720,nb_of_loops); % init im with zeros
Error using zeros
Requested 1280x720x9868 (67.8GB) array exceeds maximum array size preference.
Creation of arrays greater than this limit may take a long time and cause MATLAB to
become unresponsive.
maybe you have not the same memory limitations on your PC, or somehow we have to find away to avoid building huge arrays , either by splitting the data file in smaller chunks , or generate only one picture at a time an build an animation incrementaly
full code :
% x pixel size : 1280;
% y pixel size : 720;
% first 200 micro seconds the buffer size is 4533 (i.e. rows 1 to 4533 --> 69142-68942 = 200)
% and for next 200 micro seconds (i.e. 69143 to 69343) is reprsented by rows 4534 to 8829, the buffer size here is 4295
load('matlab.mat')
x = cd_data.x;
y = cd_data.y;
intensity = cd_data.p;
t = cd_data.ts; % time vector
samples = numel(t);
buffer_duration = 200; % microseconds
nb_of_loops = fix((t(end)-t(1))/buffer_duration);
start_index(1) = 1; % first 200 microsecond buffer starts right at the 1st sample
for k=1:nb_of_loops
stop_index(k) = find((t- t(1) - k*buffer_duration)<=0,1,'last');
end
start_index(2:nb_of_loops) = stop_index(1:nb_of_loops-1)+1; % second to last value of start_index is simply former stop_index + 1
buffer_size = stop_index - start_index +1;
x = x+1 ; % x range must be changed from (0:1279) to (1:1280)
y = y+1 ; % x range must be changed from (0:719) to (1:720)
im = zeros(1280,720,nb_of_loops); % init im with zeros
for k=1:nb_of_loops
xx = x(start_index(k):stop_index(k));
yy = y(start_index(k):stop_index(k));
Intens = intensity(start_index(k):stop_index(k));
% now use the data
for m = 1:buffer_size(k)
im(xx(m),yy(m),k) = Intens(m);
end
% display (optionnal)
imshow(im(:,:,k))
end
Turbulence Analysis
2024년 1월 30일
Mathieu NOE
2024년 1월 31일
I tried to reduce the amount of memory use , so first thing I tried is to change from double precision to integer to store the im array.
here I opted for logical class but I could have done with uint8 or int8 for the same result
try this new code :
% x pixel size : 1280;
% y pixel size : 720;
% first 200 micro seconds the buffer size is 4533 (i.e. rows 1 to 4533 --> 69142-68942 = 200)
% and for next 200 micro seconds (i.e. 69143 to 69343) is reprsented by rows 4534 to 8829, the buffer size here is 4295
load('matlab.mat')
x = cd_data.x;
y = cd_data.y;
intensity = cd_data.p;
t = cd_data.ts; % time vector
samples = numel(t);
buffer_duration = 200; % microseconds
nb_of_loops = fix((t(end)-t(1))/buffer_duration);
start_index(1) = 1; % first 200 microsecond buffer starts right at the 1st sample
for k=1:nb_of_loops
stop_index(k) = find((t- t(1) - k*buffer_duration)<=0,1,'last');
end
start_index(2:nb_of_loops) = stop_index(1:nb_of_loops-1)+1; % second to last value of start_index is simply former stop_index + 1
buffer_size = stop_index - start_index +1;
x = x+1 ; % x range must be changed from (0:1279) to (1:1280)
y = y+1 ; % x range must be changed from (0:719) to (1:720)
im = zeros(1280,720,nb_of_loops,'logical'); % init im with logical zeros
for k=1:nb_of_loops
xx = x(start_index(k):stop_index(k));
yy = y(start_index(k):stop_index(k));
Intens = intensity(start_index(k):stop_index(k)); % range : -1/+1
Intens = logical((Intens+1)*0.5); % change range to 0/+1 and converted to logical
% now use the data
for m = 1:buffer_size(k)
im(xx(m),yy(m),k) = Intens(m);
end
% display (optionnal)
imshow(im(:,:,k))
end
Turbulence Analysis
2024년 2월 1일
Turbulence Analysis
2024년 2월 1일
Mathieu NOE
2024년 2월 2일
hello again
ok, here is it :
I changed from logical to int8 class (same memory usage) , so you have both levels displayed
% x pixel size : 1280;
% y pixel size : 720;
% first 200 micro seconds the buffer size is 4533 (i.e. rows 1 to 4533 --> 69142-68942 = 200)
% and for next 200 micro seconds (i.e. 69143 to 69343) is reprsented by rows 4534 to 8829, the buffer size here is 4295
load('matlab.mat')
x = cd_data.x;
y = cd_data.y;
intensity = int8(cd_data.p);
t = cd_data.ts; % time vector
samples = numel(t);
buffer_duration = 200; % microseconds
nb_of_loops = fix((t(end)-t(1))/buffer_duration);
start_index(1) = 1; % first 200 microsecond buffer starts right at the 1st sample
for k=1:nb_of_loops
stop_index(k) = find((t- t(1) - k*buffer_duration)<=0,1,'last');
end
start_index(2:nb_of_loops) = stop_index(1:nb_of_loops-1)+1; % second to last value of start_index is simply former stop_index + 1
buffer_size = stop_index - start_index +1;
x = x+1 ; % x range must be changed from (0:1279) to (1:1280)
y = y+1 ; % x range must be changed from (0:719) to (1:720)
im = zeros(1280,720,nb_of_loops,'int8'); % init im with integer zeros
for k=1:nb_of_loops
xx = x(start_index(k):stop_index(k));
yy = y(start_index(k):stop_index(k));
Intens = intensity(start_index(k):stop_index(k)); % range : -1/+1
% now use the data
for m = 1:buffer_size(k)
im(xx(m),yy(m),k) = Intens(m);
end
% display (optionnal)
imagesc(im(:,:,k))
pause(0.01)
end
Turbulence Analysis
2024년 2월 2일
Mathieu NOE
2024년 2월 2일
as always, my pleasure !
카테고리
도움말 센터 및 File Exchange에서 Image Arithmetic에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
