Convert a 3D image array into a cell array

4 vues (au cours des 30 derniers jours)
Nora
Nora le 28 Sep 2012
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

Réponse acceptée

Razvan
Razvan le 29 Sep 2012
Modifié(e) : Razvan le 29 Sep 2012
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 commentaire
Nora
Nora le 29 Sep 2012
This does the trick. Thanks for your help

Connectez-vous pour commenter.

Plus de réponses (1)

Matt J
Matt J le 29 Sep 2012
Modifié(e) : Matt J le 29 Sep 2012
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

Catégories

En savoir plus sur Cell Arrays dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by