Exemplo n.º 1
0
    logger.info('Running on {}'.format(cohort))
    for i in range(0, hdf5_file[cohort].shape[0]):
        # cropping operation
        logger.debug('{}:- Patient {}'.format(cohort, i + 1))
        img_src = hdf5_file[cohort][i]
        coords = config['cropping_coords']
        if 'segmasks' in cohort:
            # there are no channels for segmasks
            img_dst = img_src[coords[0]:coords[1], coords[2]:coords[3], coords[4]:coords[5]]
        else:
            img_dst = img_src[:, coords[0]:coords[1], coords[2]:coords[3], coords[4]:coords[5]]

        if cohort in list_std:
            # save the image to this numpy array
            im_np[i] = img_dst
            print(img_src.max(), img_dst.max())
        new_group_preprocessed[cohort][i] = img_dst
    # find mean and standard deviation, and apply to data. Also write the mean/std values to disk
    if cohort in list_std:
        logger.info('The dataset {} needs standardization'.format(cohort))
        _tmp, vals = standardize(im_np, findMeanVarOnly=True, saveDump=(config['pathd_hdf5files']/(cohort + '_mean_std.p')))
        logging.info('Calculated normalization values for {}:\n{}'.format(cohort, vals))
        del im_np

# ====================================================================================

hdf5_file_main.close()
new_hdf5.close()


Exemplo n.º 2
0
    logger.info('Running on {}'.format(run_on))
    for i in range(0, hdf5_file[run_on].shape[0]):
        # cropping operation
        logger.debug('{}:- Patient {}'.format(run_on, i+1))
        im = hdf5_file[run_on][i]
        m = config['cropping_coords']
        if 'segmasks' in run_on:
            # there are no channels for segmasks
            k = im[m[0]:m[1], m[2]:m[3], m[4]:m[5]]
        else:
            k = im[:, m[0]:m[1], m[2]:m[3], m[4]:m[5]]

        if run_on in std_list:
            # save the image to this numpy array
            im_np[i] = k
        new_group_preprocessed[run_on][i] = k
    # find mean and standard deviation, and apply to data. Also write the mean/std values to disk
    if run_on in std_list:
        logger.info('The dataset {} needs standardization'.format(run_on))
        _tmp, vals = standardize(im_np, findMeanVarOnly=True, saveDump=saveMeanVarFilename + run_on + '_mean_std.p')
        logging.info('Calculated normalization values for {}:\n{}'.format(run_on, vals))
        del im_np

# ====================================================================================

hdf5_file_main.close()
new_hdf5.close()