循环遍历tif堆栈并提取像素值的最快方法

时间:2018-08-29 07:28:28

标签: python numpy image-processing mask

我有一个大的tif图像堆栈+1500,对于每个图像,我在x,y中有〜100个位置,我要从中提取蒙版的值。 数据框可以通过以下列表显示:

x=[80.1,80.2,80.1,80.2,80,2,80.3]
y=[40.1,40.2,40.1,40.2,40.2,40.3]
frame = [1,2,3,4,5,6]

以下代码似乎可以正常工作,但是要花很多时间才能完成。任何可以提供更快解决方案的人:

blue = image_loader_video(blue_video) # video as numpy array

def df_extractor(row):
    a,b = row['x'],row['y']
    frame = int(row['frame'])
    array = blue[frame]

    nx,ny = blue_shape
    y,x = np.ogrid[-a:nx-a,-b:ny-b]
    mask = x*x + y*y <= lip_int_size  
    mask2 = x*x + y*y <= lip_int_size+9 # to make a "gab" between BG and roi

    BG_mask = (x*x + y*y <=lip_BG_size)
    BG_mask = BG_mask-mask2
    return (sum((array[mask]))),np.median(((array[BG_mask])))

final_df['signal_np'],final_df['np_bg'] = final_df.apply(df_extractor,axis= 1)

0 个答案:

没有答案
相关问题