How do i adjust the spacing between the slices of my stacked images?

4 views (last 30 days)
Hi, i want to adjust the spacing between the slices of images i load in with "cat". Right now, they are stacked from 1 to 4, but how do i achieve that they are stacked not in steps of 1 but e.g. of 4?
What i did so far is this:
IA = imread('/Users/Desktop/Testdateien/1.tif')
IB = imread('/Users/Desktop/Testdateien/2.tif')
IC = imread('/Users/Desktop/Testdateien/3.tif');
ID = imread('/Users/Desktop/Testdateien/4.tif')
rgb4D = cat(4, IA, IB, IC, ID);
[D, map] = gray2ind(rgb4D);
I think i have to do sth. with the D matrix, but i don't know what.
Can anybody please help? Thanks in advance.

Answers (2)

Walter Roberson
Walter Roberson on 25 Oct 2016
gray2ind does not apply to stacked images. You would have to do that and then stack the results. You would need to pass the rgb or gray table to gray2ind so that you got the same meaning of ind in each case.
To stack with layers of zeros, construct a layer of zeros of the appropriate size and stack it in.
spacing = 4;
Z = zeros([size(IA), spacing-1], class(IA)) ;
cat(4, Z, IA, Z, IB, Z, IC, Z, ID)
  4 Comments
Mike Schneider
Mike Schneider on 28 Oct 2016
Hi, i am very sorry because i am new to Matlab and therefore have very low experience in the image processing.
I am working with grayscale images and i am trying to do sth. like in the "mri example" in Matlab, where i try to visualize a 3d volume with a set of 2d slices(images) taken from the volume with a distance in the z axis of about 150 micrometer. Therefore i am trying to visualize sth. later with "isosurface" to "interpolate" the missing points in between the slices.
In the x and y direction Matlab uses the pixels for scaling the axes, but e.g. i know that 120 pixels are 500 micrometer, so how can i convert this. I have the same question for the z direction, where the images i load in with "cat" are only stacked from 1 to x, depending on how much images i stack. Here i would like to have the images stacked also in distances of e.g. 150 micrometers but with the same ratio as in the x and y axis, so that they are plotted in the right ratio for a later volume calculation or similar.
Walter Roberson
Walter Roberson on 28 Oct 2016
"We create a tform via composition starting with a 2-D affine transformation T1 that scales the (new) dimension 1 by a factor of -2.5 and adds a shift of 68.5 to keep the array coordinates positive"
then the -2.5 corresponds to the pixel spacing. So you would alter
T1 = maketform('affine',[-2.5 0; 0 1; 68.5 0]);
to reflect the spacing you want, and then you would put the result through the resampler.

Sign in to comment.


Massimo Zanetti
Massimo Zanetti on 25 Oct 2016
First, most probably you don't want to stack them in the 4-th dimension as you wrote
rgb4D = cat(4, IA, IB, IC, ID);
Because this is not RGB image. If I have to guess what you are trying to do, I come with this:
IA = imread('/Users/Desktop/Testdateien/1.tif')
IB = imread('/Users/Desktop/Testdateien/2.tif')
IC = imread('/Users/Desktop/Testdateien/3.tif');
ID = imread('/Users/Desktop/Testdateien/4.tif')
rgb4D = cat(3, IA, IB, IC, ID); %notice the 3 instead of 4
%if IA,...,ID are single band images, to stack them with spacing of 4
STACKED4 = zeros([size(IA),13]);
STACKED4(:,:,1:4:13) = rgb4D

Community Treasure Hunt

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

Start Hunting!