def get_disp_img_pyramid(model, image1_path, image2_path,disp_init, output_directory):
    # 使用 GDAL 打开图像
    dataset1 = gdal.Open(image1_path)
    dataset2 = gdal.Open(image2_path)
    # 获取图像大小
    width = dataset1.RasterXSize
    height = dataset1.RasterYSize
    disp_map = np.zeros((height, width), dtype=np.float32)
    weight_map = np.zeros((height, width), dtype=np.float32)
    block_sizes = 512 #128 #512 #128
    

    w_block_number = width // block_sizes + 1 
    h_block_number = height // block_sizes + 1 
    
    for i in tqdm(range(h_block_number)):
        for j in range(w_block_number):
            #计算左图原始位置
            l_w_start = j*block_sizes
            l_w_end = min(width,l_w_start+block_sizes)
            l_h_start = i*block_sizes
            l_h_end = min(height,l_h_start+block_sizes)
            #计算右图的原始位置
            r_w_start = j*block_sizes
            r_w_end = min(width,r_w_start+block_sizes)
            r_h_start = i*block_sizes
            r_h_end = min(height,r_h_start+block_sizes)
            w_expand_pixels = 128 #512  #320
            h_expand_pixels = 32 
            # 原始 block_init_disp 计算
            block_init_disp = np.nanmean(disp_init[l_h_start:l_h_end, l_w_start:l_w_end])
            if abs(block_init_disp)>256:
                w_expand_pixels += int(abs(block_init_disp)/2)
                h_expand_pixels += 64
            # 如果整个区域都是 NaN，可以选择默认值，例如 0
            if np.isnan(block_init_disp):
                block_init_disp = 0
            else:
                block_init_disp = int(block_init_disp)
            #计算右图初始位置
            skew_r_w_start = r_w_start-block_init_disp
            skew_r_w_end = r_w_end-block_init_disp
            skew_disp = 0
            #如果超出范围，我就不管了
            if skew_r_w_start>0 and skew_r_w_end < width:
                r_w_start = skew_r_w_start
                r_w_end = skew_r_w_end
                skew_disp = block_init_disp
            

            
            
            l_w_start_adjusted = max(0, l_w_start - w_expand_pixels)
            l_w_end_adjusted = min(width, l_w_end + w_expand_pixels)
            l_h_start_adjusted = max(0, l_h_start - h_expand_pixels)
            l_h_end_adjusted = min(height, l_h_end + h_expand_pixels)
            
            r_w_start_adjusted = max(0, r_w_start - w_expand_pixels)
            r_w_end_adjusted = min(width, r_w_end + w_expand_pixels)
            r_h_start_adjusted = max(0, r_h_start - h_expand_pixels)
            r_h_end_adjusted = min(height, r_h_end + h_expand_pixels)
            
            #根据左图的外扩计算右图然后也得根据右图能不能外扩取计算左图
            map_left_expand = min(l_w_start-l_w_start_adjusted,r_w_start-r_w_start_adjusted)
            map_right_expand = min(l_w_end_adjusted - l_w_end,r_w_end_adjusted-r_w_end)
            map_up_expand = min(l_h_start-l_h_start_adjusted,r_h_start-r_h_start_adjusted)
            map_down_expand = min(l_h_end_adjusted - l_h_end,r_h_end_adjusted-r_h_end)
            
            
            l_w_start_adjusted = l_w_start-map_left_expand
            l_w_end_adjusted = l_w_end+map_right_expand
            l_h_start_adjusted = l_h_start-map_up_expand
            l_h_end_adjusted = l_h_end+map_down_expand
            
            r_w_start_adjusted = r_w_start - map_left_expand
            r_w_end_adjusted = r_w_end+map_right_expand
            r_h_start_adjusted = r_h_start - map_up_expand
            r_h_end_adjusted = r_h_end+map_down_expand

            
            image1_patch = load_image_block(dataset1, l_w_start_adjusted, l_h_start_adjusted, l_w_end_adjusted - l_w_start_adjusted, l_h_end_adjusted-l_h_start_adjusted)
            image2_patch = load_image_block(dataset2, r_w_start_adjusted, r_h_start_adjusted, r_w_end_adjusted - r_w_start_adjusted, r_h_end_adjusted-r_h_start_adjusted)


            padder = InputPadder(image1_patch.shape, divis_by=32)
            image1_patch, image2_patch = padder.pad(image1_patch, image2_patch)
            
            
            disp_patch = model(image1_patch, image2_patch, iters=12, test_mode=True)
            disp_patch = disp_patch.detach().cpu()
            disp_patch = padder.unpad(disp_patch).numpy()[0,0]

            #根据前面的外扩，再取出非外扩的值
            up_expand = l_h_start - l_h_start_adjusted
            down_expand = l_h_end_adjusted - l_h_end 
            left_expand = max(0,l_w_start - l_w_start_adjusted)
            right_expand = max(0,l_w_end_adjusted - l_w_end)
            
            # 去除外扩部分
            disp_path_non_expanded = None
            if(right_expand==0):
                if(down_expand==0):
                    disp_path_non_expanded = disp_patch[
                        up_expand:, 
                        left_expand:
                    ]
                    l_w_end = l_w_end_adjusted
                else:
                    disp_path_non_expanded = disp_patch[
                        up_expand:-down_expand, 
                        left_expand:
                    ]
                    l_w_end = l_w_end_adjusted

            else:
                if(down_expand==0):
                    disp_path_non_expanded = disp_patch[
                    up_expand:,
                    left_expand:-right_expand
                ]
                else:
                    disp_path_non_expanded = disp_patch[
                    up_expand:-down_expand, 
                    left_expand:-right_expand
                ]
            disp_map[l_h_start:l_h_end, l_w_start:l_w_end] += (disp_path_non_expanded+skew_disp)

            print(f"{l_h_start}_{l_h_end}_{l_w_start}_{l_w_end}")
    file_stem = image1_path.split('\\')[-2]
    filename = os.path.join(output_directory, f"{file_stem}_17.tif")
    imageio.imwrite(filename, disp_map.squeeze())
    # 当数据集不再需要时关闭它们
    dataset1 = None
    dataset2 = None
这个代码，你帮我改改，把weight_map用上，然后weight_map，权重怎么设置呢，我非外扩的地方设置1，其他外扩的地方设置0.3？最后计算出来
我分块的地方，不太好，你帮我优化优化