[vtkusers] displaying dicom images with the right orientation

David Gobbi david.gobbi at gmail.com
Thu Mar 17 11:19:21 EDT 2011


There is no "VTK system" per se when it comes to patient coordinate
systems.  That is just a vicious rumor.  The problem lies almost entirely
in vtkImageViewer2, which cannot provide the view orientations needed
for DICOM.

If someone wrote a new image viewer, i.e. "vtkMedicalImageViewer",
that provides proper DICOM view orientations then the problem will go
away, as long as people use FileLowerLeftOn() when reading images.
Changing the coordinate system of the image so that it "works" with
vtkImageViewer2 is a bad thing, because vtkImageViewer2 is broken
with respect to DICOM.

Until someone writes a new image viewer, I will continue to advise
people to use vtkImageActor when viewing medical images.

 - David


On Thu, Mar 17, 2011 at 9:03 AM, Jothy <jothybasu at gmail.com> wrote:
> If you use vtkImageReslice you will be doing the transformation with
> vtkImageReslice (indirectly). But again you will have problems with
> different Image Orientation patient.
>
> By transforming , I am not modifying the pixel values, its only the
> coordinates to match the vtk system.
>
> Jothy
>
> On Thu, Mar 17, 2011 at 2:53 PM, Lic. José M. Rodriguez Bacallao
> <jmrbcu at gmail.com> wrote:
>> well, I think it could be done that way but I have read in some place
>> (the book from BioImage) that one never should modify the original
>> image, that's why I am asking. In one pipeline I use the camera, in
>> the other one I use vtkImageReslice, which one is more suited to what
>> I need to achieve.
>>
>> On 3/17/11, Jothy <jothybasu at gmail.com> wrote:
>>> Hi Lic
>>>
>>> I uses vtkTransform to transform the vtkImageData rather than
>>> transforming the camera. Because I wanted to overlay the RT dose on
>>> the image. It works very well. The only problem is the  the
>>> coordinates too get transformed. I mean if you have +30, -50, it will
>>> become -30,50.
>>>
>>> Jothy
>>>
>>> On Thu, Mar 17, 2011 at 1:59 PM, Lic. José M. Rodriguez Bacallao
>>> <jmrbcu at gmail.com> wrote:
>>>> so, no one at all?
>>>>
>>>> On 3/14/11, Lic. José M. Rodriguez Bacallao <jmrbcu at gmail.com> wrote:
>>>>> any ideas?
>>>>>
>>>>> On 3/14/11, Lic. José M. Rodriguez Bacallao <jmrbcu at gmail.com> wrote:
>>>>>> i folks, I just finished two versions of a pipeline for displaying
>>>>>> dicom images with the right display position and orientation. I am
>>>>>> using gdcm vtkGDCMImageReader to read the images (and IPPSort to
>>>>>> sort). In both pipelines I set the reader's FileLoewerLeft to "On" and
>>>>>> in both I achieve the desired result. The question is which pipeline
>>>>>> is better for wat I am trying to do (display the images the right way
>>>>>> and later display a MPR view) or use one for display simple slices and
>>>>>> the other one to make a MPR. One pipeline version is using the camera
>>>>>> to achieve the right visualization and the other one is using
>>>>>> vtkImageReslice.
>>>>>>
>>>>>> here is an example program with the two pipelines (left: Camera,
>>>>>> right: vtkImageReslice)
>>>>>>
>>>>>>
>>>>>> def get_left_renderer(input, dir_cosines):
>>>>>>     image_actor = vtk.vtkImageActor()
>>>>>>     image_actor.SetInput(input.GetOutput())
>>>>>>
>>>>>>     ren_left = vtk.vtkRenderer()
>>>>>>     ren_left.SetViewport(0.0, 0.0, 0.5, 1.0)
>>>>>>     ren_left.AddActor(image_actor)
>>>>>>
>>>>>>     camera_left = ren_left.GetActiveCamera()
>>>>>>     axial_matrix = vtk.vtkMatrix4x4()
>>>>>>     axial_matrix.DeepCopy(dir_cosines)
>>>>>>     axial_matrix.SetElement(1, 1, -1)
>>>>>>     t = vtk.vtkTransform()
>>>>>>     t.Identity()
>>>>>>     t.Concatenate(axial_matrix)
>>>>>>     camera_left.SetUserTransform(t)
>>>>>>     ren_left.ResetCamera()
>>>>>>
>>>>>>     return ren_left
>>>>>>
>>>>>> def get_right_renderer(input):
>>>>>>     image = input.GetOutput()
>>>>>>     (x_min, x_max, y_min, y_max, z_min, z_max) = image.GetWholeExtent()
>>>>>>     (x_spacing, y_spacing, z_spacing) = image.GetSpacing()
>>>>>>     (x0, y0, z0) = image.GetOrigin()
>>>>>>
>>>>>>     center = (
>>>>>>         x0 + x_spacing * 0.5 * (x_min + x_max),
>>>>>>         y0 + y_spacing * 0.5 * (y_min + y_max),
>>>>>>         z0
>>>>>>     )#+ z_spacing * 0.5 * (z_min + z_max))
>>>>>>
>>>>>>     axial = vtk.vtkMatrix4x4()
>>>>>>     axial.DeepCopy((
>>>>>>         1, 0, 0, center[0],
>>>>>>         0, -1, 0, center[1],
>>>>>>         0, 0, 1, center[2],
>>>>>>         0, 0, 0, 1
>>>>>>     ))
>>>>>>
>>>>>>     reslice = vtk.vtkImageReslice()
>>>>>>     reslice.SetInput(input.GetOutput())
>>>>>>     reslice.SetOutputDimensionality(3)
>>>>>>     reslice.SetAutoCropOutput(True)
>>>>>>     reslice.SetResliceAxes(axial)
>>>>>>
>>>>>>     image_actor = vtk.vtkImageActor()
>>>>>>     image_actor.SetInput(reslice.GetOutput())
>>>>>>
>>>>>>     ren_right = vtk.vtkRenderer()
>>>>>>     ren_right.SetViewport(0.5, 0.0, 1.0, 1.0)
>>>>>>
>>>>>>     ren_right.AddActor(image_actor)
>>>>>>     ren_right.ResetCamera()
>>>>>>
>>>>>>     return ren_right
>>>>>>
>>>>>> import vtk, vtkgdcm, sys
>>>>>> from PyQt4 import QtGui
>>>>>>
>>>>>> if __name__ == '__main__':
>>>>>>     app = QtGui.QApplication(sys.argv)
>>>>>>
>>>>>>     isi = vtk.vtkInteractorStyleImage()
>>>>>>     vtk_widget = vtk.QVTKWidget()
>>>>>>     vtk_widget.resize(1280,800)
>>>>>>     vtk_widget.GetInteractor().SetInteractorStyle(isi)
>>>>>>     rwin = vtk_widget.GetRenderWindow()
>>>>>>
>>>>>>     # read the image from disk
>>>>>>     image_reader = vtkgdcm.vtkGDCMImageReader()
>>>>>>
>>>>>> image_reader.SetFileName('/home/jmrbcu/pictures/workpictures/dicom/IM66.dcm')
>>>>>>     image_reader.FileLowerLeftOn()
>>>>>>     image_reader.Update()
>>>>>>
>>>>>>     # calculate the middle window center and width
>>>>>>     image = image_reader.GetOutput()
>>>>>>     range = image.GetScalarRange()
>>>>>>     center = 0.5 * (range[1] + range[0])
>>>>>>     width  = range[1] - range[0]
>>>>>>
>>>>>>     # create the colormap
>>>>>>     colormap = vtkgdcm.vtkImageMapToWindowLevelColors2()
>>>>>>     colormap.SetInputConnection(image_reader.GetOutputPort())
>>>>>>     colormap.SetWindow(width)
>>>>>>     colormap.SetLevel(center)
>>>>>>     colormap.Update()
>>>>>>
>>>>>>     # create left and right renderers
>>>>>>     rwin.AddRenderer(get_left_renderer(colormap,
>>>>>> image_reader.GetDirectionCosines()))
>>>>>>     rwin.AddRenderer(get_right_renderer(colormap))
>>>>>>
>>>>>>     rwin.Render()
>>>>>>     vtk_widget.show()
>>>>>>
>>>>>>     app.exec_()
>>>>>>
>>>>>> #    ipp = reader.GetImagePositionPatient()
>>>>>> #    iop = reader.GetImageOrientationPatient()
>>>>>> #    row = iop[:3]
>>>>>> #    col = iop[3:]
>>>>>> #    slice = [0,0,0]
>>>>>> #    vtk.vtkMath().Cross(row, col, slice)
>>>>>> #
>>>>>> #    matrix = vtk.vtkMatrix4x4()
>>>>>> #    for j in range(3):
>>>>>> #        matrix.SetElement(j, 0, row[j])
>>>>>> #        matrix.SetElement(j, 1, col[j])
>>>>>> #        matrix.SetElement(j, 2, slice[j])
>>>>>> #
>>>>>>
>>>>>> #
>>>>>> #    ca.SetUserTransform(t)
>>>>>> #    ca.SetViewUp(0, -1, 0)
>>>>>> #    ca.SetFocalPoint(0, 0, 1)
>>>>>> #    ca.SetPosition(0,0,0)
>>>>>>
>>>>>> #    ca.ComputeViewPlaneNormal()
>>>>>> #    ca.OrthogonalizeViewUp()
>>>>>> #    ca.ParallelProjectionOn()
>>>>>> #    ca.SetParallelScale(1)
>>>>>>
>>>>>>
>>>>>>
>>>>>> --
>>>>>> Lic. José M. Rodriguez Bacallao
>>>>>> Centro de Biofisica Medica
>>>>>> -----------------------------------------------------------------
>>>>>> Todos somos muy ignorantes, lo que ocurre es que no todos ignoramos lo
>>>>>> mismo.
>>>>>>
>>>>>> Recuerda: El arca de Noe fue construida por aficionados, el titanic
>>>>>> por profesionales
>>>>>> -----------------------------------------------------------------
>>>>>>
>>>>>
>>>>>
>>>>> --
>>>>> Lic. José M. Rodriguez Bacallao
>>>>> Centro de Biofisica Medica
>>>>> -----------------------------------------------------------------
>>>>> Todos somos muy ignorantes, lo que ocurre es que no todos ignoramos lo
>>>>> mismo.
>>>>>
>>>>> Recuerda: El arca de Noe fue construida por aficionados, el titanic
>>>>> por profesionales
>>>>> -----------------------------------------------------------------
>>>>>
>>>>
>>>>
>>>> --
>>>> Lic. José M. Rodriguez Bacallao
>>>> Centro de Biofisica Medica
>>>> -----------------------------------------------------------------
>>>> Todos somos muy ignorantes, lo que ocurre es que no todos ignoramos lo
>>>> mismo.
>>>>
>>>> Recuerda: El arca de Noe fue construida por aficionados, el titanic
>>>> por profesionales
>>>> -----------------------------------------------------------------
>>>> _______________________________________________
>>>> Powered by www.kitware.com
>>>>
>>>> Visit other Kitware open-source projects at
>>>> http://www.kitware.com/opensource/opensource.html
>>>>
>>>> Please keep messages on-topic and check the VTK FAQ at:
>>>> http://www.vtk.org/Wiki/VTK_FAQ
>>>>
>>>> Follow this link to subscribe/unsubscribe:
>>>> http://www.vtk.org/mailman/listinfo/vtkusers
>>>>
>>>
>>
>>
>> --
>> Lic. José M. Rodriguez Bacallao
>> Centro de Biofisica Medica
>> -----------------------------------------------------------------
>> Todos somos muy ignorantes, lo que ocurre es que no todos ignoramos lo mismo.
>>
>> Recuerda: El arca de Noe fue construida por aficionados, el titanic
>> por profesionales
>> -----------------------------------------------------------------
>>
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers
>



More information about the vtkusers mailing list