Borrar filtros
Borrar filtros

Convert a 3D image array into a cell array

1 visualización (últimos 30 días)
Nora
Nora el 28 de Sept. de 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

Respuesta aceptada

Razvan
Razvan el 29 de Sept. de 2012
Editada: Razvan el 29 de Sept. de 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 comentario
Nora
Nora el 29 de Sept. de 2012
This does the trick. Thanks for your help

Iniciar sesión para comentar.

Más respuestas (1)

Matt J
Matt J el 29 de Sept. de 2012
Editada: Matt J el 29 de Sept. de 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

Categorías

Más información sobre Data Types en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by