Convert a 3D image array into a cell array

1 次查看(过去 30 天)
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 个)

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