<html>
<head>
<style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 12pt;
font-family:Calibri
}
--></style></head>
<body class='hmmessage'><div dir='ltr'>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?<div><span style="font-size: 12pt;">Below are my programs:</span></div><div><br></div><div><p style="box-sizing: border-box; margin-bottom: 13px; color: rgb(38, 40, 42); font-family: 'Open Sans', sans-serif; line-height: 26px; background-color: rgb(255, 255, 255);">PyQt program obtained by pyuic4:</p><pre class="markdown-highlight" style="box-sizing: border-box; overflow: auto; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 15px; padding: 12.5px; margin-top: 1rem; margin-bottom: 13px; line-height: 1.625; word-break: break-all; word-wrap: break-word; color: rgb(38, 40, 42); border: none; border-radius: 4px; max-height: 350px; background-color: rgb(255, 255, 255);"><code class="hljs python" style="box-sizing: border-box; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: inherit; padding: 0.5em; color: black; border-radius: 0px; display: block; overflow-x: auto; word-wrap: normal; background-image: initial; background-attachment: initial; background-size: initial; background-origin: initial; background-clip: initial; background-position: initial; background-repeat: initial;"><span class="hljs-keyword" style="box-sizing: border-box; color: rgb(0, 0, 136);">from</span> PyQt4 <span class="hljs-keyword" style="box-sizing: border-box; color: rgb(0, 0, 136);">import</span> QtCore, QtGui

<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(0, 0, 136);">try</span>:
    _fromUtf8 = QtCore.QString.fromUtf8
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(0, 0, 136);">except</span> AttributeError:
    <span class="hljs-function" style="box-sizing: border-box;"><span class="hljs-keyword" style="box-sizing: border-box; color: rgb(0, 0, 136);">def</span> <span class="hljs-title" style="box-sizing: border-box;">_fromUtf8</span><span class="hljs-params" style="box-sizing: border-box; color: rgb(102, 0, 102);">(s)</span>:</span>
        <span class="hljs-keyword" style="box-sizing: border-box; color: rgb(0, 0, 136);">return</span> s

<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(0, 0, 136);">try</span>:
    _encoding = QtGui.QApplication.UnicodeUTF8
    <span class="hljs-function" style="box-sizing: border-box;"><span class="hljs-keyword" style="box-sizing: border-box; color: rgb(0, 0, 136);">def</span> <span class="hljs-title" style="box-sizing: border-box;">_translate</span><span class="hljs-params" style="box-sizing: border-box; color: rgb(102, 0, 102);">(context, text, disambig)</span>:</span>
        <span class="hljs-keyword" style="box-sizing: border-box; color: rgb(0, 0, 136);">return</span> QtGui.QApplication.translate(context, text, disambig, _encoding)
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(0, 0, 136);">except</span> AttributeError:
    <span class="hljs-function" style="box-sizing: border-box;"><span class="hljs-keyword" style="box-sizing: border-box; color: rgb(0, 0, 136);">def</span> <span class="hljs-title" style="box-sizing: border-box;">_translate</span><span class="hljs-params" style="box-sizing: border-box; color: rgb(102, 0, 102);">(context, text, disambig)</span>:</span>
        <span class="hljs-keyword" style="box-sizing: border-box; color: rgb(0, 0, 136);">return</span> QtGui.QApplication.translate(context, text, disambig)

