Extract subset of time-curves from a 4D volume

1 Ansicht (letzte 30 Tage)
Domenico
Domenico am 10 Jun. 2020
Kommentiert: Turlough Hughes am 17 Jun. 2020
Dear all,
I have a 4D volume and I can easily extract the temporal curve for each voxel.
I would like to extract only the curves for the voxels that correspond to a certain condition.
For example: V is the 4D volume and R is a 3D mask volume. I would like to extract only the curves of the points in which R>0 but without using a for cicle.
Normally I would write:
for k=1:size(V,3)
for i=1:size(V,1)
for j =1:size(V,2)
if (R(i,j,k)>0)
y = squeeze(V(i,j,k,:));
a(i,:) = y;
......
end
end
end
I tried to use indexing but I can only use it with 3D volumes.
Is there an efficient solution (I mean fast) to do this?
Thanks a lot
  4 Kommentare
Turlough Hughes
Turlough Hughes am 10 Jun. 2020
You could do something like this.
V2 = V; % make a copy of V
V2(repmat(R<=0,1,1,1,size(V2,4)))=NaN; % Remove values where R <= 0
My feeling is that you should maintain the shape of V, so I opted to insert NaN's at coordinates where your condition R>0 is false, ie where R<=0 is true. Is that the sort of answer you're looking for?
Domenico
Domenico am 10 Jun. 2020
Thanks a lot.
In this way you obtain a sort of "masking" of the 4D volume, right? From that masking, however, I would like to extract each single temporal 1D curve, i.e. for every survived pixel I would like to obtain its curve (without using for)

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Turlough Hughes
Turlough Hughes am 17 Jun. 2020
I can reduce this to a single for loop which iterates through the timesteps but i'm not sure about doing this entirely without loop. Here, I concatentate the data of a given timestep into a column vector and insert it into results. I took the liberty of including the x,y and z indices in columns 1,2 and 3, respectively, so each timestep is added sequentially thereafter.
Rmask = R>0; % Binary mask
[Ix, Iy, Iz] = ind2sub(size(Rmask),find(Rmask)); % get x,y,z indices for mask
result = [Ix, Iy, Iz, zeros(numel(Ix),size(V,4))]; % preallocate space
for t = 1:size(V,4)
Vtemp = V(:,:,:,t); % grab one timestep
result(:,t+3) = Vtemp(Rmask); % Convert to column vector and insert into results
end
  7 Kommentare
Domenico
Domenico am 17 Jun. 2020
Ok, only a question: what do you do with Ixyz? You obtain it but you don't use it for Vr. Is right?
Turlough Hughes
Turlough Hughes am 17 Jun. 2020
Ixyz is the corresponding index in V. The first row of Vr shows values changing over time at a single point within V, the first row of Ixyz inidicates the corresponding xyz indices within V which can usually be related to an xyz position. I just assumed you would need it.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Matrices and Arrays finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by