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



我在应用程序中加载了一个 .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]:https://i.stack.imgur.com/vzDJt.png(

我需要更新相同的图形/情节,可以吗?

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

如果你看一下SimpleITK-Notebooks,这几乎就是Jupyter笔记本中图像的显示方式。

http://insightsoftwareconsortium.github.io/SimpleITK-Notebooks/Python_html/04_Image_Display.html

"使用 matplotlib 进行内联显示"部分使用imshow来显示图像。

最新更新