1234567891011121314151617181920212223242526 |
- import pandas as pd
- import nibabel as nib
- import matplotlib.pyplot as plt
- '''
- Function to load and show image. If the image is NL, control must be true.
- '''
- def show_image(image_id, show=True, data_path='./ADNI_volumes_customtemplate_float32/', annotations_path='./LP_ADNIMERGE.csv'):
- print('Image ID: ' + str(image_id))
- annotations_file = pd.read_csv(annotations_path)
- image_info = annotations_file[annotations_file["Image Data ID"] == image_id]
- print(image_info)
- if image_info.iat[0,0] == "CN":
- loaded_data = nib.load(data_path + 'Inf_NaN_stableNL__I' + str(image_id) + '_masked_brain.nii.nii').get_fdata()
- else:
- loaded_data = nib.load(data_path + 'Inf_NaN_stableAD__I' + str(image_id) + '_masked_brain.nii.nii').get_fdata()
- print(loaded_data.shape) # Dimensions: (91, 109, 91)
- if show:
- image = loaded_data[:, :, 40]
- plt.imshow(image)
- plt.show()
|