Image Python:使用带滑块权重的图像更新绘图

Image Python:使用带滑块权重的图像更新绘图,image,matplotlib,plot,simpleitk,mri,Image,Matplotlib,Plot,Simpleitk,Mri,我在应用程序中加载了一个.nii文件 def show(self): image = SimpleITK.ReadImage(file_name) t1 = SimpleITK.GetArrayFromImage(image) t2 = color.rgb2gray(t1[w.get()]) print(w.get()) print(t2.shape) plt.ion() fig = plt.figure() ax = fig.ad

我在应用程序中加载了一个.nii文件

def show(self):
    image = SimpleITK.ReadImage(file_name)
    t1 = SimpleITK.GetArrayFromImage(image)
    t2 = color.rgb2gray(t1[w.get()])
    print(w.get())
    print(t2.shape)
    plt.ion()
    fig = plt.figure()
    ax = fig.add_subplot(111)
    line1 = ax.imshow(t2, cmap='gray')
当我移动滑块并在新图形中显示大脑切片时,会调用此函数。(应用程序的屏幕截图附在此处:[1]:)


我需要更新相同的图形/绘图,这是可能的,但我不会每次调用
show
时都调用
ReadImage
GetArrayFromImage
。您不希望每次小部件更改时都重新加载和转换图像。当应用程序启动时,执行这些操作一次

如果你看看SimpleTik笔记本电脑,你会发现Jupyter笔记本电脑中的图像显示方式非常相似


“使用matplotlib内联显示”部分使用
imshow
来显示图像。

应该可以,但我不会每次调用
show
时都调用
ReadImage
getarrayfrommage
。您不希望每次小部件更改时都重新加载和转换图像。当应用程序启动时,执行这些操作一次

如果你看看SimpleTik笔记本电脑,你会发现Jupyter笔记本电脑中的图像显示方式非常相似


“使用matplotlib内联显示”部分使用
imshow
显示图像。

我将所有这些放在一个函数中,仅用于上下文。我将所有这些放在一个函数中,仅用于上下文。