<span class="hljs-class" style="box-sizing: border-box;"><span class="hljs-keyword" style="box-sizing: border-box; color: rgb(0, 0, 136);">class</span> <span class="hljs-title" style="box-sizing: border-box; color: rgb(102, 0, 102);">Ui_Form</span><span class="hljs-params" style="box-sizing: border-box; color: rgb(102, 0, 102);">(object)</span>:</span>
    <span class="hljs-function" style="box-sizing: border-box;"><span class="hljs-keyword" style="box-sizing: border-box; color: rgb(0, 0, 136);">def</span> <span class="hljs-title" style="box-sizing: border-box;">setupUi</span><span class="hljs-params" style="box-sizing: border-box; color: rgb(102, 0, 102);">(self, Form)</span>:</span>
        Form.setObjectName(_fromUtf8(<span class="hljs-string" style="box-sizing: border-box; color: rgb(0, 136, 0);">"Form"</span>))
        Form.resize(<span class="hljs-number" style="box-sizing: border-box; color: rgb(0, 102, 102);">292</span>, <span class="hljs-number" style="box-sizing: border-box; color: rgb(0, 102, 102);">337</span>)
        self.image_vtk = QVTKRenderWindowInteractor(Form)
        self.image_vtk.setGeometry(QtCore.QRect(<span class="hljs-number" style="box-sizing: border-box; color: rgb(0, 102, 102);">0</span>, <span class="hljs-number" style="box-sizing: border-box; color: rgb(0, 102, 102);">10</span>, <span class="hljs-number" style="box-sizing: border-box; color: rgb(0, 102, 102);">291</span>, <span class="hljs-number" style="box-sizing: border-box; color: rgb(0, 102, 102);">331</span>))
        self.image_vtk.setObjectName(_fromUtf8(<span class="hljs-string" style="box-sizing: border-box; color: rgb(0, 136, 0);">"image_vtk"</span>))

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

    <span class="hljs-function" style="box-sizing: border-box;"><span class="hljs-keyword" style="box-sizing: border-box; color: rgb(0, 0, 136);">def</span> <span class="hljs-title" style="box-sizing: border-box;">retranslateUi</span><span class="hljs-params" style="box-sizing: border-box; color: rgb(102, 0, 102);">(self, Form)</span>:</span>
        Form.setWindowTitle(_translate(<span class="hljs-string" style="box-sizing: border-box; color: rgb(0, 136, 0);">"Form"</span>, <span class="hljs-string" style="box-sizing: border-box; color: rgb(0, 136, 0);">"Form"</span>, <span class="hljs-keyword" style="box-sizing: border-box; color: rgb(0, 0, 136);">None</span>))

<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(0, 0, 136);">from</span> vtk.qt4.QVTKRenderWindowInteractor <span class="hljs-keyword" style="box-sizing: border-box; color: rgb(0, 0, 136);">import</span> QVTKRenderWindowInteractor

<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(0, 0, 136);">if</span> __name__ == <span class="hljs-string" style="box-sizing: border-box; color: rgb(0, 136, 0);">"__main__"</span>:
    <span class="hljs-keyword" style="box-sizing: border-box; color: rgb(0, 0, 136);">import</span> sys
    app = QtGui.QApplication(sys.argv)
    Form = QtGui.QWidget()
    ui = Ui_Form()
    ui.setupUi(Form)
    Form.show()
    sys.exit(app.exec_())
</code></pre><p style="box-sizing: border-box; margin-bottom: 13px; color: rgb(38, 40, 42); font-family: 'Open Sans', sans-serif; line-height: 26px; background-color: rgb(255, 255, 255);">My test program to open the interface, but not knowing how to link the image:</p><pre class="markdown-highlight" style="box-sizing: border-box; overflow: auto; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 15px; padding: 12.5px; margin-top: 1rem; margin-bottom: 13px; line-height: 1.625; word-break: break-all; word-wrap: break-word; color: rgb(38, 40, 42); border: none; border-radius: 4px; max-height: 350px; background-color: rgb(255, 255, 255);"><code class="hljs python" style="box-sizing: border-box; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: inherit; padding: 0.5em; color: black; border-radius: 0px; display: block; overflow-x: auto; word-wrap: normal; background-image: initial; background-attachment: initial; background-size: initial; background-origin: initial; background-clip: initial; background-position: initial; background-repeat: initial;"><span class="hljs-keyword" style="box-sizing: border-box; color: rgb(0, 0, 136);">import</span> sys
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(0, 0, 136);">from</span> PyQt4.QtCore <span class="hljs-keyword" style="box-sizing: border-box; color: rgb(0, 0, 136);">import</span> *
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(0, 0, 136);">from</span> PyQt4.QtGui <span class="hljs-keyword" style="box-sizing: border-box; color: rgb(0, 0, 136);">import</span> *
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(0, 0, 136);">from</span> xob <span class="hljs-keyword" style="box-sizing: border-box; color: rgb(0, 0, 136);">import</span> *

