dose matrix coordinate issue

Aug 27, 2015 at 6:32 PM
I read dose matrix using dose.GetDoseProfile and then saving to a data file (.csv) with the attached code. Then I use Matlab to read the saved dose data into dose matrix D.
 M = csvread(doseFileName);
 D = reshape(M, gridSize(1), gridSize(2), 1, gridSize(3));
When I overlay the dose matrix D over the original CT images in Matlab, I have to rotate each dose slice 90 degrees clockwise, and then flip left right to match the screen display from Eclipse. This is equivalent to map (x, y) to (-y, -x) for each dose slice from dose matrix D. Can anybody give an explanation? TIA.
        double[] doseArray = new double[dose.XSize];

        using (System.IO.StreamWriter sw = new System.IO.StreamWriter(doseFileName, false, Encoding.ASCII))
        {

            for (int k = 0; k < dose.ZSize; k++)
                {

                for (int j = 0; j < dose.YSize; j++)
                {
                    VVector start = dose.Origin + 
                        dose.YDirection * dose.YRes * j + 
                        dose.ZDirection * dose.ZRes * k;
                    VVector end = start + dose.XDirection * dose.XRes * dose.XSize;
                    DoseProfile doseProfile = dose.GetDoseProfile(start, end, doseArray);

                    for (int i = 0; i < dose.XSize; i++)
                    {
                        double doseValue = doseProfile[i].Value;
                        DoseValue.DoseUnit doseUnit = doseProfile.Unit;
                        sw.WriteLine(string.Format("{0:0.0000}", doseValue));
                    }
                    doseProfile = null;
                }
            }
Coordinator
Aug 27, 2015 at 8:12 PM
I don't know Matlab, but by looking at the reshape function (http://www.mathworks.com/help/matlab/ref/reshape.html), it looks like reshape(M, 2, 2, 2) on the following:

1
2
3
4
5
6
7
8

would produce the following matrix:
    5------7
1---+--3   |
|   |  |   |
|   6--+---8
2------4
That already looks wrong. Shouldn't the it be something like:
    5------6
1---+--2   |
|   |  |   |
|   7--+---8
3------4
This may explain the 90 degree rotation, but it doesn't quite explain flipping the direction.
Aug 27, 2015 at 9:34 PM
Thanks, redcurry.

Matlab reshape function puts data in matrix column-wise, and dose.GetDoseProfile reads data row by tow. That's why we see (x, y) mapped to (-y, -x). I think the easiest way is to transpose the dose slice in x-y plane.