PDA

View Full Version : Show Dicom Image using PyQt4



Pedro Monteiro
29th October 2015, 22:46
Hello, I am studying the Qt Designer and PyQt4 to make a GUI, one of the GUI features will display a DICOM image that I implemented already using VTK and made a simple test on Qt to try to show that image, but I do not know how to link the image to Qt using PyQt, if anyone can help me how to do this, thank you!

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.GetOutputPor t())
renderWindowInteractor = vtk.vtkRenderWindowInteractor()
imageViewer.SetupInteractor(renderWindowInteractor )
imageViewer.Render()
imageViewer.GetRenderer().ResetCamera()
imageViewer.Render()
renderWindowInteractor.Start()

show_dicom_image('image.dcm')

nayyab
6th July 2018, 11:46
Hello, you wrote that you have already implemented the task of showing Dicom images in Qt using VTK. Please, can you share the code? I am having errors like different header files are not found. I am new to app development and this project is given to me by my professor that I have to develop and application in Qt c++ that can open and analyze Dicom images in Linux environment. Please, help me. I have not been able to find a single way to read Dicom images in Qt so far. I am using Qt 5. Cmake 3.10.2.

d_stranz
12th July 2018, 18:28
He -did- share the code, most of it at least.

VTK has the methods to read Dicom images. See vtkDICOMImageReader. Once you have read the image into a vtkImageData instance, you can modify the VTK VisualizeImageData (https://www.vtk.org/Wiki/VTK/Examples/Cxx/Visualization/VisualizeImageData) example to put it into a vtkRenderWindow, which you then display using a QVTKWidget. Here is a complete example. (https://hxr99.blogspot.com/2013/03/qt-vtk-displaying-single-dicom-file.html)

nayyab
15th July 2018, 16:53
I alread am fully aware of the example that you shared. That example does not work on my system and I have installed 5 different versions of vtk yet, the example works with none of those versions. Everytime I get the error, ui::mainwindow has no member named vtkrenderer or that qvtkwidget.h not found or some other error. I get a dozen errors with that example.