Code covered by the BSD License  

Highlights from
Extract Slice from Volume

5.0

5.0 | 1 rating Rate this file 20 Downloads (last 30 days) File Size: 2.67 KB File ID: #32032
image thumbnail

Extract Slice from Volume

by Ted P Teng

 

02 Jul 2011 (Updated 12 Aug 2011)

ExtractSlice extracts an arbitrary slice, both intensities and indices, from a given volume.

| Watch this File

File Information
Description

ExtractSlice extracts an arbitrary slice, both intensities and indices, from the input volume given the center and normal of the slice. If you are familiar with IDL, this is the equivalent function of EXTRACT_SLICE.

MATLAB release MATLAB 7.7 (R2008b)
Other requirements All you need is "surf".
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (12)
29 Jul 2011 Jian Lin

Very cool and useful function!
I tried it and feel very easy to use it.
The function is just what I need. I really appreciate your work and thank you for your sharing the code.
But I need to transform the resultant plane back to the original coordinate space, too. Would it be any possible?
Thanks.

Jian

29 Jul 2011 Ted P Teng

Hi Jian, If you just need the coordinates of the individual pixels in the slice, you can transform the coordinates of the pixels with the second output from extractSlice, ('sliceInd(:)'), by using function 'ind2sub'. Note that you may be getting NaNs if part of the slice is outside the volume. I hope this answers your question.

29 Jul 2011 Jian Lin

thank you, Ted!
So you mean that sliceInd(:) or xyz after 'ind2sub' are still in the original space?

thanks.

Jian

29 Jul 2011 Jian Lin

by the way, what is the exact meaning of the input parameters centerX,centerY,centerZ? Are they are the center of the original image volume or something else?

thanks.

Jian

29 Jul 2011 Ted P Teng

The coordinates (x,y,z) from 'ind2sub' will be the coordinates within the volume (original space).
'centerX', 'centerY' and 'centerZ' are the coordinates (in original space) of the center of the output slice.

02 Aug 2011 Jian Lin

Thank you, Ted.
I need to extract a plane perpendicular to the norm vector and pass a point (pX, pY, pZ) on the norm vector. I used command like
[theSlice, sliceInd] = extractSlice(volume,pX,pY,pZ,normX,normY,normZ,128)
The resultant plane is perpendicular to norm vector but not pass the point. (It seems to me the shift is not right.)
I am wondering how I can fix the problem if I can use the function to the purpose.

Thanks.

Jian

02 Aug 2011 Ted P Teng

Can you try to duplicate the same error with the example data as provided in the extractSlice function and paste the code here?

08 Aug 2011 Jian Lin

I checked again and was wrong with what I mentioned in my previous email. The shift is right!
After rotation, xd, yd and zd are rounded before "for" loop of ExtractSlice. I am wondering if it is possible for ExtractSlice to extract slice with xd,yd and zd without rounding.

Thanks for your help in advance.

Jian

08 Aug 2011 Ted P Teng

Hi Jian, Feel free to change the code in any way you like, as long as it works for you!

09 Aug 2011 Jian Lin

Thanks.
Do you have any idea how to extract the slice with unrounded xd, yd and zd in ExtractSlice?

13 Aug 2011 Ted P Teng

Hi Jian, Please give the updated function a try!

15 Aug 2011 Jian Lin

Thank you very much! I really appreciate your work.
I downloaded the updated function and tested it. Yes, it gave me the unrounded xd (subX), yd (subY) and zd (subZ) which I needed. Great! Thanks!
Since I also need the values of the extracted plane from subX, subY and subZ (sorry for not metioning it in my previous email), I added the line to extractSlice before "for" loop,
h = slice(volume, subX, subY, subZ);
plane= get(h,'CData');
For a point on the plane, plane(i,j), I can get its coordinate [subX(i,j), subY(i,j) subZ(i,j)].
Hope what I did makes sense to you. I am happy to hear your comments.

Please login to add a comment or rating.
Updates
09 Jul 2011

Updated copyright information.

12 Aug 2011

outputs the subscripts of the slice.

Tag Activity for this File
Tag Applied By Date/Time
image processing Ted P Teng 05 Jul 2011 11:03:34

Contact us at files@mathworks.com