[Neuroimaging] DICOM Orientation and World<-->Image coordinate transformation
Steve Pieper
pieper at isomics.com
Tue Sep 6 11:43:06 EDT 2016
Hi Athanaios -
What I'm saying is that if you make the index to physical matrix using the
method I described it will be invertable and you can use that to calculate
know the image coordinates for any point in physical space. You need to
look at the vector between the slice origins to calculate the third column
of your matrix.
-Steve
On Tue, Sep 6, 2016 at 10:02 AM, Athanasios Anastasiou <
athanastasiou at gmail.com> wrote:
> Hello Steve
>
> Thank you very much for your response and the pointer.
>
> I feel that this might be an additional thing to be looking into once I
> get the mapping between World and Image coordinates (and back) right. Also,
> the scan direction is something that is not "bothering" me so much at the
> moment because each ROI references its grayscale image and I receive them
> sequentially ordered anyway.
>
> All the best
> AA
>
> On Tue, Sep 6, 2016 at 2:34 PM, Steve Pieper <pieper at isomics.com> wrote:
>
>> 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:
>>
>> https://github.com/Slicer/Slicer/blob/master/Modules/Scripte
>> d/DICOMPlugins/DICOMScalarVolumePlugin.py#L195-L216
>>
>> Best,
>> Steve
>>
>> 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))
>>> #M[0:3,0]=numpy.array(tumourImageData[n].ImageOrientationPatient[0:3])
>>> * tumourImageData[n].PixelSpacing[0]
>>> #M[0:3,1]=numpy.array(tumourImageData[n].ImageOrientationPatient[3:])
>>> * tumourImageData[n].PixelSpacing[1]
>>> #M[0:3,3]=tumourImageData[n].ImagePositionPatient
>>> #M[3,3]=1.0
>>> #M=numpy.matrix(M)
>>>
>>> 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
>>> matrix.
>>>
>>> Specific Data:
>>>
>>> ImageOrientationPatient:
>>> ['0.999857', '0.00390641', '0.0164496', '-0.00741602', '0.975738',
>>> '0.218818']
>>>
>>> ImagePositionPatient:
>>> ['-127.773', '-105.599', '-94.5758']
>>>
>>> PixelSpacing:
>>> ['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/slicer
>>> Wiki/index.php/Coordinate_systems).
>>>
>>> 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
>>> AA
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>> On Tue, Sep 6, 2016 at 12:48 AM, Matthew Brett <matthew.brett at gmail.com>
>>> wrote:
>>>
>>>> Hi,
>>>>
>>>> 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
>>>> having
>>>> > some difficulty, particularly with inversing the transform.
>>>> >
>>>> > I need this specifically, as I would like to extract the pixels that
>>>> have
>>>> > been prescribed (manually) by a ROI. I can access the grayscale
>>>> values which
>>>> > 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 the
>>>> > 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?
>>>>
>>>> Best,
>>>>
>>>> Matthew
>>>> _______________________________________________
>>>> Neuroimaging mailing list
>>>> Neuroimaging at python.org
>>>> https://mail.python.org/mailman/listinfo/neuroimaging
>>>>
>>>
>>>
>>> _______________________________________________
>>> Neuroimaging mailing list
>>> Neuroimaging at python.org
>>> https://mail.python.org/mailman/listinfo/neuroimaging
>>>
>>>
>>
>> _______________________________________________
>> Neuroimaging mailing list
>> Neuroimaging at python.org
>> https://mail.python.org/mailman/listinfo/neuroimaging
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/neuroimaging/attachments/20160906/012e9f8e/attachment.html>
More information about the Neuroimaging
mailing list