主 界 面 版 本 迭 代 记 录 主界面版本迭代记录 主界面版本迭代记录
.
1
# 0.导入需要的包和模块
from PyQt5.Qt import *
import sys
class FramePane(QWidget):
def __init__(self):
super().__init__()
self.setWindowTitle("Major")
self.resize(1400, 900)
self.setMouseTracking(True)
self.setup_ui()
def setup_ui(self):
'''
主构造
'''
# 创建控件
menu_bar = QWidget()
# menu_bar.setStyleSheet("background-color:yellow;")
tool_tar = QWidget()
# tool_tar.setStyleSheet("background-color:red;")
left = QWidget()
# left.setStyleSheet("background-color:blue;")
body = QWidget()
# body.setStyleSheet("background-color:blue;")
body.setMouseTracking(True)
right = QWidget()
# right.setStyleSheet("background-color:blue;")
# 1.创建布局管理器对象
v_layout = QVBoxLayout()
h_layout = QHBoxLayout()
# 2.把布局管理器对象设置给需要布局的父控件
self.setLayout(v_layout)
# 3.添加需要布局的子控件到布局管理器当中
v_layout.addWidget(menu_bar)
v_layout.addWidget(tool_tar)
h_layout.addWidget(left)
h_layout.addWidget(body)
h_layout.addWidget(right)
v_layout.addLayout(h_layout)
# 4.设置伸缩因子
v_layout.setStretchFactor(menu_bar, 1)
v_layout.setStretchFactor(tool_tar, 1)
v_layout.setStretchFactor(h_layout, 20)
h_layout.setStretchFactor(left,1)
h_layout.setStretchFactor(body, 6)
h_layout.setStretchFactor(right, 1)
'''
Menu_Bar
'''
# 创建水平布局
h_menu_bar_layout = QHBoxLayout()
# 使用水平布局
menu_bar.setLayout(h_menu_bar_layout)
# 加入控件
file_btn = QPushButton(menu_bar)
file_btn.setText("file")
h_menu_bar_layout.addWidget(file_btn,1)
h_menu_bar_layout.addStretch(5)
# 创建菜单
file_menu = QMenu()
# 创建子菜单
open_recent_menu = QMenu(file_menu)
open_recent_menu.setTitle("最近打开")
# 1.新建动作
new_action = QAction(QIcon(r"D:\pyqt5\resources\images\1.png"), "新建", file_menu)
new_action.triggered.connect(lambda: print("新建文件"))
# 2.打开动作
open_action = QAction(QIcon(r"D:\pyqt5\resources\images\1.png"), "打开", file_menu)
open_action.triggered.connect(lambda: print("打开文件"))
# 3.退出动作
exit_action = QAction(QIcon(r"D:\pyqt5\resources\images\1.png"), "退出", file_menu)
exit_action.triggered.connect(lambda: print("退出程序"))
# 4.子菜单动作
file_action = QAction("python_test")
open_recent_menu.addAction(file_action)
# 添加
file_menu.addAction(new_action)
file_menu.addAction(open_action)
file_menu.addMenu(open_recent_menu)
file_menu.addSeparator()
file_menu.addAction(exit_action)
file_btn.setMenu(file_menu)
file_btn.setFlat(True)
'''
Tool_Bar
'''
tb = QToolButton(tool_tar)
tb.setText("工具")
tb.setIconSize(QSize(25,25))
tb.setToolTip("这是一个新建按钮")
tb.setAutoRaise(True)
tb1 = QToolButton(tool_tar)
tb1.setText("工具2")
tb1.move(60,0)
tb1.setIconSize(QSize(25,25))
tb1.setToolTip("这是一个新建按钮")
tb1.setAutoRaise(True)
'''
Left
'''
left_layout = QVBoxLayout()
left.setLayout(left_layout)
file_dir_tree = QTreeView()
left_layout.addWidget(file_dir_tree)
'''
Body
'''
body_layout = QVBoxLayout()
body.setLayout(body_layout)
img_show_lb = QLabel()
img_show_lb.setText("显示图片区域")
body_layout.addWidget(img_show_lb)
'''
Right
'''
right_layout = QVBoxLayout()
right.setLayout(right_layout)
tag_view_tv = QTableView(right)
right_layout.addWidget(tag_view_tv)
# def mouseMoveEvent(self,event):
# x = event.x()
# y = event.y()
# text = "x:{0},y:{1}".format(x,y)
# print(text)
if __name__ == '__main__':
# 1.创建一个应用程序对象
app = QApplication(sys.argv)
# 2.控件的操作
# 2.1创建控件
window = FramePane()
# 2.2设置控件
# 2.3展示控件
window.show()
# 3.应用程序的执行,进入到信息循环
sys.exit(app.exec_())
2
# 0.导入需要的包和模块
from PyQt5.Qt import *
import sys
import pydicom
from PIL import Image
import os
class FramePane(QWidget):
def __init__(self):
super().__init__()
self.setWindowTitle("Major")
self.resize(1400, 900)
self.setMouseTracking(True)
self.setup_ui()
# 定义绘画类型
self.Draw = ""
self.Line_list = [0, 0, 0, 0]
self.Point_list = []
self.Elipse_list = [0, 0, 0, 0]
self.Rectangle_list = [0, 0, 0, 0]
self.Polygon_list = []
# 其他
self.cwd = os.getcwd() # 获取当前路径
self.dir_model = QFileSystemModel() # 文件系统模型
self.dicom_tag_model = QStandardItemModel(5,1)
# 设置水平方向头标签文本内容
self.dicom_tag_model.setVerticalHeaderLabels(['ID', '姓名', '就诊日期', '性别', '年龄'])
self.dicom_tag_model.setHorizontalHeaderLabels(['值'])
self.flag = 0
def setup_ui(self):
'''
主构造
'''
# 创建控件
self.menu_bar = QWidget()
# menu_bar.setStyleSheet("background-color:yellow;")
self.tool_tar = QWidget()
# tool_tar.setStyleSheet("background-color:red;")
self.left = QWidget()
# left.setStyleSheet("background-color:blue;")
self.body = QWidget()
# body.setStyleSheet("background-color:blue;")
self.body.setMouseTracking(True)
self.right = QWidget()
# right.setStyleSheet("background-color:blue;")
# 1.创建布局管理器对象
self.v_layout = QVBoxLayout()
self.h_layout = QHBoxLayout()
# 2.把布局管理器对象设置给需要布局的父控件
self.setLayout(self.v_layout)
# 3.添加需要布局的子控件到布局管理器当中
self.v_layout.addWidget(self.menu_bar)
self.v_layout.addWidget(self.tool_tar)
self.h_layout.addWidget(self.left)
self.h_layout.addWidget(self.body)
self.h_layout.addWidget(self.right)
self.v_layout.addLayout(self.h_layout)
# 4.设置伸缩因子
self.v_layout.setStretchFactor(self.menu_bar, 1)
self.v_layout.setStretchFactor(self.tool_tar, 1)
self.v_layout.setStretchFactor(self.h_layout, 20)
self.h_layout.setStretchFactor(self.left,1)
self.h_layout.setStretchFactor(self.body, 6)
self.h_layout.setStretchFactor(self.right, 1)
'''
Menu_Bar
'''
# 创建水平布局
self.h_menu_bar_layout = QHBoxLayout()
# 使用水平布局
self.menu_bar.setLayout(self.h_menu_bar_layout)
# 加入控件
self.file_btn = QPushButton(self.menu_bar)
self.file_btn.setText("file")
self.h_menu_bar_layout.addWidget(self.file_btn,1)
self.h_menu_bar_layout.addStretch(5)
# 创建菜单
self.file_menu = QMenu()
# 创建子菜单
self.open_recent_menu = QMenu(self.file_menu)
self.open_recent_menu.setTitle("最近打开")
# 1.新建动作
self.new_action = QAction(QIcon(r"D:\pyqt5\resources\images\1.png"), "打开文件", self.file_menu)
self.new_action.triggered.connect(self.call_back_action_open_file)
# 2.打开动作
self.open_action = QAction(QIcon(r"D:\pyqt5\resources\images\1.png"), "打开文件夹", self.file_menu)
self.open_action.triggered.connect(lambda: print("打开文件夹"))
# 3.退出动作
self.exit_action = QAction(QIcon(r"D:\pyqt5\resources\images\1.png"), "退出", self.file_menu)
self.exit_action.triggered.connect(lambda: print("退出程序"))
# 4.子菜单动作
self.file_action = QAction("python_test")
self.open_recent_menu.addAction(self.file_action)
# 添加
self.file_menu.addAction(self.new_action)
self.file_menu.addAction(self.open_action)
self.file_menu.addMenu(self.open_recent_menu)
self.file_menu.addSeparator()
self.file_menu.addAction(self.exit_action)
self.file_btn.setMenu(self.file_menu)
self.file_btn.setFlat(True)
'''
Tool_Bar
'''
self.tb = QToolButton(self.tool_tar)
self.tb.setText("工具")
self.tb.setIconSize(QSize(25,25))
self.tb.setToolTip("这是一个新建按钮")
self.tb.setAutoRaise(True)
self.tb1 = QToolButton(self.tool_tar)
self.tb1.setText("工具2")
self.tb1.move(60,0)
self.tb1.setIconSize(QSize(25,25))
self.tb1.setToolTip("这是一个新建按钮")
self.tb1.setAutoRaise(True)
'''
Left
'''
self.left_layout = QVBoxLayout()
self.left.setLayout(self.left_layout)
self.file_dir_tree = QTreeView()
self.left_layout.addWidget(self.file_dir_tree)
'''
Body
'''
self.body_layout = QVBoxLayout()
self.body.setLayout(self.body_layout)
self.img_show_lb = QLabel()
self.img_show_lb.setText("显示图片区域")
self.body_layout.addWidget(self.img_show_lb)
'''
Right
'''
self.right_layout = QVBoxLayout()
self.right.setLayout(self.right_layout)
self.tag_view_tv = QTableView(self.right)
self.right_layout.addWidget(self.tag_view_tv)
# def mouseMoveEvent(self,event):
# x = event.x()
# y = event.y()
# text = "x:{0},y:{1}".format(x,y)
# print(text)
def call_back_action_open_file(self):
print("call_back_action_open_file")
fileName_choose, filetype = QFileDialog.getOpenFileName(self,
"选取文件",
self.cwd, # 起始路径
"All Files (*);;Text Files (*.txt)") # 设置文件扩展名过滤,用双分号间隔
if fileName_choose == "":
print("\n取消选择")
return
print("\n你选择的文件夹为:")
print(fileName_choose)
'''
1.显示图像
'''
dcm = pydicom.read_file(fileName_choose)
raw_img = dcm.pixel_array
# img = Image.fromarray(raw_img)
# img.show()
# 2.映射到0-255之间
raw_flatten_img = raw_img.flatten()
max_val = max(raw_flatten_img)
min_val = min(raw_flatten_img)
raw_img = (raw_img - min_val) / (max_val - min_val) # 图像归一化
raw_img = raw_img * 255
img = Image.fromarray(raw_img)
img.convert('RGB').save("rgb_show.jpg", format='jpeg')
# img.show() # 正常
# 转QImage
# 显示图片
self.img_show_lb.setPixmap(QPixmap("rgb_show.jpg"))
self.img_show_lb.setScaledContents(True)
'''
2.显示Tag信息
'''
info = {}
info["PatientID"] = dcm.PatientID # 患者ID
info["PatientName"] = dcm.PatientName # 患者姓名
info['StudyDate'] = dcm.StudyDate # 检查日期
info['PatientSex'] = dcm.PatientSex # 患者性别
info["PatientAge"] = dcm.PatientAge # 患者年龄
# print(info)
val_list = []
for val in info.values():
val_list.append(val)
# 2.在tabel中显示元信息
for row in range(len(info)):
print(val_list[row])
item = QStandardItem(str(val_list[row]))
# 设置每个位置的文本值
self.dicom_tag_model.setItem(row, 0, item)
self.tag_view_tv.setModel(self.dicom_tag_model)
if __name__ == '__main__':
# 1.创建一个应用程序对象
app = QApplication(sys.argv)
# 2.控件的操作
# 2.1创建控件
window = FramePane()
# 2.2设置控件
# 2.3展示控件
window.show()
# 3.应用程序的执行,进入到信息循环
sys.exit(app.exec_())
3
# 0.导入需要的包和模块
from PyQt5.Qt import *
import sys
import pydicom
from PIL import Image
import os
class FramePane(QWidget):
def __init__(self):
super().__init__()
self.setWindowTitle("Major")
self.resize(1400, 900)
self.setMouseTracking(True)
self.setup_ui()
# 定义绘画类型
self.Draw = ""
self.Line_list = [0, 0, 0, 0]
self.Point_list = []
self.Elipse_list = [0, 0, 0, 0]
self.Rectangle_list = [0, 0, 0, 0]
self.Polygon_list = []
# 其他
self.cwd = os.getcwd() # 获取当前路径
self.dir_model = QFileSystemModel() # 文件系统模型
self.dicom_tag_model = QStandardItemModel(5,1)
# 设置水平方向头标签文本内容
self.dicom_tag_model.setVerticalHeaderLabels(['ID', '姓名', '就诊日期', '性别', '年龄'])
self.dicom_tag_model.setHorizontalHeaderLabels(['值'])
self.flag = 0
'''
<1> 界面构造
'''
def setup_ui(self):
'''
主构造
'''
# 创建控件
self.menu_bar = QWidget()
# menu_bar.setStyleSheet("background-color:yellow;")
self.tool_tar = QWidget()
# tool_tar.setStyleSheet("background-color:red;")
self.left = QWidget()
# left.setStyleSheet("background-color:blue;")
self.body = QWidget()
# body.setStyleSheet("background-color:blue;")
self.body.setMouseTracking(True)
self.right = QWidget()
# right.setStyleSheet("background-color:blue;")
# 1.创建布局管理器对象
self.v_layout = QVBoxLayout()
self.h_layout = QHBoxLayout()
# 2.把布局管理器对象设置给需要布局的父控件
self.setLayout(self.v_layout)
# 3.添加需要布局的子控件到布局管理器当中
self.v_layout.addWidget(self.menu_bar)
self.v_layout.addWidget(self.tool_tar)
self.h_layout.addWidget(self.left)
self.h_layout.addWidget(self.body)
self.h_layout.addWidget(self.right)
self.v_layout.addLayout(self.h_layout)
# 4.设置伸缩因子
self.v_layout.setStretchFactor(self.menu_bar, 1)
self.v_layout.setStretchFactor(self.tool_tar, 1)
self.v_layout.setStretchFactor(self.h_layout, 20)
self.h_layout.setStretchFactor(self.left,2)
self.h_layout.setStretchFactor(self.body,8)
self.h_layout.setStretchFactor(self.right,2)
'''
Menu_Bar
'''
# 创建水平布局
self.h_menu_bar_layout = QHBoxLayout()
# 使用水平布局
self.menu_bar.setLayout(self.h_menu_bar_layout)
# 加入控件
self.file_btn = QPushButton(self.menu_bar)
self.file_btn.setText("file")
self.h_menu_bar_layout.addWidget(self.file_btn,1)
self.h_menu_bar_layout.addStretch(20)
# 创建菜单
self.file_menu = QMenu()
# 创建子菜单
self.open_recent_menu = QMenu(self.file_menu)
self.open_recent_menu.setTitle("最近打开")
# 1.新建动作
self.new_action = QAction(QIcon(r"D:\pyqt5\resources\images\1.png"), "打开文件", self.file_menu)
self.new_action.triggered.connect(self.open_dicom_file)
# 2.打开动作
self.open_action = QAction(QIcon(r"D:\pyqt5\resources\images\1.png"), "打开文件夹", self.file_menu)
self.open_action.triggered.connect(self.open_dicom_dir)
# 3.退出动作
self.exit_action = QAction(QIcon(r"D:\pyqt5\resources\images\1.png"), "退出", self.file_menu)
self.exit_action.triggered.connect(lambda: print("退出程序"))
# 4.子菜单动作
self.file_action = QAction("python_test")
self.open_recent_menu.addAction(self.file_action)
# 添加
self.file_menu.addAction(self.new_action)
self.file_menu.addAction(self.open_action)
self.file_menu.addMenu(self.open_recent_menu)
self.file_menu.addSeparator()
self.file_menu.addAction(self.exit_action)
self.file_btn.setMenu(self.file_menu)
self.file_btn.setFlat(True)
'''
Tool_Bar
'''
self.tb = QToolButton(self.tool_tar)
self.tb.setText("工具")
self.tb.setIconSize(QSize(25,25))
self.tb.setToolTip("这是一个新建按钮")
self.tb.setAutoRaise(True)
self.tb1 = QToolButton(self.tool_tar)
self.tb1.setText("工具2")
self.tb1.move(60,0)
self.tb1.setIconSize(QSize(25,25))
self.tb1.setToolTip("这是一个新建按钮")
self.tb1.setAutoRaise(True)
'''
Left
'''
self.left_layout = QVBoxLayout()
self.left.setLayout(self.left_layout)
self.file_dir_tree = QTreeView()
self.left_layout.addWidget(self.file_dir_tree)
'''
Body
'''
self.body_layout = QVBoxLayout()
self.body.setLayout(self.body_layout)
self.img_show_lb = QLabel()
self.img_show_lb.setText("显示图片区域")
self.body_layout.addWidget(self.img_show_lb)
'''
Right
'''
self.right_layout = QVBoxLayout()
self.right.setLayout(self.right_layout)
self.tag_view_tv = QTableView(self.right)
self.right_layout.addWidget(self.tag_view_tv)
# def mouseMoveEvent(self,event):
# x = event.x()
# y = event.y()
# text = "x:{0},y:{1}".format(x,y)
# print(text)
'''
<2> 绘画
'''
'''
<3> dicom的图像和tag信息展示
'''
def open_dicom_file(self):
print("call_back_action_open_file")
fileName_choose, filetype = QFileDialog.getOpenFileName(self,
"选取文件",
self.cwd, # 起始路径
"All Files (*);;Text Files (*.txt)") # 设置文件扩展名过滤,用双分号间隔
if fileName_choose == "":
print("\n取消选择")
return
print("\n你选择的文件夹为:")
print(fileName_choose)
'''
1.显示图像
'''
dcm = pydicom.read_file(fileName_choose)
raw_img = dcm.pixel_array
# img = Image.fromarray(raw_img)
# img.show()
# 2.映射到0-255之间
raw_flatten_img = raw_img.flatten()
max_val = max(raw_flatten_img)
min_val = min(raw_flatten_img)
raw_img = (raw_img - min_val) / (max_val - min_val) # 图像归一化
raw_img = raw_img * 255
img = Image.fromarray(raw_img)
img.convert('RGB').save("rgb_show.jpg", format='jpeg')
# img.show() # 正常
# 转QImage
# 显示图片
self.img_show_lb.setPixmap(QPixmap("rgb_show.jpg"))
self.img_show_lb.setScaledContents(True)
'''
2.显示Tag信息
'''
info = {}
info["PatientID"] = dcm.PatientID # 患者ID
info["PatientName"] = dcm.PatientName # 患者姓名
info['StudyDate'] = dcm.StudyDate # 检查日期
info['PatientSex'] = dcm.PatientSex # 患者性别
info["PatientAge"] = dcm.PatientAge # 患者年龄
# print(info)
val_list = []
for val in info.values():
val_list.append(val)
# 2.在tabel中显示元信息
for row in range(len(info)):
#print(val_list[row])
item = QStandardItem(str(val_list[row]))
# 设置每个位置的文本值
self.dicom_tag_model.setItem(row, 0, item)
self.tag_view_tv.setModel(self.dicom_tag_model)
def open_dicom_dir(self):
dir_choose = QFileDialog.getExistingDirectory(self,
"选取文件夹",
self.cwd) # 起始路径
if dir_choose == "":
print("\n取消选择")
return
#print("\n你选择的文件夹为:")
#print(dir_choose)
self.dir_model.setRootPath(dir_choose)
self.file_dir_tree.setModel(self.dir_model)
self.file_dir_tree.setRootIndex(self.dir_model.index(dir_choose))
self.file_dir_tree.clicked.connect(self.show_info)
self.file_dir_tree.setColumnWidth(0,300)
#print("call_back_action_store_dir")
def show_info(self, signal):
'''
1.显示图像
'''
file_path=self.dir_model.filePath(signal)
# 1.pydicom读取dicom图像
dcm = pydicom.read_file(file_path)
raw_img = dcm.pixel_array
# img = Image.fromarray(raw_img)
# img.show()
# 2.映射到0-255之间
raw_flatten_img =raw_img.flatten()
max_val = max(raw_flatten_img)
min_val = min(raw_flatten_img)
raw_img = (raw_img-min_val)/(max_val-min_val) # 图像归一化
raw_img = raw_img*255
img = Image.fromarray(raw_img)
img.convert('RGB').save("rgb_show.jpg", format='jpeg')
# img.show() # 正常
# 转QImage
# 显示图片
self.img_show_lb.setPixmap(QPixmap("rgb_show.jpg"))
self.img_show_lb.setScaledContents(True)
'''
2.显示Tag信息
'''
info = {}
info["PatientID"] = dcm.PatientID # 患者ID
info["PatientName"] = dcm.PatientName # 患者姓名
info["PatientAge"] = dcm.PatientAge # 患者年龄
info['PatientSex'] = dcm.PatientSex # 患者性别
info['StudyDate'] = dcm.StudyDate # 检查日期
# print(info)
val_list = []
for val in info.values():
val_list.append(val)
# 2.在tabel中显示元信息
for row in range(len(info)):
# print(val_list[row])
item = QStandardItem(str(val_list[row]))
# 设置每个位置的文本值
self.dicom_tag_model.setItem(row, 0, item)
self.tag_view_tv.setModel(self.dicom_tag_model)
'''
<4> 图像的保存(jpg、dicom)
'''
'''
<5> 智能医学
'''
'''
<6> 三维重建
'''
'''
<7> 常用图像处理
'''
'''
<8> 生成病情报告
'''
'''
<9> 病人病情显示
'''
if __name__ == '__main__':
# 1.创建一个应用程序对象
app = QApplication(sys.argv)
# 2.控件的操作
# 2.1创建控件
window = FramePane()
# 2.2设置控件
# 2.3展示控件
window.show()
# 3.应用程序的执行,进入到信息循环
sys.exit(app.exec_())
4
# 0.导入需要的包和模块
from PyQt5.Qt import *
import sys
import pydicom
from PIL import Image
import os
class FramePane(QWidget):
def __init__(self):
super().__init__()
self.setWindowTitle("Major")
self.resize(1400, 900)
self.setMouseTracking(True)
self.setup_ui()
# 定义绘画类型
self.Draw = ""
self.Line_list = [0, 0, 0, 0]
self.Point_list = []
self.Elipse_list = [0, 0, 0, 0]
self.Rectangle_list = [0, 0, 0, 0]
self.Polygon_list = []
# 其他
self.cwd = os.getcwd() # 获取当前路径
self.dir_model = QFileSystemModel() # 文件系统模型
self.dicom_tag_model = QStandardItemModel(5,1)
# 设置水平方向头标签文本内容
self.dicom_tag_model.setVerticalHeaderLabels(['ID', '姓名', '就诊日期', '性别', '年龄'])
self.dicom_tag_model.setHorizontalHeaderLabels(['值'])
self.flag = 0
'''
<1> 界面构造
'''
def setup_ui(self):
'''
主构造
'''
# 创建控件
self.menu_bar = QWidget()
# menu_bar.setStyleSheet("background-color:yellow;")
self.tool_bar = QWidget()
# tool_bar.setStyleSheet("background-color:red;")
self.left = QWidget()
# left.setStyleSheet("background-color:blue;")
self.body = QWidget()
# body.setStyleSheet("background-color:blue;")
self.body.setMouseTracking(True)
self.right = QWidget()
# right.setStyleSheet("background-color:blue;")
# 1.创建布局管理器对象
self.v_layout = QVBoxLayout()
self.h_layout = QHBoxLayout()
# 2.把布局管理器对象设置给需要布局的父控件
self.setLayout(self.v_layout)
# 3.添加需要布局的子控件到布局管理器当中
self.v_layout.addWidget(self.menu_bar)
self.v_layout.addWidget(self.tool_bar)
self.h_layout.addWidget(self.left)
self.h_layout.addWidget(self.body)
self.h_layout.addWidget(self.right)
self.v_layout.addLayout(self.h_layout)
# 4.设置伸缩因子
self.v_layout.setStretchFactor(self.menu_bar, 1)
self.v_layout.setStretchFactor(self.tool_bar, 1)
self.v_layout.setStretchFactor(self.h_layout, 20)
self.h_layout.setStretchFactor(self.left,2)
self.h_layout.setStretchFactor(self.body,8)
self.h_layout.setStretchFactor(self.right,2)
'''
Menu_Bar
'''
# 创建水平布局
self.menu_bar_layout = QHBoxLayout()
# 使用水平布局
self.menu_bar.setLayout(self.menu_bar_layout)
# 加入控件
self.file_btn = QPushButton(self.menu_bar)
self.file_btn.setText("file")
self.menu_bar_layout.addWidget(self.file_btn,1)
self.menu_bar_layout.addStretch(20)
# 创建菜单
self.file_menu = QMenu()
# 创建子菜单
self.open_recent_menu = QMenu(self.file_menu)
self.open_recent_menu.setTitle("最近打开")
# 1.新建动作
self.new_action = QAction(QIcon(r"D:\pyqt5\resources\images\1.png"), "打开文件", self.file_menu)
self.new_action.triggered.connect(self.open_dicom_file)
# 2.打开动作
self.open_action = QAction(QIcon(r"D:\pyqt5\resources\images\1.png"), "打开文件夹", self.file_menu)
self.open_action.triggered.connect(self.open_dicom_dir)
# 3.退出动作
self.exit_action = QAction(QIcon(r"D:\pyqt5\resources\images\1.png"), "退出", self.file_menu)
self.exit_action.triggered.connect(lambda: print("退出程序"))
# 4.子菜单动作
self.file_action = QAction("python_test")
self.open_recent_menu.addAction(self.file_action)
# 添加
self.file_menu.addAction(self.new_action)
self.file_menu.addAction(self.open_action)
self.file_menu.addMenu(self.open_recent_menu)
self.file_menu.addSeparator()
self.file_menu.addAction(self.exit_action)
self.file_btn.setMenu(self.file_menu)
self.file_btn.setFlat(True)
'''
Tool_Bar
'''
# 创建水平布局
self.tool_bar_layout = QHBoxLayout()
# 使用水平布局
self.tool_bar.setLayout(self.tool_bar_layout)
# 1.打开文件
self.open_file_tb = QToolButton(self.tool_bar)
self.open_file_tb.setText("打开文件")
self.open_file_tb.setAutoRaise(True)
# 2.打开文件夹
self.open_dir_tb = QToolButton(self.tool_bar)
self.open_dir_tb.setText("打开文件夹")
self.open_dir_tb.setAutoRaise(True)
# 3.直线
self.line_tb = QToolButton(self.tool_bar)
self.line_tb.setText("直线")
self.line_tb.setAutoRaise(True)
# 4.矩形
self.rectangle_tb = QToolButton(self.tool_bar)
self.rectangle_tb.setText("矩形")
self.rectangle_tb.setAutoRaise(True)
# 5.圆形
self.circle_tb = QToolButton(self.tool_bar)
self.circle_tb.setText("圆形")
self.circle_tb.setAutoRaise(True)
# 6.自由绘制
self.polygon_tb = QToolButton(self.tool_bar)
self.polygon_tb.setText("自由绘制")
self.polygon_tb.setAutoRaise(True)
# 7.形态学
self.xtx_tb = QToolButton(self.tool_bar)
self.xtx_tb.setText("形态学")
self.xtx_tb.setAutoRaise(True)
# 8.模糊度
self.mhd_tb = QToolButton(self.tool_bar)
self.mhd_tb.setText("模糊度")
self.mhd_tb.setAutoRaise(True)
# 9.边缘检测
self.byjc_tb = QToolButton(self.tool_bar)
self.byjc_tb.setText("边缘检测")
self.byjc_tb.setAutoRaise(True)
# 10.亮度
self.ld_tb = QToolButton(self.tool_bar)
self.ld_tb.setText("亮度")
self.ld_tb.setAutoRaise(True)
# 11.对比度
self.dbd_tb = QToolButton(self.tool_bar)
self.dbd_tb.setText("对比度")
self.dbd_tb.setAutoRaise(True)
# 12.图像分类
self.classification_tb = QToolButton(self.tool_bar)
self.classification_tb.setText("图像分类")
self.classification_tb.setAutoRaise(True)
# 13.图像分割
self.segementation_tb = QToolButton(self.tool_bar)
self.segementation_tb.setText("图像分割")
self.segementation_tb.setAutoRaise(True)
# 14.图像检测
self.detection_tb = QToolButton(self.tool_bar)
self.detection_tb.setText("图像检测")
self.detection_tb.setAutoRaise(True)
# 15.三维重建
self.swcj_tb = QToolButton(self.tool_bar)
self.swcj_tb.setText("三维重建")
self.swcj_tb.setAutoRaise(True)
# 加入控件
self.tool_bar_layout.addWidget(self.open_file_tb,1)
self.tool_bar_layout.addWidget(self.open_dir_tb, 1)
self.tool_bar_layout.addWidget(self.line_tb, 1)
self.tool_bar_layout.addWidget(self.rectangle_tb, 1)
self.tool_bar_layout.addWidget(self.circle_tb, 1)
self.tool_bar_layout.addWidget(self.polygon_tb, 1)
self.tool_bar_layout.addWidget(self.xtx_tb,1)
self.tool_bar_layout.addWidget(self.mhd_tb, 1)
self.tool_bar_layout.addWidget(self.byjc_tb, 1)
self.tool_bar_layout.addWidget(self.ld_tb, 1)
self.tool_bar_layout.addWidget(self.dbd_tb, 1)
self.tool_bar_layout.addWidget(self.classification_tb, 1)
self.tool_bar_layout.addWidget(self.segementation_tb, 1)
self.tool_bar_layout.addWidget(self.detection_tb, 1)
self.tool_bar_layout.addWidget(self.swcj_tb, 1)
self.tool_bar_layout.addStretch(20)
'''
Left
'''
self.left_layout = QVBoxLayout()
self.left.setLayout(self.left_layout)
self.file_dir_tree = QTreeView()
self.left_layout.addWidget(self.file_dir_tree)
'''
Body
'''
self.body_layout = QVBoxLayout()
self.body.setLayout(self.body_layout)
self.img_show_lb = QLabel()
self.img_show_lb.setText("显示图片区域")
self.body_layout.addWidget(self.img_show_lb)
'''
Right
'''
self.right_layout = QVBoxLayout()
self.right.setLayout(self.right_layout)
self.tag_view_tv = QTableView(self.right)
self.right_layout.addWidget(self.tag_view_tv)
# def mouseMoveEvent(self,event):
# x = event.x()
# y = event.y()
# text = "x:{0},y:{1}".format(x,y)
# print(text)
'''
<2> 绘画
'''
'''
<3> dicom的图像和tag信息展示
'''
def open_dicom_file(self):
print("call_back_action_open_file")
fileName_choose, filetype = QFileDialog.getOpenFileName(self,
"选取文件",
self.cwd, # 起始路径
"All Files (*);;Text Files (*.txt)") # 设置文件扩展名过滤,用双分号间隔
if fileName_choose == "":
print("\n取消选择")
return
print("\n你选择的文件夹为:")
print(fileName_choose)
'''
1.显示图像
'''
dcm = pydicom.read_file(fileName_choose)
raw_img = dcm.pixel_array
# img = Image.fromarray(raw_img)
# img.show()
# 2.映射到0-255之间
raw_flatten_img = raw_img.flatten()
max_val = max(raw_flatten_img)
min_val = min(raw_flatten_img)
raw_img = (raw_img - min_val) / (max_val - min_val) # 图像归一化
raw_img = raw_img * 255
img = Image.fromarray(raw_img)
img.convert('RGB').save("rgb_show.jpg", format='jpeg')
# img.show() # 正常
# 转QImage
# 显示图片
self.img_show_lb.setPixmap(QPixmap("rgb_show.jpg"))
self.img_show_lb.setScaledContents(True)
'''
2.显示Tag信息
'''
info = {}
info["PatientID"] = dcm.PatientID # 患者ID
info["PatientName"] = dcm.PatientName # 患者姓名
info['StudyDate'] = dcm.StudyDate # 检查日期
info['PatientSex'] = dcm.PatientSex # 患者性别
info["PatientAge"] = dcm.PatientAge # 患者年龄
# print(info)
val_list = []
for val in info.values():
val_list.append(val)
# 2.在tabel中显示元信息
for row in range(len(info)):
#print(val_list[row])
item = QStandardItem(str(val_list[row]))
# 设置每个位置的文本值
self.dicom_tag_model.setItem(row, 0, item)
self.tag_view_tv.setModel(self.dicom_tag_model)
def open_dicom_dir(self):
dir_choose = QFileDialog.getExistingDirectory(self,
"选取文件夹",
self.cwd) # 起始路径
if dir_choose == "":
print("\n取消选择")
return
#print("\n你选择的文件夹为:")
#print(dir_choose)
self.dir_model.setRootPath(dir_choose)
self.file_dir_tree.setModel(self.dir_model)
self.file_dir_tree.setRootIndex(self.dir_model.index(dir_choose))
self.file_dir_tree.clicked.connect(self.show_info)
self.file_dir_tree.setColumnWidth(0,300)
#print("call_back_action_store_dir")
def show_info(self, signal):
'''
1.显示图像
'''
file_path=self.dir_model.filePath(signal)
# 1.pydicom读取dicom图像
dcm = pydicom.read_file(file_path)
raw_img = dcm.pixel_array
# img = Image.fromarray(raw_img)
# img.show()
# 2.映射到0-255之间
raw_flatten_img =raw_img.flatten()
max_val = max(raw_flatten_img)
min_val = min(raw_flatten_img)
raw_img = (raw_img-min_val)/(max_val-min_val) # 图像归一化
raw_img = raw_img*255
img = Image.fromarray(raw_img)
img.convert('RGB').save("rgb_show.jpg", format='jpeg')
# img.show() # 正常
# 转QImage
# 显示图片
self.img_show_lb.setPixmap(QPixmap("rgb_show.jpg"))
self.img_show_lb.setScaledContents(True)
'''
2.显示Tag信息
'''
info = {}
info["PatientID"] = dcm.PatientID # 患者ID
info["PatientName"] = dcm.PatientName # 患者姓名
info["PatientAge"] = dcm.PatientAge # 患者年龄
info['PatientSex'] = dcm.PatientSex # 患者性别
info['StudyDate'] = dcm.StudyDate # 检查日期
# print(info)
val_list = []
for val in info.values():
val_list.append(val)
# 2.在tabel中显示元信息
for row in range(len(info)):
# print(val_list[row])
item = QStandardItem(str(val_list[row]))
# 设置每个位置的文本值
self.dicom_tag_model.setItem(row, 0, item)
self.tag_view_tv.setModel(self.dicom_tag_model)
'''
<4> 图像的保存(jpg、dicom)
'''
'''
<5> 智能医学
'''
'''
<6> 三维重建
'''
'''
<7> 常用图像处理
'''
'''
<8> 生成病情报告
'''
'''
<9> 病人病情显示
'''
if __name__ == '__main__':
# 1.创建一个应用程序对象
app = QApplication(sys.argv)
# 2.控件的操作
# 2.1创建控件
window = FramePane()
# 2.2设置控件
# 2.3展示控件
window.show()
# 3.应用程序的执行,进入到信息循环
sys.exit(app.exec_())
5
# 0.导入需要的包和模块
import cv2
from PyQt5.Qt import *
import sys
import pydicom
from PIL import Image
import os
class FramePane(QWidget):
def __init__(self):
super().__init__()
self.setWindowTitle("Major")
self.resize(1400, 900)
self.setMouseTracking(True)
self.setup_ui()
# 定义绘画类型
self.Draw = ""
self.Line_list = [0, 0, 100, 100]
self.Point_list = []
self.Elipse_list = [0, 0, 0, 0]
self.Rectangle_list = [0, 0, 0, 0]
self.Polygon_list = []
# 其他
self.cwd = os.getcwd() # 获取当前路径
self.dir_model = QFileSystemModel() # 文件系统模型
self.dicom_tag_model = QStandardItemModel(5,1)
# 设置水平方向头标签文本内容
self.dicom_tag_model.setVerticalHeaderLabels(['ID', '姓名', '就诊日期', '性别', '年龄'])
self.dicom_tag_model.setHorizontalHeaderLabels(['值'])
self.flag = 0
'''
<1> 界面构造
'''
def setup_ui(self):
'''
主构造
'''
# 创建控件
self.menu_bar = QWidget()
# menu_bar.setStyleSheet("background-color:yellow;")
self.tool_bar = QWidget()
# tool_bar.setStyleSheet("background-color:red;")
self.left = QWidget()
# left.setStyleSheet("background-color:blue;")
self.body = QWidget()
# body.setStyleSheet("background-color:blue;")
self.body.setMouseTracking(True)
self.right = QWidget()
# right.setStyleSheet("background-color:blue;")
# 1.创建布局管理器对象
self.v_layout = QVBoxLayout()
self.h_layout = QHBoxLayout()
# 2.把布局管理器对象设置给需要布局的父控件
self.setLayout(self.v_layout)
# 3.添加需要布局的子控件到布局管理器当中
self.v_layout.addWidget(self.menu_bar)
self.v_layout.addWidget(self.tool_bar)
self.h_layout.addWidget(self.left)
self.h_layout.addWidget(self.body)
self.h_layout.addWidget(self.right)
self.v_layout.addLayout(self.h_layout)
# 4.设置伸缩因子
self.v_layout.setStretchFactor(self.menu_bar, 1)
self.v_layout.setStretchFactor(self.tool_bar, 1)
self.v_layout.setStretchFactor(self.h_layout, 20)
self.h_layout.setStretchFactor(self.left,2)
self.h_layout.setStretchFactor(self.body,8)
self.h_layout.setStretchFactor(self.right,2)
'''
Menu_Bar
'''
# 创建水平布局
self.menu_bar_layout = QHBoxLayout()
# 使用水平布局
self.menu_bar.setLayout(self.menu_bar_layout)
# 加入控件
self.file_btn = QPushButton(self.menu_bar)
self.file_btn.setText("file")
self.menu_bar_layout.addWidget(self.file_btn,1)
self.menu_bar_layout.addStretch(20)
# 创建菜单
self.file_menu = QMenu()
# 创建子菜单
self.open_recent_menu = QMenu(self.file_menu)
self.open_recent_menu.setTitle("最近打开")
# 1.新建动作
self.new_action = QAction(QIcon(r".\resources\images\1.png"), "打开文件", self.file_menu)
self.new_action.triggered.connect(self.open_dicom_file)
# 2.打开动作
self.open_action = QAction(QIcon(r".\resources\images\1.png"), "打开文件夹", self.file_menu)
self.open_action.triggered.connect(self.open_dicom_dir)
# 3.退出动作
self.exit_action = QAction(QIcon(r".\resources\images\1.png"), "退出", self.file_menu)
self.exit_action.triggered.connect(lambda: print("退出程序"))
# 4.子菜单动作
self.file_action = QAction("python_test")
self.open_recent_menu.addAction(self.file_action)
# 添加
self.file_menu.addAction(self.new_action)
self.file_menu.addAction(self.open_action)
self.file_menu.addMenu(self.open_recent_menu)
self.file_menu.addSeparator()
self.file_menu.addAction(self.exit_action)
self.file_btn.setMenu(self.file_menu)
self.file_btn.setFlat(True)
'''
Tool_Bar
'''
# 创建水平布局
self.tool_bar_layout = QHBoxLayout()
# 使用水平布局
self.tool_bar.setLayout(self.tool_bar_layout)
# 1.打开文件
self.open_file_tb = QToolButton(self.tool_bar)
self.open_file_tb.setText("打开文件")
self.open_file_tb.setAutoRaise(True)
self.open_file_tb.clicked.connect(self.open_dicom_file)
# 2.打开文件夹
self.open_dir_tb = QToolButton(self.tool_bar)
self.open_dir_tb.setText("打开文件夹")
self.open_dir_tb.setAutoRaise(True)
self.open_dir_tb.clicked.connect(self.open_dicom_dir)
# 3.直线
self.line_tb = QToolButton(self.tool_bar)
self.line_tb.setText("直线")
self.line_tb.setAutoRaise(True)
# 4.矩形
self.rectangle_tb = QToolButton(self.tool_bar)
self.rectangle_tb.setText("矩形")
self.rectangle_tb.setAutoRaise(True)
# 5.圆形
self.circle_tb = QToolButton(self.tool_bar)
self.circle_tb.setText("圆形")
self.circle_tb.setAutoRaise(True)
# 6.自由绘制
self.polygon_tb = QToolButton(self.tool_bar)
self.polygon_tb.setText("自由绘制")
self.polygon_tb.setAutoRaise(True)
# 7.旋转
self.rotate_tb = QToolButton(self.tool_bar)
self.rotate_tb.setText("旋转")
self.rotate_tb.setAutoRaise(True)
self.rotate_tb.clicked.connect(self.rotate_img)
# 8.缩放
self.scale_tb = QToolButton(self.tool_bar)
self.scale_tb.setText("缩放")
self.scale_tb.setAutoRaise(True)
self.scale_tb.clicked.connect(self.scale_img)
# 9.边缘检测
self.byjc_tb = QToolButton(self.tool_bar)
self.byjc_tb.setText("边缘检测")
self.byjc_tb.setAutoRaise(True)
# 10.亮度
self.ld_tb = QToolButton(self.tool_bar)
self.ld_tb.setText("亮度")
self.ld_tb.setAutoRaise(True)
self.ld_tb.clicked.connect(self.bright_img)
# 11.对比度
self.dbd_tb = QToolButton(self.tool_bar)
self.dbd_tb.setText("对比度")
self.dbd_tb.setAutoRaise(True)
self.dbd_tb.clicked.connect(self.contrast_img)
# 12.图像分类
self.classification_tb = QToolButton(self.tool_bar)
self.classification_tb.setText("图像分类")
self.classification_tb.setAutoRaise(True)
# 13.图像分割
self.segementation_tb = QToolButton(self.tool_bar)
self.segementation_tb.setText("图像分割")
self.segementation_tb.setAutoRaise(True)
# 14.图像检测
self.detection_tb = QToolButton(self.tool_bar)
self.detection_tb.setText("图像检测")
self.detection_tb.setAutoRaise(True)
# 15.三维重建
self.swcj_tb = QToolButton(self.tool_bar)
self.swcj_tb.setText("三维重建")
self.swcj_tb.setAutoRaise(True)
self.swcj_tb.clicked.connect(self.reconstruct_3D)
# 加入控件
self.tool_bar_layout.addWidget(self.open_file_tb,1)
self.tool_bar_layout.addWidget(self.open_dir_tb, 1)
self.tool_bar_layout.addWidget(self.line_tb, 1)
self.tool_bar_layout.addWidget(self.rectangle_tb, 1)
self.tool_bar_layout.addWidget(self.circle_tb, 1)
self.tool_bar_layout.addWidget(self.polygon_tb, 1)
self.tool_bar_layout.addWidget(self.rotate_tb,1)
self.tool_bar_layout.addWidget(self.scale_tb, 1)
self.tool_bar_layout.addWidget(self.byjc_tb, 1)
self.tool_bar_layout.addWidget(self.ld_tb, 1)
self.tool_bar_layout.addWidget(self.dbd_tb, 1)
self.tool_bar_layout.addWidget(self.classification_tb, 1)
self.tool_bar_layout.addWidget(self.segementation_tb, 1)
self.tool_bar_layout.addWidget(self.detection_tb, 1)
self.tool_bar_layout.addWidget(self.swcj_tb, 1)
self.tool_bar_layout.addStretch(20)
'''
Left
'''
self.left_layout = QVBoxLayout()
self.left.setLayout(self.left_layout)
self.file_dir_tree = QTreeView()
self.left_layout.addWidget(self.file_dir_tree)
'''
Body
'''
self.body_layout = QVBoxLayout()
self.body.setLayout(self.body_layout)
self.img_show_lb = QLabel()
self.img_show_lb.setText("显示图片区域")
self.img_show_lb.setMouseTracking(True)
self.body_layout.addWidget(self.img_show_lb)
'''
Right
'''
self.right_layout = QVBoxLayout()
self.right.setLayout(self.right_layout)
self.tag_view_tv = QTableView(self.right)
self.right_layout.addWidget(self.tag_view_tv)
def mouseMoveEvent(self,event):
x = event.x()
y = event.y()
text = "x:{0},y:{1}".format(x,y)
print(text)
'''
<2> 绘画
'''
def DrawLine(self):
self.update()
self.Draw = "Line"
# def paintEvent(self, QPaintEvent):
# print("test")
# # painter = QPainter(self)
# # painter.setPen(QColor(166, 66, 250))
# # painter.begin(self)
# # if self.Draw == "Line":
# # painter.drawLine(self.Line_list[0], self.Line_list[1], self.Line_list[2], self.Line_list[3])
# # print("DrawLine")
# # painter.end()
'''
<3> dicom的图像和tag信息展示
'''
def open_dicom_file(self):
print("call_back_action_open_file")
fileName_choose, filetype = QFileDialog.getOpenFileName(self,
"选取文件",
self.cwd, # 起始路径
"All Files (*);;Text Files (*.txt)") # 设置文件扩展名过滤,用双分号间隔
if fileName_choose == "":
print("\n取消选择")
return
print("\n你选择的文件夹为:")
print(fileName_choose)
'''
1.显示图像
'''
dcm = pydicom.read_file(fileName_choose)
raw_img = dcm.pixel_array
# img = Image.fromarray(raw_img)
# img.show()
# 2.映射到0-255之间
raw_flatten_img = raw_img.flatten()
max_val = max(raw_flatten_img)
min_val = min(raw_flatten_img)
raw_img = (raw_img - min_val) / (max_val - min_val) # 图像归一化
raw_img = raw_img * 255
img = Image.fromarray(raw_img)
img.convert('RGB').save("rgb_show.jpg", format='jpeg')
# img.show() # 正常
# 转QImage
# 显示图片
self.img_show_lb.setPixmap(QPixmap("rgb_show.jpg"))
self.img_show_lb.setScaledContents(True)
'''
2.显示Tag信息
'''
info = {}
info["PatientID"] = dcm.PatientID # 患者ID
info["PatientName"] = dcm.PatientName # 患者姓名
info['StudyDate'] = dcm.StudyDate # 检查日期
info['PatientSex'] = dcm.PatientSex # 患者性别
info["PatientAge"] = dcm.PatientAge # 患者年龄
# print(info)
val_list = []
for val in info.values():
val_list.append(val)
# 2.在tabel中显示元信息
for row in range(len(info)):
#print(val_list[row])
item = QStandardItem(str(val_list[row]))
# 设置每个位置的文本值
self.dicom_tag_model.setItem(row, 0, item)
self.tag_view_tv.setModel(self.dicom_tag_model)
def open_dicom_dir(self):
dir_choose = QFileDialog.getExistingDirectory(self,
"选取文件夹",
self.cwd) # 起始路径
if dir_choose == "":
print("\n取消选择")
return
#print("\n你选择的文件夹为:")
#print(dir_choose)
self.dir_model.setRootPath(dir_choose)
self.file_dir_tree.setModel(self.dir_model)
self.file_dir_tree.setRootIndex(self.dir_model.index(dir_choose))
self.file_dir_tree.clicked.connect(self.show_info)
self.file_dir_tree.setColumnWidth(0,300)
#print("call_back_action_store_dir")
def show_info(self, signal):
'''
1.显示图像
'''
file_path=self.dir_model.filePath(signal)
# 1.pydicom读取dicom图像
dcm = pydicom.read_file(file_path)
raw_img = dcm.pixel_array
# img = Image.fromarray(raw_img)
# img.show()
# 2.映射到0-255之间
raw_flatten_img =raw_img.flatten()
max_val = max(raw_flatten_img)
min_val = min(raw_flatten_img)
raw_img = (raw_img-min_val)/(max_val-min_val) # 图像归一化
raw_img = raw_img*255
img = Image.fromarray(raw_img)
img.convert('RGB').save("rgb_show.jpg", format='jpeg')
# img.show() # 正常
# 转QImage
# 显示图片
self.img_show_lb.setPixmap(QPixmap("rgb_show.jpg"))
self.img_show_lb.setScaledContents(True)
'''
2.显示Tag信息
'''
info = {}
info["PatientID"] = dcm.PatientID # 患者ID
info["PatientName"] = dcm.PatientName # 患者姓名
info["PatientAge"] = dcm.PatientAge # 患者年龄
info['PatientSex'] = dcm.PatientSex # 患者性别
info['StudyDate'] = dcm.StudyDate # 检查日期
# print(info)
val_list = []
for val in info.values():
val_list.append(val)
# 2.在tabel中显示元信息
for row in range(len(info)):
# print(val_list[row])
item = QStandardItem(str(val_list[row]))
# 设置每个位置的文本值
self.dicom_tag_model.setItem(row, 0, item)
self.tag_view_tv.setModel(self.dicom_tag_model)
'''
<4> 图像的保存(jpg、dicom)
'''
'''
<5> 智能医学
'''
'''
<6> 三维重建
'''
def reconstruct_3D(self):
dir_choose = QFileDialog.getExistingDirectory(self,
"选取文件夹",
self.cwd) # 起始路径
if dir_choose == "":
print("\n取消选择")
return
print(dir_choose)
from util import three_d_reconstruction
three_d_reconstruction.show_3d(dir_choose+'/')
'''
<7> 常用图像处理
'''
# 7.1 旋转
def rotating_img(self):
self.img_show_lb.setText(str(self.dial.value()))
img = Image.open("rgb_show.jpg")
img_rotated = img.rotate(angle=self.dial.value())
img_rotated.save("rgb_rotated_show.jpg")
self.img_show_lb.setPixmap(QPixmap("rgb_rotated_show.jpg"))
self.img_show_lb.setScaledContents(True)
def rotate_img(self):
self.dial = QDial()
# 设置最大值和最小值
self.dial.setMinimum(0)
self.dial.setMaximum(360)
# 绑定槽函数
self.dial.valueChanged.connect(self.rotating_img)
# 外观倒立
self.dial.setInvertedAppearance(True)
self.dial.show()
# 7.2 缩放图像
def scaling_img(self):
self.img_show_lb.setText(str(self.scale_sd.value()))
img = cv2.imread('rgb_show.jpg')
# 方法一:通过设置缩放比例,来对图像进行放大或缩小
res1 = cv2.resize(img, None, fx=self.scale_sd.value() / 100, fy=self.scale_sd.value() / 100,
interpolation=cv2.INTER_CUBIC)
cv2.imwrite("scaled_img.jpg", res1)
self.img_show_lb.setPixmap(QPixmap("scaled_img.jpg"))
self.img_show_lb.adjustSize() # 窗口适应图片
def scale_img(self):
self.scale_sd= QSlider()
# 设置最大值和最小值
self.scale_sd.setMinimum(10)
self.scale_sd.setMaximum(500)
# 绑定槽函数
self.scale_sd.valueChanged.connect(self.scaling_img)
# 外观倒立
self.scale_sd.setInvertedAppearance(True)
self.scale_sd.show()
# 7.3 亮度
def brighting_img(self):
self.img_show_lb.setText(str(self.bright_sd.value()))
print(self.bright_sd.value() / 100)
img = cv2.imread('rgb_show.jpg')
# 调节亮度
res = img * (self.bright_sd.value() / 100)
cv2.imwrite("light_img.jpg", res)
self.img_show_lb.setPixmap(QPixmap("light_img.jpg"))
self.img_show_lb.setScaledContents(True)
def bright_img(self):
self.bright_sd= QSlider()
# 设置最大值和最小值
self.bright_sd.setMinimum(10)
self.bright_sd.setMaximum(500)
# 绑定槽函数
self.bright_sd.valueChanged.connect(self.brighting_img)
# 外观倒立
self.bright_sd.setInvertedAppearance(True)
self.bright_sd.show()
# 7.4 对比度
def contrasting_img(self):
self.img_show_lb.setText(str(self.contrast_sd.value()))
img = cv2.imread('rgb_show.jpg')
# 调节对比度
res = img + self.contrast_sd.value()
cv2.imwrite("light_img.jpg", res)
self.img_show_lb.setPixmap(QPixmap("light_img.jpg"))
self.img_show_lb.setScaledContents(True)
def contrast_img(self):
self.contrast_sd= QSlider()
# 设置最大值和最小值
self.contrast_sd.setMinimum(0)
self.contrast_sd.setMaximum(255)
# 绑定槽函数
self.contrast_sd.valueChanged.connect(self.contrasting_img)
# 外观倒立
self.contrast_sd.setInvertedAppearance(True)
self.contrast_sd.show()
'''
<8> 生成病情报告
'''
'''
<9> 病人病情显示
'''
if __name__ == '__main__':
# 1.创建一个应用程序对象
app = QApplication(sys.argv)
# 2.控件的操作
# 2.1创建控件
window = FramePane()
# 2.2设置控件
# 2.3展示控件
window.show()
# 3.应用程序的执行,进入到信息循环
sys.exit(app.exec_())