def resample_to_average(tex_path, subject, side, verbose=False): """Resample a given texture to fsaverage Parameters ========== tex_path: string, path of the input texture subject: string, subject id in the freesurfer database side: string, on of ['left', 'right'] verbose: boolean, the verbosity mode Returns ======= resmapled: string, path of the result """ resampled = op.join(op.dirname(tex_path), op.basename(tex_path)[:-4] + '_resampled.gii') # convert the input to .mgz format mgz = tex_path[:-4] + '.mgz' tex = load_texture(tex_path)[np.newaxis, np.newaxis].T mghformat.save(Nifti1Image(tex, np.eye(4)), mgz) # run the resmapling using freesurfer tools fs_comment = commands.getoutput( 'mri_surf2surf --srcsubject %s --srcsurfval %s --trgsubject ico --trgsurfval %s --hemi %sh --trgicoorder 7' % ( subject, mgz, resampled, side[0])) if verbose: print fs_comment return resampled
def resample_to_subject(tex_path, subject, side, output_path, verbose=False): """Resample a given texture from fsaverage to subject space Parameters ========== tex_path: string, path of the input texture subject: string, subject id in the freesurfer database side: string, on of ['left', 'right'] outoput_path: string verbose: boolean, the verbosity mode """ # convert the input to .mgz format mgz = tex_path[:-4] + '.mgz' tex = load_texture(tex_path)[np.newaxis, np.newaxis].T mghformat.save(Nifti1Image(tex, np.eye(4)), mgz) fs_comment = commands.getoutput( 'mri_surf2surf --trgsubject %s --trgsurfval %s --srcsubject ico --srcsurfval %s --hemi %sh --srcicoorder 7' % ( subject, output_path, mgz, side[0])) if verbose: print fs_comment return output_path
imgs = np.expand_dims(imgs, axis=3) return imgs def preprocess_squeeze(imgs): imgs = np.squeeze(imgs, axis=3) return imgs number_of_files = len(png_files) image_rows = int(256) image_cols = int(256) image_depth = 5 print(' ---------------- image reconstruction in progress -----------------') imgs_temp = np.ndarray((number_of_files, image_rows, image_cols), dtype=np.uint8) for i in range(0, number_of_files): img = ((imread("mask/" + png_files[i]))) img = img.astype(np.uint8) img = np.array([img]) imgs_temp[i] = img imgs_temp = np.around(imgs_temp, decimals=0) imgs_temp = (imgs_temp * 255).astype(np.uint8) affine = np.diag([1, 2, 2, 1]) array_img = nib.Nifti1Image(imgs_temp, affine) print(' ---------------- image reconstructed -----------------') array_header = array_img.header mgh.save(scaled_img, "img.mgz") print(' ---------------- image saved to local drive -----------------')