[vtkusers] Show Dicom Image using PyQt4

Pedro Paulo pedropaulobmjr at hotmail.com
Fri Oct 30 16:16:09 EDT 2015


Hello, recently I asked for help on using the VTK in Qt, but I'm having trouble because I do not know how to link the image that the VTK shown in PyQt, does anyone know how can I do this?Below are my programs:
PyQt program obtained by pyuic4:from PyQt4 import QtCore, QtGui

try:
    _fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
    def _fromUtf8(s):
        return s

try:
    _encoding = QtGui.QApplication.UnicodeUTF8
    def _translate(context, text, disambig):
        return QtGui.QApplication.translate(context, text, disambig, _encoding)
except AttributeError:
    def _translate(context, text, disambig):
        return QtGui.QApplication.translate(context, text, disambig)

class Ui_Form(object):
    def setupUi(self, Form):
        Form.setObjectName(_fromUtf8("Form"))
        Form.resize(292, 337)
        self.image_vtk = QVTKRenderWindowInteractor(Form)
        self.image_vtk.setGeometry(QtCore.QRect(0, 10, 291, 331))
        self.image_vtk.setObjectName(_fromUtf8("image_vtk"))

        self.retranslateUi(Form)
        QtCore.QMetaObject.connectSlotsByName(Form)

    def retranslateUi(self, Form):
        Form.setWindowTitle(_translate("Form", "Form", None))

from vtk.qt4.QVTKRenderWindowInteractor import QVTKRenderWindowInteractor

if __name__ == "__main__":
    import sys
    app = QtGui.QApplication(sys.argv)
    Form = QtGui.QWidget()
    ui = Ui_Form()
    ui.setupUi(Form)
    Form.show()
    sys.exit(app.exec_())
My test program to open the interface, but not knowing how to link the image:import sys
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from xob import *

class test(QWidget, Ui_Form):
    def __init__(self, parent=None):
        super(test, self).__init__(parent)
        self.setupUi(self)

app = QApplication(sys.argv)
dlg = test()
dlg.show()
app.exec_()
Finally, the program using VTK opening DICOM image:import vtk

def show_dicom_image(ndicom):
    reader = vtk.vtkDICOMImageReader()
    reader.SetFileName(ndicom)
    reader.Update()

    # Visualize
    imageViewer = vtk.vtkImageViewer()
    imageViewer.SetInputConnection(reader.GetOutputPort())
    renderWindowInteractor = vtk.vtkRenderWindowInteractor()
    imageViewer.SetupInteractor(renderWindowInteractor)
    imageViewer.Render()
    imageViewer.GetRenderer().ResetCamera()
    imageViewer.Render()
    renderWindowInteractor.Start()

show_dicom_image('image.dcm') 		 	   		  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20151030/50a49ba3/attachment.html>


More information about the vtkusers mailing list