필터 지우기
필터 지우기

Convert a 3D image array into a cell array

조회 수: 1 (최근 30일)
Nora
Nora 2012년 9월 28일
Hi,
I know this will be basic for an experienced Matlab user but what I'm trying to do is convert an image stack, say a [mxnXp] matrix where p is the indexing dimension into a [px1] cell array.
My motivation for doing this originally was because I wanted to check to see which 'frames' of my image array were blank, i.e. equal to zeros(m,n).
I tried to use something like the following:
indices = find(arrayfun(@(IDX) ~isequal(IDX), isequal(imstack, zeros(size(imstack,1),size(imstack,2)))));
however this didn't work since imstack is a 3D matrix (at least this is why I suspect it didn't work)
To remedy I thought to convert imstack to a px1 cell array, with the view to using a 'cellfun' version of the above. And this is where I got stuck converting imstack to a cell array.
Any suggestions would be appreciated.
Thank you.
n

채택된 답변

Razvan
Razvan 2012년 9월 29일
편집: Razvan 2012년 9월 29일
Try this:
blank = true(1,p);
for k = 1:p
if any(M(:,:,k))
blank(k) = false;
end
end
where M is your 3d matrix and p is the number of frames. You'll get in the end a vector blank which is true for the blank frames. To get the indices do
find(blank)
  댓글 수: 1
Nora
Nora 2012년 9월 29일
This does the trick. Thanks for your help

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

추가 답변 (1개)

Matt J
Matt J 2012년 9월 29일
편집: Matt J 2012년 9월 29일
A more efficient approach than the for-loop would be
blank=~any(reshape(M,[],p),1);
Also, to put the slices of an array into cells, you can use this FEX file
In your case, this would look like
Mcell=mat2tiles(M,[inf,inf,1]);
Mcell=Mcell(:); %make px1

카테고리

Help CenterFile Exchange에서 Data Types에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by