Cristina Bîrsan
Cristina Bîrsan

Reputation: 11

Python: update plot with image with slider weight

I loaded a .nii file in my application.

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')

This function it is called when I move the slider and show me in a new figure the slice of brain.(the screenshot of application is attach here: [1]: https://i.sstatic.net/vzDJt.png)

I need to update the same figure/plot, it is possible?

Upvotes: 1

Views: 219

Answers (1)

Dave Chen
Dave Chen

Reputation: 2085

That should work, but I would not be calling ReadImage and GetArrayFromImage every time show gets called. You don't want to be re-loading and converting the image each time your widget changes. Do those thing once, when the application starts.

If you look at the SimpleITK-Notebooks that's pretty much how images are displayed in Jupyter notebooks.

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

The section 'Inline display with matplotlib' uses imshow to display images.

Upvotes: 0

Related Questions