Apply a mask to 4D medical images in a vectorized way

조회 수: 2 (최근 30일)
AP
AP 2013년 2월 11일
Dear All,
I have a 4D array V, with the size [144 144 12 25]. In fact, it is a 4D medical image with 12 stacked slices in 25 different time. I want to apply a mask, named M, to each image in the array in a vectorized way. M is a 144x144 array containing logical values. Could someone help me how to do it?
Thanks,
Ahmad
  댓글 수: 1
José-Luis
José-Luis 2013년 2월 11일
I notice that you don't seem accept many answers after asking questions. Some of the answers seemed valid to me. Please remember to accept answers if they help you, since it is the only "payment" the volunteers in this forum receive.

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

채택된 답변

José-Luis
José-Luis 2013년 2월 11일
편집: José-Luis 2013년 2월 12일
data = rand(144,144,12,25);
your_mask = rand(144,144) > 0.5;
Assuming you want to multiply by the mask:
your_result = bsxfun(@times,data,mask);
Note that you can do operations other than multiplication. Please have a look at
doc bsxfun
  댓글 수: 4
AP
AP 2013년 2월 11일
I want the operation on each image. I thought bsxfun is only for each pixel and can't be applied to each image in a 4D array. Please correct me if I am wrong: so when we call bsxfun(@times,data,mask), bsxfun applies the mask to each 144x144. Is that right?
José-Luis
José-Luis 2013년 2월 12일
Yes. That's what the "singleton expansion" in the documentation means.

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

추가 답변 (1개)

Conrad
Conrad 2013년 2월 11일
Something like this:
fV = V.*M(:,:,ones(1,size(V,3)),ones(1,size(V,4)));
Conrad
  댓글 수: 2
AP
AP 2013년 2월 11일
How can I convert M, with size [144 144] to M with [144 144 12 25]?
AP
AP 2013년 2월 11일
편집: AP 2013년 2월 11일
I think, I have to use
repmat(M, [1 1 size(V,3) size(V,4)])
to duplicate M in other dimensions and make it [144 144 12 25].

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by