how to view mha file in Python

Hi all,

a beginner here, I am working on prostate cancer 3D dataset using deep learning,
I can open these 3D files using Fiji, how I can open in python using SimpleITK ?
do I need to convert these file into specific format in order to view it?

if you can share any relevant documents to work with 3D MRI dataset would be helpful.

thank you so much in advance.

each patient has five mha files.
each patient dataset look like this:

['10466_1000474_hbv.mha', '10466_1000474_sag.mha', '10466_1000474_t2w.mha', '10466_1000474_cor.mha', '10466_1000474_adc.mha']

Hello @Uljibuh,

Reading the images is straightforward:

import SimpleITK

image = sitk.ReadImage("10466_1000474_hbv.mha")

SimpleITK only provides components for image analysis, not for visualization. A utility function, Show, and class, ImageViewer, for displaying images using external programs are available. By default the external program is Fiji (this is configurable so can use other programs).

As you are new to SimpleITK, I highly recommend going over the fundamental concepts, common conventions, and possibly the online tutorial. You may also find the toolkit’s Jupyter notebook repository of interest.

1 Like

Thank you for response, your shared information is helpful for me to go further.
have a nice day.