<p dir="ltr">Hello Matthew & Steven</p>
<p dir="ltr">Thank you for your email. Of course I am missing the third column :( I am paying too much attention on the two numbers I am after right now, to bring the contour right where it should be when plotting it over the image.</p>
<p dir="ltr">Thank you for your help, I will have another go at establishing the matrix with the helpful comments provided here.</p>
<p dir="ltr">All the best<br>
AA</p>
<div class="gmail_extra"><br><div class="gmail_quote">On 6 Sep 2016 18:25, "Matthew Brett" <<a href="mailto:matthew.brett@gmail.com">matthew.brett@gmail.com</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi,<br>
<br>
On Tue, Sep 6, 2016 at 6:34 AM, Steve Pieper <<a href="mailto:pieper@isomics.com">pieper@isomics.com</a>> wrote:<br>
> Hi Athanasios -<br>
><br>
> To get the scan direction you'll need to look at the relative<br>
> ImagePositionPatient points from slice to slice.  Note that the scan<br>
> direction is not always the cross product of the row and column orientations<br>
> since the scan may go in the other direction from a right handed cross<br>
> product or the slices can be sheared (or even at arbitrary locations)..<br>
> There are lots of other things that can happen too, like irregular spacing,<br>
> missing slices, etc, but usually just normalizing the vector between your<br>
> origin and any slice in the scan will be what you want.<br>
><br>
> This code will give you an idea:<br>
><br>
> <a href="https://github.com/Slicer/Slicer/blob/master/Modules/Scripted/DICOMPlugins/DICOMScalarVolumePlugin.py#L195-L216" rel="noreferrer" target="_blank">https://github.com/Slicer/<wbr>Slicer/blob/master/Modules/<wbr>Scripted/DICOMPlugins/<wbr>DICOMScalarVolumePlugin.py#<wbr>L195-L216</a><br>
><br>
<br>
>From your code, you are missing a valid third column for your affine.<br>
I believe that column will be all zeros from your code. This is what<br>
the later part of the DICOM orientation page is talking about, and<br>
what Steve is referring to as the "slice direction".<br>
<br>
Steve is quite right that the slice direction need not be the<br>
cross-product of the first two, and the DICOM information can often<br>
tell you what that slice direction vector is, but assuming for a<br>
moment that it is the cross product, and that you are looking at the<br>
first slice of the volume, then you'd want something like:<br>
<br>
"""<br>
import numpy as np<br>
<br>
ImageOrientationPatient = [0.999857, 0.00390641, 0.0164496,<br>
                           -0.00741602, 0.975738, 0.218818]<br>
<br>
ImagePositionPatient = [-127.773, -105.599, -94.5758]<br>
<br>
PixelSpacing = [0.4688, 0.4688]<br>
<br>
slice_spacing = 3.0  # ?<br>
<br>
# Make F array from DICOM orientation page<br>
F = np.fliplr(np.reshape(<wbr>ImageOrientationPatient, (2, 3)).T)<br>
rotations = np.eye(3)<br>
rotations[:, :2] = F<br>
# Third direction cosine from cross-product of first two<br>
rotations[:, 2] = np.cross(F[:, 0], F[:, 1])<br>
# Add the zooms<br>
zooms = np.diag(PixelSpacing + [slice_spacing])<br>
<br>
# Make the affine<br>
affine = np.diag([0., 0, 0, 1])<br>
affine[:3, :3] = rotations.dot(zooms)<br>
affine[:3, 3] = ImagePositionPatient<br>
<br>
np.set_printoptions(precision=<wbr>4, suppress=True)<br>
print(affine)<br>
"""<br>
<br>
But - Steve's suggestion is more general - this code is just to give<br>
you an idea.<br>
<br>
Best,<br>
<br>
Matthew<br>
______________________________<wbr>_________________<br>
Neuroimaging mailing list<br>
<a href="mailto:Neuroimaging@python.org">Neuroimaging@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/neuroimaging" rel="noreferrer" target="_blank">https://mail.python.org/<wbr>mailman/listinfo/neuroimaging</a><br>
</blockquote></div></div>