def __getitem__(self, idx): temp = load_fmri(self.samples[idx]).get_data() # temp[temp < scoreatpercentile(temp.flatten(),2)] = 0 max_weight = temp.max() temp = temp / max_weight min_weight = np.abs(temp.min()) temp = temp + min_weight return temp, max_weight, min_weight
def __getitem__(self, idx):# for each item in the sample """ Because we will use binary cross entropy loss function, it is crutial that we make sure the data range between 0 and 1 """ # load the nii.gz format data temp = load_fmri(self.samples[idx]).get_data() # get the maximum of the volume max_weight = temp.max() # ge the minmum of the volume min_weight = temp.min() # standardize temp_std = (temp - min_weight) / (max_weight - min_weight) temp_scaled = temp_std * (1 - 0) + 0 return temp_scaled,max_weight,min_weight,self.samples[idx]
def __getitem__(self, idx): label, name = self.samples[idx] print('label is %s' % label) print('name is %s' % name) load = load_fmri(name).get_data() npimg = np.array(load, dtype='int32') npimg_fit = (npimg + 1) * 127.5 npimg_fit = npimg_fit.astype(np.uint8) transform = transforms.Compose([ transforms.ToPILImage(), transforms.ToTensor(), ]) img = torch.tensor(transform(npimg_fit)) nplabel = np.asarray(label, dtype='int32') print('nplabel is %s' % nplabel) return img, nplabel
# -*- coding: utf-8 -*- """ Created on Wed Aug 21 10:53:56 2019 @author: nmei """ import os from glob import glob from nipype.interfaces import afni from nilearn.image import resample_img from nibabel import load as load_fmri data_dir = '../data/converted' filtered = glob(os.path.join(data_dir, "*/*/*/*/*", "filtered.nii.gz")) target_func = load_fmri( os.path.abspath(os.path.join(data_dir, 'target_func.nii.gz'))) for idx in range(len(filtered)): picked_data = os.path.abspath(filtered[idx]) resample3d = afni.utils.Resample(voxel_size=(2.386364, 2.386364, 2.4)) resample3d.inputs.in_file = picked_data resample3d.inputs.outputtype = 'NIFTI_GZ' resample3d.inputs.out_file = picked_data.replace( 'filtered.nii.gz', 'filtered_resample.nii.gz') print(resample3d.cmdline) resample3d.run() resampled = resample_img(resample3d.inputs.out_file, target_affine=target_func.affine, target_shape=(88, 88, 66)) resampled.to_filename(
def __getitem__(self, idx): return load_fmri(self.samples[idx]).get_data() / load_fmri( self.samples[idx]).get_data().max()