alexlaurence / NIfTI-Image-Converter

🖼 A lightweight neuroimaging .nii to .png converter for Matlab and Python users
https://alexlaurence.github.io/NIfTI-Image-Converter/
MIT License
117 stars 39 forks source link

NIFTI images (MRI, DTI, and PET) from ADNI database to jpg #23

Open dupfem opened 1 year ago

dupfem commented 1 year ago

I have the dataset with four classes . I want to convert the NIFTI images to jpg to develop a model for classification

I am still debugging this segments of the code: base_path=os.path.abspath(os.path.dirname(file)) parser = argparse.ArgumentParser(description='Arguments for input and output files') parser.add_argument('--input_path', type=str, default = base_path, help='Path of the input files') parser.add_argument('--rotation_angle', type=int, default = 90, help='Rotation degree, i.e., 90°, 180°, 270°, default value is 90°') args = parser.parse_args() input_path = args.input_path rotation_angle = args.rotation_angle ##############################################################

get list of nii or nii.gz source files

source_files = os.listdir(input_path) slice_counter = 0

identify sample ids and get source ids

source_ids = [files[0:8] for files in source_files if files.endswith('.nii')]

sample_ids = list(set(source_ids))

monjoybme commented 1 year ago

Did you change .png to .jpg or .jpeg? Follow the below steps and run the code. Replace: image_name = fname[:-4] + "_z" + "{:0>3}".format(str(current_slice+1))+ ".png"

with image_name = fname[:-4] + "_z" + "{:0>3}".format(str(current_slice+1))+ ".jpeg"

and Replace: image_name = fname[:-4] + "_z" + "{:0>3}".format(str(current_slice+1))+ ".png"

with image_name = fname[:-4] + "_z" + "{:0>3}".format(str(current_slice+1))+ ".jpeg"

Let me know if it works for you. Else, you may share a single data for testing.