[Neuroimaging] DICOM Orientation and World<-->Image coordinate transformation
pieper at isomics.com
Tue Sep 6 09:34:31 EDT 2016
Hi Athanasios -
To get the scan direction you'll need to look at the relative
ImagePositionPatient points from slice to slice. Note that the scan
direction is not always the cross product of the row and column
orientations since the scan may go in the other direction from a right
handed cross product or the slices can be sheared (or even at arbitrary
locations).. There are lots of other things that can happen too, like
irregular spacing, missing slices, etc, but usually just normalizing the
vector between your origin and any slice in the scan will be what you want.
This code will give you an idea:
On Tue, Sep 6, 2016 at 7:50 AM, Athanasios Anastasiou <
athanastasiou at gmail.com> wrote:
> Hello Matthew
> Thank you for your response.
> As per the DICOM pages:
> #M = numpy.zeros((4,4))
> * tumourImageData[n].PixelSpacing
> * tumourImageData[n].PixelSpacing
> ImageOrientationPatient is a flat 1x6 vector as it is coming out of the
> image but more importantly it contains direction cosines which means that
> it may not constitute a "proper" rotation matrix. The determinant of that
> matrix is 0.0. Scaling apart, it would still have to be a "valid" rotation
> Specific Data:
> ['0.999857', '0.00390641', '0.0164496', '-0.00741602', '0.975738',
> ['-127.773', '-105.599', '-94.5758']
> ['0.4688', '0.4688']
> Now, if I read this correctly, all the points are offset by
> ImagePositionPatient, scaled by pixel spacing (and so far so good), the
> FIRST ROW (i.e. X) points mostly downwards (rotation of almost 90 degrees
> around the X axis in the world system), and the FIRST COLUMN (i.e. Y) now
> points left. To interpert the rotations, I am taking the direction cosines
> as angle differences between the scanner space (x,y,z) and image space
> (i,j,k) as depicted in (https://www.slicer.org/slicerWiki/index.php/
> Come to think of it, these very small angles might be the reason for the
> non-zero Z coordinate in the ROI.
> What am I doing wrong?
> All the best
> On Tue, Sep 6, 2016 at 12:48 AM, Matthew Brett <matthew.brett at gmail.com>
>> On Sun, Sep 4, 2016 at 12:12 PM, Athanasios Anastasiou
>> <athanastasiou at gmail.com> wrote:
>> > Hello everyone
>> > I am trying to convert between world and image coordinates and I am
>> > some difficulty, particularly with inversing the transform.
>> > I need this specifically, as I would like to extract the pixels that
>> > been prescribed (manually) by a ROI. I can access the grayscale values
>> > are in some pixel space and I can access the ROI data which however is
>> > expressed in 'mm' and thus in world coordinates.
>> > As per http://nipy.org/nibabel/dicom/dicom_orientation.html I have all
>> > data to construct the matrix that converts pixel to world coordinates
>> but I
>> > am interested in the opposite direction (i.e. from world (ROI) to image
>> > (pixels)).
>> > My immediate reaction was to invert the transformation matrix. However,
>> I am
>> > getting an error that the matrix is "singular".
>> Yes, inverting is what you want to do. The error is telling you
>> about some error in the affine matrix.
>> Would you mind giving more details on where you got the entries for
>> your affine matrix? What are your ImageOrientationPatient and
>> ImagePositionPatient fields? I assume you got the third column of the
>> matrix by taking the cross-product of the first two? What matrix do
>> you end up with?
>> Neuroimaging mailing list
>> Neuroimaging at python.org
> Neuroimaging mailing list
> Neuroimaging at python.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Neuroimaging