[vtkusers] displaying dicom images with the right orientation

Lic. José M. Rodriguez Bacallao jmrbcu at gmail.com
Thu Mar 17 14:09:56 EDT 2011


oohh, I am understanding better now, for example, if I need to view
ortho slices (MPR) I need to use vtkImageReslice, just one question,
this cannot be achieved with camera as well?
for axial slice viewing with camera is sufficient no?

PS: vtkImageSliceMapper and vtkImageResliceMapper? what are they for?

On 3/17/11, David Gobbi <david.gobbi at gmail.com> wrote:
> Use the camera (but also see below).  In the VTK development head,
> I added a method to the vtkInteractorStyleImage class that makes it
> easier to set the camera orientation:
>
>   SetImageOrientation(double leftToRight[3], double bottomToTop[3]);
>
> This method sets the vectors that correspond to the window "up" and "right"
> directions, i.e. bottomToTop is exactly the same as the camera ViewUp.
>
>
> When I say "use the camera" it is not quite as simple as just that,
> unless you are only viewing axial slices.  For other orientations,
> look at e.g. Examples/ImageProcessing/Python/ImageSlicing.py
> or even better get the VTK development head and use the new
> classes vtkImageSliceMapper and vtkImageResliceMapper.
>
> I only use vtkImageReslice to transform a whole image if that is
> what I really need, for example if I am reslicing an image after
> doing an image registration.  For general image visualization
> pipelines, I use vtkImageReslice to extract single slices in the view
> orientations that I need.  But it is not something so simple that I can
> explain it in an email, that is why there are examples like ImageSlicing.py.
>
>  - David
>
>
> On Thu, Mar 17, 2011 at 10:28 AM, Lic. José M. Rodriguez Bacallao
> <jmrbcu at gmail.com> wrote:
>> well, I give up vtkIMageViewer2 long time ago. Right now I am reading
>> all my images with FileLoewerLeftOn  to maintain the dicom coordinates
>> system. So my question is, which is better, to use the camera to
>> achive the right orientation or to use vtkImageReslice?
>>
>> On 3/17/11, David Gobbi <david.gobbi at gmail.com> wrote:
>>> 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
>>>>
>>>
>>
>>
>> --
>> 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
-----------------------------------------------------------------



More information about the vtkusers mailing list