MATLAB Answers

Masking data of 4D images

2 views (last 30 days)
Gina Carts
Gina Carts on 10 Oct 2019
Edited: Gina Carts on 10 Oct 2019
Hi there,
I have a 3D binary mask and I would like to mask my 4D data. So basically I would like to keep the information of my 4D data in all the voxels corresponding to the mask.
Any idea how to do this?

  0 Comments

Sign in to comment.

Answers (1)

David Legland
David Legland on 10 Oct 2019
Hi Gina,
I suppose that you want to repeat the binary mask along the missing dimension of your 4D data, right?
One possibility could be the following:
mask4d = repmat(mask, 1, 1, 1, size(data, 4));
values = data(mask4d);
(This assumes that the three dimensions of the mask correspond to the first three dimension of the data).

  1 Comment

Gina Carts
Gina Carts on 10 Oct 2019
Yes, I want to repeat the mask along the 4th dimension to identify the non zero voxels. The rest will be zero.
I tried what you have suggested but I'm getting the following error at this line: values = data(mask4d);
My data are all positive numbers
Subscript indices must either be real positive integers or logicals.

Sign in to comment.

Sign in to answer this question.