Image Processing: DeInterleaving, is it possible?

Hello!
Is it possible for MatLab to "De-Interleave" stacked images? Originally this is a ImageJ plugin function, but it would be very useful it can be run through MatLab.
Thanks!
-Frank
Website
Diagram

1 comentario

Frank
Frank el 19 de Mayo de 2011
I'm aiming for getting images De-Interleaved and saved into a different folder through a loop function

Iniciar sesión para comentar.

Respuestas (2)

Sean de Wolski
Sean de Wolski el 19 de Mayo de 2011
Copied from Andrew with modifications:
function [A, B] = deinterleave(file_name)
I = imread(file_name); %don't call a variable image since it overwrites built-in function.
A = I(:,:,1:2:end);
B = I(:,:,2:2:end);
Not only is this vectorized but it can account for volumes with an odd number of pages (slices).
You could also change it to accept a 3D volume rather than a file name; I recommend that.
function [A, B] = deinterleave(I)
%I is a 3D volume
A = I(:,:,1:2:end);
B = I(:,:,2:2:end);

13 comentarios

Frank
Frank el 19 de Mayo de 2011
I've tried this and i'm not sure how to interpret what I received.
It returned a lot of numbers and columns.
Code:
function [A, B] = deinterleave(file_name);
I = imread('343b001.tif');
A = I(:,:,1:2:end);
B = I(:,:,2:2:end);
function [A, B] = deinterleave(file_name);
I = imread('343b001.tif');
A = I(:,:,1:2:end);
B = I(:,:,2:2:end);
Sean de Wolski
Sean de Wolski el 19 de Mayo de 2011
Does 343b001.tif contain a 3-d image?
Did you put a semicolon after the call?
call it from the command line with:
[A B] = deinterleave('343b001.tif');
and use this as the function. Don't change file_name to the one instance string.
function [A, B] = deinterleave(file_name)
I = imread(file_name); %don't call a variable image since it overwrites built-in function.
A = I(:,:,1:2:end);
B = I(:,:,2:2:end);
Frank
Frank el 19 de Mayo de 2011
So I would use:
function [A, B] = deinterleave(file_name);
I = imread('file_name');
A = I(:,:,1:2:end);
B = I(:,:,2:2:end);
Do you mean variable image as in an image stored to a variable?
Sean de Wolski
Sean de Wolski el 19 de Mayo de 2011
NO!!!
'filename' is a string. Unless you have a file named 'filename' with no extension it will fail. filename is a variable that contains a string (in this case passed in as '343b001.tif'.
Literally copy and paste these four lines and store it in deinterleave.m
function [A, B] = deinterleave(file_name)
I = imread(file_name); %don't call a variable image since it overwrites built-in function.
A = I(:,:,1:2:end);
B = I(:,:,2:2:end);
Then call it (from the command line) with
[A B] = deinterleave('343b001.tif');
Frank
Frank el 19 de Mayo de 2011
Okay
I got an error, but when I called it with
"[A B] = deinterleave('343b001.tif'); "
it ran.
I only have an image stored in A
Would the images split between A and B?
Frank
Frank el 19 de Mayo de 2011
Error:
??? Input argument "file_name" is undefined.
Sean de Wolski
Sean de Wolski el 19 de Mayo de 2011
One 2d image? Or is it 3D?
What does
size(A)
return
What does:
size(imread('343b001.tif'))
return?
Frank
Frank el 19 de Mayo de 2011
The image is 2-d, i'll post it above.
size(A) returned: 256 64
size(imread('343b001.tif') returned 256 64
Sean de Wolski
Sean de Wolski el 19 de Mayo de 2011
Well then how to do you plan on deinterleaving it? There are no slices to deinterleave!
Frank
Frank el 19 de Mayo de 2011
Did you use the posted image? I think it may have changed it, that or I've uploaded the wrong image. Let me re-upload.
Sean de Wolski
Sean de Wolski el 19 de Mayo de 2011
No. Your definition of interleaving presented above requires a 3d image. You don't have a 3d image right now so this whole objective is ill-posed.
Frank
Frank el 19 de Mayo de 2011
The function of deinterleaving organizes image stacks in the diagram above, it doesn't require the images to be in 3d, otherwise how was I able to deinterleave 2d images.
Thanks for the help though
Sean de Wolski
Sean de Wolski el 19 de Mayo de 2011
Yes it does require them to be 3D. How can you pull the second slice from a 2d image? ImageJ may work differently and be able to read a file full of 2d images, but it's viewing that file internally as a 3D image.

Iniciar sesión para comentar.

Andrew Fowler
Andrew Fowler el 19 de Mayo de 2011
This should be fairly straightforward if you are already working with a format that can be easily imported into matlab as an array. If you're working with a standard image format like .tif, or even dicom files, you should be able to set up an easy function with a quick for loop. Here's an example for a dicom file:
function [A, B] = deinterleave(dicom_filename)
image = dicomread(dicom_filename);
height = length(image(:,1,1));
width = length(image(1,:,1));
slices = length(image(1,1,:));
A = zeros(height, width, slices/2);
B = A;
for i = 1:length(image(1,1,:)
A(:,:,i) = image(:,:,(2*i-1));
B(:,:,i) = image(:,:,(2*i));
end
You can use IMREAD instead of DICOMREAD if you're using another format. If you're using a more esoteric image format like REC-PAR or 2dseq, you may need to do a little more work to actually import your images into matlab as arrays.

3 comentarios

Frank
Frank el 19 de Mayo de 2011
I am working with .tif images, so would I simply input the name of the file to the function?
Like:
function [A, B] = deinterleave('name.tif');
image = dicoread('name.tif');
...
Andrew Fowler
Andrew Fowler el 19 de Mayo de 2011
you should use IMREAD instead of DICOMREAD. Also Sean has some really good additions that you should probably follow. Ex:
i = imread('name.tif')
Frank
Frank el 19 de Mayo de 2011
Thanks for the help

Iniciar sesión para comentar.

Categorías

Más información sobre Convert Image Type en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 19 de Mayo de 2011

Community Treasure Hunt

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

Start Hunting!

Translated by