Find the right slice

Dec 4, 2015 at 8:39 AM

I am trying to find the plane(slice) which has the same z value as the isocenter.
I can get the isocenter coordinated from API, but have no idea how to check each plane's z value against that.

Would appreciate any kind of help.

Thank you.
Dec 8, 2015 at 9:25 PM
Dec 8, 2015 at 9:38 PM
I assume that you're talking about an image? Dose also has slices. If you know the z coordinate value, you can do some math to figure out the plane index it's at. First, you need the distance between the top edge (in the z-axis) of the image and the z value. The top edge may not necessarily be 0, but the Origin property of the image returns the center point of the topmost voxel corner of the image (it might be the bottommost if the ZDirection is in reverse). Because the Origin is at the center of the voxel, the edge in the z-axis is actually image.Origin.z - image.ZRes / 2.0 (I'll call this zEdge). So the distance between the top edge and your z value is z - zEdge (I'll call this zDistance). Now, you need to divide this value by the size of each voxel in the z-axis (image.ZRes) and throw away the fractional part to get the plane index. Therefore, the plane index (an int) is (int)Math.Floor(zDistance / image.ZRes).

I haven't implemented or tested this myself, so there may be something I'm missing. Please test it thoroughly and let me know if it works.
Dec 8, 2015 at 11:56 PM
Edited Dec 9, 2015 at 12:00 AM
Thank you so much.
It works and now we have access to the correct image slice. Here's the code if someone is interested in:
double z_start=volume_image.Origin.z - volume_image.ZRes/2;
double z_step=volume_image.ZRes;
int slice_number=(int)Math.Ceiling((z_value_isocenter-z_start)/z_step);

//Getting pixels
image.GetVoxels(slice_number, voxelPlane);
for (int x = 0; x < image.XSize; x ++) {
   for (int y = 0; y < image.YSize; y++) {
      int imageValue = voxelPlane[x, y];
       writer.Write(imageValue +  ",");

We have also gotten the voxel values for that plane. We have done this for both CT and CBCT images. Our first problem is mapping isocenter to the images. We are getting isocenter like this
PlanSetup myplan=context.PlanSetup;
IEnumerable<Beam> mybeams = myplan.Beams;
int isoCenterX = mybeams.First().IsocenterPosition.x;
int isoCenterY =mybeams.First().IsocenterPosition.y;
We are dividing these x and y values with pixel width and pixel height of both images respectively to get the "pixel number" having the isocenter. Then we start from top left corner of image and mark that exact point.
Here's the pseudocode (We are actually doing it in matlab for now)

%starts from left top corner and find pixel having x, y indices equal to isocenters calculated above

The isocenter mark we get this way is different than what we can see in eclipse interface. We are assuming we are missing some factor to be added to isocenter. Is this something related to "DicomToUser" coordinates?
Dec 9, 2015 at 2:21 PM
Similar to finding the z-plane index, you might need to use a similar method to finding the x and y pixel numbers, as they're like finding the x-plane and y-plane indexes. That is, you might need to use the image.Origin.x and image.Origin.y to correctly calculate the x and y pixel numbers.