python - 如何更新脑切片的 Tkinter 图中的值,以便能够从 4D 图像中翻阅不同的脑容量
问题描述
我正在尝试设计一个 python gui,以便能够通过绘制大脑切片、逐帧位移时间序列和运动检测算法的不同输出来评估运动的影响。我希望能够单独滑过每个大脑体积(每次扫描 180 个体积),以便我可以将 FD 时间过程与实际大脑数据的样子进行比较。
我一直在使用 tkinter,我可以绘制一个脑容量的多个切片,但我正在更新选定的容量。我尝试创建按钮来前进和后退,并且还使用了 tkinter Scale。
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg, NavigationToolbar2TkAgg
from matplotlib.figure import Figure
from matplotlib import pyplot as plt
import os
import nibabel
from nilearn import plotting
from nilearn import image
from matplotlib.widgets import Slider, Button, RadioButtons
data_path = os.getcwd()
file='sub-HV01baseline_task-EA1_bold.nii'
file_path = os.path.join(data_path,file)
EA1=nibabel.load(file_path)
struct_arr2 = EA1.get_data()
vol=1
import tkinter as tk
from tkinter import ttk
fig = plt.Figure(figsize=(10,5), dpi=100)
class App:
def __init__(self, master):
self.event_num = 1
frame = tk.Frame(master)
frame.pack()
self.txt = tk.Entry(frame,width=10)
self.txt.pack(side="bottom")
self.lbl = tk.Label(frame, text="FD Value")
self.lbl.pack(side="bottom")
self.btn = tk.Button(frame, text = "Update",command=self.clicked)
self.btn.pack(side="bottom")
self.txt.focus()
self.var =tk.IntVar(frame)
self.var.set(0)
self.vol_scale=tk.Scale(frame,from_=0, to=180,orient="horizontal",sliderlength=20,command=self.show_slices(fig))
self.increase_btn = tk.Button(frame, text = "Increase",command=self.show_slices(fig))
self.increase_btn.pack(side="bottom")
self.vol_scale.pack(side="bottom")
#self.spin = tk.Spinbox(frame, from_=0, to=180, width=5, textvariable=self.var)
#self.spin.pack(side="bottom")
self.canvas = FigureCanvasTkAgg(fig,master=master)
self.canvas.get_tk_widget().pack(side=tk.TOP)
def clicked(self):
res = "FD = " + self.txt.get()
self.lbl.configure(text = res)
def show_slices(self,fig):
vol = self.vol_scale.get()
slice_0 = struct_arr2[:, :, 10,vol]
slice_1 = struct_arr2[:, : , 15,vol]
slice_2 = struct_arr2[:, :, 20,vol]
slice_3 = struct_arr2[:, :, 25,vol]
slice_4 = struct_arr2[:, : , 30,vol]
slices=[slice_0, slice_1, slice_2, slice_3, slice_4]
axes = fig.subplots(1, len(slices))
#svol = Slider(axes, 'Vol', 0, 180, valinit=0, valstep=1)
fig.subplots_adjust(hspace=0, wspace=0)
for i, slice in enumerate(slices):
axes[i].xaxis.set_major_locator(plt.NullLocator())
axes[i].yaxis.set_major_locator(plt.NullLocator())
axes[i].imshow(slice.T, origin="lower")
root=tk.Tk()
app = App(root)
root.mainloop()
目前我收到一个错误“应用程序没有属性'vol_scale'”,即使我已经在上面定义了它。
解决方案
推荐阅读
- sql-server - 对象名称“AMAPHLINK.Payroll.dbo.EmpResignTb”包含的前缀数量超过了最大数量。最大值为 2
- javascript - 在加载的网页顶部添加一个按钮
- java - 编写一个程序,将用户的输入作为数组接收,并将其与另一个数组进行比较,以使用 while 循环检查正确答案
- java - 从 Windows (DOS) shell 运行 Eclipse Java Maven 项目
- reactjs - 如何使用异步请求的响应初始化 Redux 状态
- assembly - 8085; 为什么 RET 不需要像 CALL 那样的 6 个 T 状态 Fetch 循环?
- angular7 - 组件离开角度7后如何重置表单
- ios - 如何使用 Swift5 仅通过相机扫描某些区域?
- android - 升级 android 应用程序时要采取的措施
- cmake - 有什么方法可以在没有 cmake 的情况下构建柯南