I have an MHA file and when I write
from medpy.io import load
image_data, image_header = load("HG/0001/VSD.Brain.XX.O.MR_Flair/VSD.Brain.XX.O.MR_Flair.684.mha")
print(image_data.shape)
I get a tuple (160, 216, 176). What do these dimensions represent (for reference these are brain tumor images from BRATS 2013)? Your help is appreciated.
Edit: on Jupyter for the slider to work I did
import matplotlib.pyplot as plt
from ipywidgets import interact
import numpy as np
%matplotlib inline
@interact(x=(0, image_data.shape[2]))
def update(x):
plt.imshow(np.flip(image_data[x].T, 0))
but of course your code probably works on other editors
According to the documentation, load(image) "Loads the image and returns a ndarray
with the image’s pixel content as well as a header object."
Further down in medpy.io.load
it says that image_data is "The image data as numpy array with order x,y,z,c.".
Edit: Because I was kind of curious to see what is actually in this file, I put together a quick script (heavily based on the slider demo) to take a look. I'll leave it here just in case it may be useful to someone. (Click on the "Layer" slider to select the z-coordinate to be drawn.)
from medpy.io import load
image_data, image_header = load("/tmp/VSD.Brain.XX.O.MR_Flair.684.mha")
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.widgets import Slider, Button, RadioButtons
fig, ax = plt.subplots()
plt.subplots_adjust(bottom=0.25)
axlayer = plt.axes([0.25, 0.1, 0.65, 0.03])
slider_layer = Slider(axlayer, 'Layer', 1, image_data.shape[2], valinit=1, valstep=1)
def update(val):
layer = slider_layer.val
ax.imshow(image_data[:,:,layer])
fig.canvas.draw_idle()
slider_layer.on_changed(update)
ax.imshow(image_data[:,:,0])
plt.show()
(This indirectly confirms that image_data
holds a 3-D voxel image.)