MATLAB Answers

Read out intensites and corresponding X,Y,Z-coordinates from a 3D-image

47 views (last 30 days)
Arne
Arne on 24 Nov 2014
Commented: Image Analyst on 8 May 2016
Hello,
this is a common problem. But there were no real answers to this question in this forum.
I have a 3D-image generated from a 3D-array - I want to get the intensity values plus their corresponding position (X,Y,Z) in a normal spreadsheet in MatLab.
Ultimately, I would get something like:
Intensity | X | Y | Z
and this for every point in the image.
Since there are millions of points it might be also a good idea to cut out points with 0 intensity.
Has somebody done something similar?
Best wishes.

  0 Comments

Sign in to comment.

Accepted Answer

Image Analyst
Image Analyst on 24 Nov 2014
Edited: Image Analyst on 24 Nov 2014
What is the size of the third dimension? If it's 3 then it can be considered a normal RGB color image and you can use impixelinfo() to see the values. If you still want it in a spreadsheet, then I suggest you extract each plane of your volumetric image in a loop and then send that to Excel. If you really, really need the x,y,z values also then I suggest you create an N by 4 array and then write out
[rows, columns, slices] = size(array3D);
array2D = zeros(numel(array3D), 4);
counter = 1;
for z = 1 : slices
for x = 1 : columns
for y = 1 : rows
array2D(counter, :) = [array3D(y, x, z), x, y, z];
counter = counter + 1;
end
end
end
xlswrite(filename, array2D);

  10 Comments

Show 7 older comments
Sean de Wolski
Sean de Wolski on 10 Dec 2014
That's specifically why I use row/col/page. It helps with this confusion that will come back to bite many times.
Walter Roberson
Walter Roberson on 8 May 2016
Hesham Shehata comments,
I tried to use this code with various types of images but i always get zero values only! can you please advise how to define the image with this code? thanks for your cooperation.
Image Analyst
Image Analyst on 8 May 2016
Then your image is all zero. Obviously the x, y, and z cannot be printed as zeros - that's impossible.

Sign in to comment.

More Answers (1)

Sean de Wolski
Sean de Wolski on 26 Nov 2014
load mri
D = squeeze(D);
idx = logical(D); % Where in D is nonzero?
vals = D(idx); % extract values
ind = find(idx); % linear index
[row,col,pag] = ind2sub(size(D),ind); % sub indices
xlswrite('file.xlsx',[row col pag vals])

  0 Comments

Sign in to comment.

Sign in to answer this question.


Translated by