<span class="hljs-class" style="box-sizing: border-box;"><span class="hljs-keyword" style="box-sizing: border-box; color: rgb(0, 0, 136);">class</span> <span class="hljs-title" style="box-sizing: border-box; color: rgb(102, 0, 102);">test</span><span class="hljs-params" style="box-sizing: border-box; color: rgb(102, 0, 102);">(QWidget, Ui_Form)</span>:</span>
    <span class="hljs-function" style="box-sizing: border-box;"><span class="hljs-keyword" style="box-sizing: border-box; color: rgb(0, 0, 136);">def</span> <span class="hljs-title" style="box-sizing: border-box;">__init__</span><span class="hljs-params" style="box-sizing: border-box; color: rgb(102, 0, 102);">(self, parent=None)</span>:</span>
        super(test, self).__init__(parent)
        self.setupUi(self)

app = QApplication(sys.argv)
dlg = test()
dlg.show()
app.exec_()
</code></pre><pre class="markdown-highlight" style="box-sizing: border-box; overflow: auto; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: 15px; padding: 12.5px; margin-top: 1rem; margin-bottom: 13px; line-height: 1.625; word-break: break-all; word-wrap: break-word; color: rgb(38, 40, 42); border: none; border-radius: 4px; max-height: 350px; background-color: rgb(255, 255, 255);"><code class="hljs python" style="box-sizing: border-box; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: inherit; padding: 0.5em; color: black; border-radius: 0px; display: block; overflow-x: auto; word-wrap: normal; background-image: initial; background-attachment: initial; background-size: initial; background-origin: initial; background-clip: initial; background-position: initial; background-repeat: initial;"><p style="box-sizing: border-box; margin-bottom: 13px; color: rgb(38, 40, 42); font-family: 'Open Sans', sans-serif; font-size: 16px; line-height: 26px; white-space: normal;">Finally, the program using VTK opening DICOM image:</p><pre class="markdown-highlight" style="box-sizing: border-box; overflow: auto; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; padding: 12.5px; margin-top: 1rem; margin-bottom: 13px; line-height: 1.625; word-break: break-all; word-wrap: break-word; color: rgb(38, 40, 42); border: none; border-radius: 4px; max-height: 350px;"><code class="hljs python" style="box-sizing: border-box; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: inherit; padding: 0.5em; color: black; border-radius: 0px; display: block; overflow-x: auto; word-wrap: normal; background-image: initial; background-attachment: initial; background-size: initial; background-origin: initial; background-clip: initial; background-position: initial; background-repeat: initial;"><span class="hljs-keyword" style="box-sizing: border-box; color: rgb(0, 0, 136);">import</span> vtk

<span class="hljs-function" style="box-sizing: border-box;"><span class="hljs-keyword" style="box-sizing: border-box; color: rgb(0, 0, 136);">def</span> <span class="hljs-title" style="box-sizing: border-box;">show_dicom_image</span><span class="hljs-params" style="box-sizing: border-box; color: rgb(102, 0, 102);">(ndicom)</span>:</span>
    reader = vtk.vtkDICOMImageReader()
    reader.SetFileName(ndicom)
    reader.Update()

    <span class="hljs-comment" style="box-sizing: border-box; color: rgb(136, 0, 0);"># Visualize</span>
    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(<span class="hljs-string" style="box-sizing: border-box; color: rgb(0, 136, 0);">'image.dcm'</span>)</code></pre></code></pre></div>                                       </div></body>
</html>