目录
功能3:【上传】按钮,将本地的文件上传到服务器中,实现进度条显示
功能4:在lable区域读出CT图像后,用鼠标事件,添加 绘图功能,绘制十字坐标线。
功能7:python与excle表格交互:读取信息 + python读写操作
功能10 :添加【软件说明】界面,添加新界面,并将新界面的button功能实现
功能12:选中结节和取消选中 的样式改变,选中后及时保存选中文件
前端界面与后台功能对接
1.前端代码由QTdesigner生成的ui文件,经过命令行产生,我们不妨 放在ui文件夹下,ui\seekJJ.py
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'SeekJJ.ui'
#
# Created by: PyQt5 UI code generator 5.15.3
#
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again. Do not edit this file unless you know what you are doing.
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(814, 694)
icon = QtGui.QIcon()
icon.addPixmap(QtGui.QPixmap("../image/icon.jpg"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
MainWindow.setWindowIcon(icon)
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.horizontalLayout_9 = QtWidgets.QHBoxLayout(self.centralwidget)
self.horizontalLayout_9.setObjectName("horizontalLayout_9")
self.groupBox = QtWidgets.QGroupBox(self.centralwidget)
self.groupBox.setMaximumSize(QtCore.QSize(250, 16777215))
self.groupBox.setTitle("")
self.groupBox.setObjectName("groupBox")
self.horizontalLayout_8 = QtWidgets.QHBoxLayout(self.groupBox)
self.horizontalLayout_8.setObjectName("horizontalLayout_8")
self.verticalLayout = QtWidgets.QVBoxLayout()
self.verticalLayout.setSizeConstraint(QtWidgets.QLayout.SetMaximumSize)
self.verticalLayout.setObjectName("verticalLayout")
self.read_ct_label = QtWidgets.QLabel(self.groupBox)
self.read_ct_label.setMinimumSize(QtCore.QSize(0, 35))
self.read_ct_label.setMaximumSize(QtCore.QSize(16777215, 40))
font = QtGui.QFont()
font.setFamily("黑体")
font.setPointSize(12)
self.read_ct_label.setFont(font)
self.read_ct_label.setStyleSheet("background-color:rgb(190, 217, 238)")
self.read_ct_label.setAlignment(QtCore.Qt.AlignCenter)
self.read_ct_label.setObjectName("read_ct_label")
self.verticalLayout.addWidget(self.read_ct_label)
self.horizontalLayout_6 = QtWidgets.QHBoxLayout()
self.horizontalLayout_6.setObjectName("horizontalLayout_6")
self.ct_path = QtWidgets.QLineEdit(self.groupBox)
self.ct_path.setMinimumSize(QtCore.QSize(0, 30))
self.ct_path.setObjectName("ct_path")
self.horizontalLayout_6.addWidget(self.ct_path)
self.verticalLayout.addLayout(self.horizontalLayout_6)
self.horizontalLayout_7 = QtWidgets.QHBoxLayout()
self.horizontalLayout_7.setObjectName("horizontalLayout_7")
spacerItem = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
self.horizontalLayout_7.addItem(spacerItem)
self.choose_ct_path = QtWidgets.QPushButton(self.groupBox)
self.choose_ct_path.setMinimumSize(QtCore.QSize(0, 30))
self.choose_ct_path.setObjectName("choose_ct_path")
self.horizontalLayout_7.addWidget(self.choose_ct_path)
self.upload_ct = QtWidgets.QPushButton(self.groupBox)
self.upload_ct.setMinimumSize(QtCore.QSize(0, 30))
self.upload_ct.setObjectName("upload_ct")
self.horizontalLayout_7.addWidget(self.upload_ct)
self.verticalLayout.addLayout(self.horizontalLayout_7)
self.upload_progressBar = QtWidgets.QProgressBar(self.groupBox)
self.upload_progressBar.setProperty("value", 0)
self.upload_progressBar.setObjectName("upload_progressBar")
self.verticalLayout.addWidget(self.upload_progressBar)
self.now_layers_label = QtWidgets.QLabel(self.groupBox)
self.now_layers_label.setObjectName("now_layers_label")
self.verticalLayout.addWidget(self.now_layers_label)
self.horizontalLayout_5 = QtWidgets.QHBoxLayout()
self.horizontalLayout_5.setObjectName("horizontalLayout_5")
self.ajust_layer_label = QtWidgets.QLabel(self.groupBox)
self.ajust_layer_label.setMinimumSize(QtCore.QSize(0, 30))
self.ajust_layer_label.setObjectName("ajust_layer_label")
self.horizontalLayout_5.addWidget(self.ajust_layer_label)
self.layer_slider = QtWidgets.QSlider(self.groupBox)
self.layer_slider.setMinimumSize(QtCore.QSize(0, 25))
self.layer_slider.setOrientation(QtCore.Qt.Horizontal)
self.layer_slider.setObjectName("layer_slider")
self.horizontalLayout_5.addWidget(self.layer_slider)
self.verticalLayout.addLayout(self.horizontalLayout_5)
self.horizontalLayout_4 = QtWidgets.QHBoxLayout()
self.horizontalLayout_4.setObjectName("horizontalLayout_4")
self.ajust_light_label = QtWidgets.QLabel(self.groupBox)
self.ajust_light_label.setObjectName("ajust_light_label")
self.horizontalLayout_4.addWidget(self.ajust_light_label)
self.light_slider = QtWidgets.QSlider(self.groupBox)
self.light_slider.setMinimumSize(QtCore.QSize(0, 25))
self.light_slider.setOrientation(QtCore.Qt.Horizontal)
self.light_slider.setObjectName("light_slider")
self.horizontalLayout_4.addWidget(self.light_slider)
self.verticalLayout.addLayout(self.horizontalLayout_4)
spacerItem1 = QtWidgets.QSpacerItem(20, 40, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Expanding)
self.verticalLayout.addItem(spacerItem1)
self.ct_pre_deal_label = QtWidgets.QLabel(self.groupBox)
self.ct_pre_deal_label.setMinimumSize(QtCore.QSize(0, 35))
self.ct_pre_deal_label.setMaximumSize(QtCore.QSize(16777215, 40))
font = QtGui.QFont()
font.setFamily("黑体")
font.setPointSize(12)
self.ct_pre_deal_label.setFont(font)
self.ct_pre_deal_label.setStyleSheet("background-color:rgb(190, 217, 238)")
self.ct_pre_deal_label.setAlignment(QtCore.Qt.AlignCenter)
self.ct_pre_deal_label.setObjectName("ct_pre_deal_label")
self.verticalLayout.addWidget(self.ct_pre_deal_label)
self.horizontalLayout_3 = QtWidgets.QHBoxLayout()
self.horizontalLayout_3.setObjectName("horizontalLayout_3")
self.generate_mhd = QtWidgets.QPushButton(self.groupBox)
self.generate_mhd.setMinimumSize(QtCore.QSize(0, 30))
self.generate_mhd.setObjectName("generate_mhd")
self.horizontalLayout_3.addWidget(self.generate_mhd)
self.verticalLayout.addLayout(self.horizontalLayout_3)
self.generate_clean_label = QtWidgets.QPushButton(self.groupBox)
self.generate_clean_label.setMinimumSize(QtCore.QSize(0, 30))
self.generate_clean_label.setObjectName("generate_clean_label")
self.verticalLayout.addWidget(self.generate_clean_label)
self.generate_lbb_pbb = QtWidgets.QPushButton(self.groupBox)
self.generate_lbb_pbb.setMinimumSize(QtCore.QSize(0, 30))
self.generate_lbb_pbb.setObjectName("generate_lbb_pbb")
self.verticalLayout.addWidget(self.generate_lbb_pbb)
spacerItem2 = QtWidgets.QSpacerItem(20, 40, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Expanding)
self.verticalLayout.addItem(spacerItem2)
self.vessel_apart_label = QtWidgets.QLabel(self.groupBox)
self.vessel_apart_label.setMinimumSize(QtCore.QSize(0, 35))
self.vessel_apart_label.setMaximumSize(QtCore.QSize(16777215, 40))
font = QtGui.QFont()
font.setFamily("黑体")
font.setPointSize(12)
self.vessel_apart_label.setFont(font)
self.vessel_apart_label.setStyleSheet("background-color:rgb(190, 217, 238)")
self.vessel_apart_label.setAlignment(QtCore.Qt.AlignCenter)
self.vessel_apart_label.setObjectName("vessel_apart_label")
self.verticalLayout.addWidget(self.vessel_apart_label)
self.horizontalLayout_2 = QtWidgets.QHBoxLayout()
self.horizontalLayout_2.setObjectName("horizontalLayout_2")
self.ct_2_jpg = QtWidgets.QPushButton(self.groupBox)
self.ct_2_jpg.setMinimumSize(QtCore.QSize(0, 30))
self.ct_2_jpg.setObjectName("ct_2_jpg")
self.horizontalLayout_2.addWidget(self.ct_2_jpg)
self.verticalLayout.addLayout(self.horizontalLayout_2)
self.vessel_line_mark = QtWidgets.QPushButton(self.groupBox)
self.vessel_line_mark.setMinimumSize(QtCore.QSize(0, 30))
self.vessel_line_mark.setObjectName("vessel_line_mark")
self.verticalLayout.addWidget(self.vessel_line_mark)
self.line_deal = QtWidgets.QPushButton(self.groupBox)
self.line_deal.setMinimumSize(QtCore.QSize(0, 30))
self.line_deal.setObjectName("line_deal")
self.verticalLayout.addWidget(self.line_deal)
spacerItem3 = QtWidgets.QSpacerItem(20, 40, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Expanding)
self.verticalLayout.addItem(spacerItem3)
self.generate_jj_zb_label = QtWidgets.QLabel(self.groupBox)
self.generate_jj_zb_label.setMinimumSize(QtCore.QSize(0, 35))
self.generate_jj_zb_label.setMaximumSize(QtCore.QSize(16777215, 40))
font = QtGui.QFont()
font.setFamily("黑体")
font.setPointSize(12)
self.generate_jj_zb_label.setFont(font)
self.generate_jj_zb_label.setStyleSheet("background-color:rgb(190, 217, 238)")
self.generate_jj_zb_label.setAlignment(QtCore.Qt.AlignCenter)
self.generate_jj_zb_label.setObjectName("generate_jj_zb_label")
self.verticalLayout.addWidget(self.generate_jj_zb_label)
self.horizontalLayout = QtWidgets.QHBoxLayout()
self.horizontalLayout.setObjectName("horizontalLayout")
self.generate_jj_zb = QtWidgets.QPushButton(self.groupBox)
self.generate_jj_zb.setMinimumSize(QtCore.QSize(0, 30))
self.generate_jj_zb.setObjectName("generate_jj_zb")
self.horizontalLayout.addWidget(self.generate_jj_zb)
self.see_jjzb = QtWidgets.QPushButton(self.groupBox)
self.see_jjzb.setMinimumSize(QtCore.QSize(0, 30))
self.see_jjzb.setObjectName("see_jjzb")
self.horizontalLayout.addWidget(self.see_jjzb)
self.verticalLayout.addLayout(self.horizontalLayout)
spacerItem4 = QtWidgets.QSpacerItem(20, 40, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Expanding)
self.verticalLayout.addItem(spacerItem4)
self.horizontalLayout_8.addLayout(self.verticalLayout)
self.horizontalLayout_9.addWidget(self.groupBox)
self.ct_img = PaintArea(self.centralwidget)
self.ct_img.setMinimumSize(QtCore.QSize(600, 600))
self.ct_img.setText("")
self.ct_img.setScaledContents(False)
self.ct_img.setAlignment(QtCore.Qt.AlignCenter)
self.ct_img.setObjectName("ct_img")
self.horizontalLayout_9.addWidget(self.ct_img)
MainWindow.setCentralWidget(self.centralwidget)
self.menubar = QtWidgets.QMenuBar(MainWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 814, 23))
self.menubar.setObjectName("menubar")
self.file_menu = QtWidgets.QMenu(self.menubar)
self.file_menu.setObjectName("file_menu")
self.seek_jj_menu = QtWidgets.QMenu(self.menubar)
self.seek_jj_menu.setObjectName("seek_jj_menu")
self.classify_jj_menu = QtWidgets.QMenu(self.menubar)
self.classify_jj_menu.setObjectName("classify_jj_menu")
self.setting_menu = QtWidgets.QMenu(self.menubar)
self.setting_menu.setObjectName("setting_menu")
self.help_menu = QtWidgets.QMenu(self.menubar)
self.help_menu.setObjectName("help_menu")
MainWindow.setMenuBar(self.menubar)
self.exit_action = QtWidgets.QAction(MainWindow)
self.exit_action.setObjectName("exit_action")
self.seek_jj_action = QtWidgets.QAction(MainWindow)
self.seek_jj_action.setObjectName("seek_jj_action")
self.cut_jj_action = QtWidgets.QAction(MainWindow)
self.cut_jj_action.setObjectName("cut_jj_action")
self.classify_jj_action = QtWidgets.QAction(MainWindow)
self.classify_jj_action.setObjectName("classify_jj_action")
self.to_index_action = QtWidgets.QAction(MainWindow)
self.to_index_action.setObjectName("to_index_action")
self.file_menu.addAction(self.to_index_action)
self.file_menu.addAction(self.exit_action)
self.seek_jj_menu.addAction(self.seek_jj_action)
self.seek_jj_menu.addAction(self.cut_jj_action)
self.classify_jj_menu.addAction(self.classify_jj_action)
self.menubar.addAction(self.file_menu.menuAction())
self.menubar.addAction(self.seek_jj_menu.menuAction())
self.menubar.addAction(self.classify_jj_menu.menuAction())
self.menubar.addAction(self.setting_menu.menuAction())
self.menubar.addAction(self.help_menu.menuAction())
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "肺结节多种病理类型人工智能检测系统"))
self.read_ct_label.setText(_translate("MainWindow", "读取CT文件"))
self.choose_ct_path.setText(_translate("MainWindow", "选择CT路径"))
self.upload_ct.setText(_translate("MainWindow", "上传CT"))
self.now_layers_label.setText(_translate("MainWindow", "当前层数:0/0"))
self.ajust_layer_label.setText(_translate("MainWindow", "调整层数:"))
self.ajust_light_label.setText(_translate("MainWindow", "调整亮度:"))
self.ct_pre_deal_label.setText(_translate("MainWindow", "影像预处理"))
self.generate_mhd.setText(_translate("MainWindow", "生成mhd"))
self.generate_clean_label.setText(_translate("MainWindow", "生成clean和label"))
self.generate_lbb_pbb.setText(_translate("MainWindow", "生成lbb和pbb"))
self.vessel_apart_label.setText(_translate("MainWindow", "血管分割"))
self.ct_2_jpg.setText(_translate("MainWindow", "影像生成图片"))
self.vessel_line_mark.setText(_translate("MainWindow", "血管轮廓标记"))
self.line_deal.setText(_translate("MainWindow", "轮廓处理"))
self.generate_jj_zb_label.setText(_translate("MainWindow", "生成结节坐标"))
self.generate_jj_zb.setText(_translate("MainWindow", "生成结节坐标"))
self.see_jjzb.setText(_translate("MainWindow", "查看结节坐标"))
self.file_menu.setTitle(_translate("MainWindow", "文件"))
self.seek_jj_menu.setTitle(_translate("MainWindow", "肺结节检测"))
self.classify_jj_menu.setTitle(_translate("MainWindow", "分类诊断"))
self.setting_menu.setTitle(_translate("MainWindow", "设置"))
self.help_menu.setTitle(_translate("MainWindow", "帮助"))
self.exit_action.setText(_translate("MainWindow", "退出"))
self.exit_action.setShortcut(_translate("MainWindow", "Esc"))
self.seek_jj_action.setText(_translate("MainWindow", "肺结节检测"))
self.cut_jj_action.setText(_translate("MainWindow", "裁剪肺结节"))
self.classify_jj_action.setText(_translate("MainWindow", "肺结节影像良恶性诊断"))
self.to_index_action.setText(_translate("MainWindow", "系统首页"))
from frame.myQLabel import PaintArea
2.后端代码由我们新建,frame\seekJJ.py
导入本界面
from ui.SeekJJ import Ui_MainWindow
然后对里面的button函数的书写构造。线程类和函数类。
class UploadThread(QThread):
sigout = pyqtSignal(float)
def __init__(self):
super().__init__()
self.nativePath = ''
self.uploadPath = ''
def run(self):
n = 0
fileLength = len(os.listdir(self.nativePath)) - 1
for i in os.listdir(self.nativePath):
print(self.nativePath+i)
sftp.put(self.nativePath + i, self.uploadPath + i)
self.sigout.emit((n/fileLength)*100)
n += 1
记得这段代码:调用界面的,下面会说到。 def __init__(self, parent=None):函数初始化各个参数用的。
def __init__(self, parent=None):
super().__init__(parent) # 调用父类构造函数,创建窗体
self.ui = Ui_MainWindow() # 创建UI对象
![界面](https://i-blog.csdnimg.cn/blog_migrate/e39eaa00b23abb617934dea9ca3275b3.png)
界面中的相关按键的函数实现。
在新界面中的
class SeeJJ(QMainWindow):类
表示这是个新窗口类 SeekJJ.show()函数就是打开这个界面的
class SeekJJ(QMainWindow):
def resizeEvent(self, e):
try:
img = QPixmap(self.ct_file)
width = self.ui.ct_img.width()
height = self.ui.ct_img.height()
if img is None:
return
if width > height:
small