File size: 1,023 Bytes
ecf08bc |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
import SimpleITK as sitk
import argparse
import numpy as np
import torch
import os
from batchgenerators.utilities.file_and_folder_operations import join, isdir, maybe_mkdir_p
import matplotlib.image as pltimage
def main(input_folder):
files = os.listdir(input_folder)
output_folder = join(input_folder, 'pngs')
maybe_mkdir_p(output_folder)
for file in files:
if file.endswith('.gz'):
file_path = join(input_folder, file)
image = sitk.ReadImage(file_path)
image = sitk.GetArrayFromImage(image)
image = image[0]
color_image = image*255
output_path = join(output_folder, file[:-len('.nii.gz')] + '_front.png')
pltimage.imsave(output_path, color_image, cmap='gray', vmax=255)
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument("-i", '--input_folder', help="Folder with NIfTI files")
args = parser.parse_args()
input_folder = args.input_folder
main(input_folder) |