python - 如何调整 .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)
`
解决方案
推荐阅读
- html - VBA 从包含空格的 HTML 中检索数据
- python - 如何解决“cuDNN 未启用”
- sql - SAP HANA SQL 中是否有任何方法可以计算迭代中没有循环操作的百分比?
- python - 日期时间戳无法正确读取为字符串
- javascript - 如何在 javascript ( w/ webpack) 中播放 mp3 文件?
- ruby-on-rails - 如何让 Rails 5 上的 avatar.variant(size: "200x200") 在生产中使用 aws 工作?
- date - 将 Hubspot 类似 NIX 的整数日期转换为 Google 表格人类可读的日期
- javascript - 日期选择器上的材质 UI 自定义文本字段
- azure - 使用 Azure EventHubs Capture 生成的 Azure Data Lake Gen1 中的 Databricks 读取 avro 数据失败
- r - 在R中划分行