MRI Series Viewer

Hi all,

Just wanted to share a little bokeh app I created some time ago. It was written as a simple 2D viewer for MRI data, but it could easily be used to visualize any 3D matrix in the same way.

The code is available on GitHub. It still needs some drastic refactoring but I added docstrings in case anyone actually wants to do anything with it.

The frame rate on the recording isn’t great so it looks a little jumpy, but it’s working smoothly enough :slight_smile:

In the beginning of the gif I change the displayed images by clicking a point in one plane, which causes updates in the indices of the two other planes according to the location of the Tap event.
Afterwards I change the index using the MouseWheel event, and finally by using the sliders. They aren’t visible here until I use them but the sliders are of course updated together with the previous options as well.


This is really fantastic! Are there any particular issues you encountered during making this, or things that might make developing something like this simpler?

I’m not an experienced programmer, so it’s hard for me to tell which difficulties stem from my own lack of experience and what could actually be constructive to share, but I hope that these two points would make some sense:

  • Working with the 3D matrix was a little confusing. I ended up creating three separate ColumnDataSource instances that are updated from a global data variable using a function that extracts the relevant image as indices are updated. It’s working fine but I did feel like perhaps I’m missing a more elegant way to manage it.

  • I was a little thrown off in the beginning by the way an app is generally written as a script. I was constantly looking to objectify things until I eventually felt like I’m simply misusing bokeh and yielded to writing most of it using simple functions. I still feel like there must be a cleaner way to write the app, but I’m not really sure how to approach it. Should I just refactor functions to separate files according to their purpose in the application? Should I try to make abstractions of those (mostly) independent parts and rewrite them as classes? I guess what I’m trying to say is that I feel like I’m lacking a clear approach to writing clean and modular applications that can scale.

Hope this isn’t completely useless. Also, great talk on Talk Python To Me last month! It was really fascinating to hear about the evolution of bokeh and your own journey along with it. Thank you for sharing from your valuable experience.