No account yet ?
.mha is a MetaImage format for medical images used in graphic visualization software used in medicine.
Tested in Anaconda and Python 3.7
import skimage.io import matplotlib.pyplot as plt import os def mha2png(file_path, dest_dir, slices=None): if not os.path.exists(dest_dir): output_file = dest_dir os.mkdir(output_file) img = skimage.io.imread(fname=file_path, plugin='simpleitk') if slices == None: slice_min = 0 slice_max = img.shape[0] else: slice_min = slices[0] slice_max = slices[1] for slicer in range(slice_min,slice_max): plt.imsave(dest_dir + '/' + dest_dir + '_' + str(slicer) + '.png', img[slicer], cmap='gray',format='png') if __name__=='__main__': input_path = ('mha') for root, dirs, files in os.walk(input_path): for filename in files: input_file = os.path.join(root, filename) output_path = input_file.replace('.mha','') output_path = output_path.replace(input_path,'') output_path = output_path.replace('\\','') mha2png(input_file, output_path)
mha2png
Copyright (c) 2023 elodees
Downloading and Viewing the training_001_mr_T1.mha File
Welcome, my name is Eric Soupet and I am the administrator of the site elodees.com. elodees.com is a state of the art of Artificial Intelligence and aims to be collaborative, you can now offer content such as articles, events, tutorials, ... so don't hesitate !
Platform images credit : Pixabay - Pixabay License | Pexels - Pexels License