首页 > 解决方案 > 如何调整 .aim 文件的大小以使所有文件都相同?

问题描述

我有保存为 .aim 文件的 uCT 扫描。当我想运行以下代码时,我收到错误消息 mask and image do not have the same shape。是否有可能重塑我不再具有不同形状的目标文件?这是代码的一部分:

def read_mask(sample,models_path,start_day = '07'):

    '''
    Function that loads the mask from the first time-point. The loaded mask is used for the following days.
    The mask is corrected in z_height at the bottom of the scaffold
    '''
    sub_s1 = sample.split('_')
    sub_s1[4] = start_day
    mask0 = np.load(os.path.join(models_path,"_".join(sub_s1)+'_mask.npy'))   
    midpoint_x = np.load(os.path.join(models_path,"_".join(sub_s1)+'_midpoint_x.npy'))   
    return mask0,midpoint_x

dens_histo = range(-150,2000,25)
bv_bins = range(bv_thres,2000,25) # density bins in mg HA/cm**3
colnames_histo = list(['scaffold','bior','day','type','mu (mg HA/ccm','loc (mg HA/ccm)','sigma','TV'])+list(dens_histo[:-1])
colnames_bior = list(['scaffold','bior','day','type','TV','BV','mass','surface','TMD-median','TMD-mean'])
#colnames_cl_nr = list(['scaffold','bior','day','type','TV','BV','mass','surface','TMD-median','TMD-mean'])
colnames_bv_bins = list(['scaffold','bior','day','type'])+list(bv_bins[:-1])
df_bior = pd.DataFrame(data = np.zeros(shape=(len(samples_bior),len(colnames_bior))),columns=colnames_bior,index=[s[:-len(ending_bior)] for s in samples_bior])
#df_cl_nr = pd.DataFrame(data = np.zeros(shape=(len(samples_cl_nr),len(colnames_cl_nr))),columns=colnames_cl_nr,index=[s[:-len(ending_cl_nr)] for s in samples_cl_nr])
df_histo = pd.DataFrame(data = np.zeros(shape=(len(samples_bior),len(colnames_histo))),columns=colnames_histo,index=[s[:-len(ending_bior)] for s in samples_bior])
#df_histo = pd.DataFrame(data = np.zeros(shape=(len(samples_cl_nr),len(colnames_histo))),columns=colnames_histo,index=[s[:-len(ending_cl_nr)] for s in samples_cl_nr])
df_bv_bins = pd.DataFrame(data = np.zeros(shape=(len(samples_bior),len(colnames_bv_bins))), columns=colnames_bv_bins,index=[s[:-len(ending_bior)] for s in samples_bior])
#df_bv_bins = pd.DataFrame(data = np.zeros(shape=(len(samples_cl_nr),len(colnames_bv_bins))), columns=colnames_bv_bins,index=[s[:-len(ending_cl_nr)] for s in samples_cl_nr])
#for (c,s) in tqdm(zip(samples_cl_nr,samples_gfilt1)):
for (c,s) in tqdm(zip(samples_bior,samples_gfilt1)):```

    # sample information
    sub_s = s.split('_')
    bior = sub_s[2]+'_'+sub_s[3]
    day =  'day '+ sub_s[4]#[1:]
    

    #cl_nr = load_aim(os.path.join(cl_nr_path,c),auto_convert_to_density=False)
    bior = load_aim(os.path.join(bior_path,c),auto_convert_to_density=False)
    image = load_aim(os.path.join(gfilt1_path,s),auto_convert_to_density=True)
    data = image.data.m
    print(day)
    print(data.shape)

    # if possible we use the mask from starting day for all following days
    if sub_s[4] == starting_day:
        mask,radius_calc,midpoint_x = create_cylindrical_mask(data,image.voxelsize[0],radius,depth,s)
        # calculate mask for void space
        #mask_void = (bior.data == 0).astype('int')
        # combine cylindrical mask with mask for void space
        #mask = np.logical_or(mask,mask_void)
        # make a binary dilation
        np.save(os.path.join(gfilt1_path,s[:-len(ending_gfilt)]+'_mask'),mask)
        np.save(os.path.join(gfilt1_path,s[:-len(ending_gfilt)]+'_midpoint_x'),midpoint_x)
    else:
        mask,midpoint_x = read_mask(s[:-len(ending_gfilt)],gfilt1_path,start_day = starting_day)
    if data.shape != mask.shape:
        error_message = **'Mask and image do not have the same shape'**
        logger.exception(error_message)
        raise ValueError(error_message)
        `

标签: pythonarraysimagenumpy

解决方案


推荐阅读