python - 有人可以向我解释 map_coordinates 如何在 n 维数据集上工作吗?
问题描述
我有一个正在尝试转换的 3D 图像,具有已知的坐标映射。我正在尝试使用 map_coordinates 但 scipy 文档只讨论映射到一维向量,这让我很困惑。
转换是矢量化的,所以我可以给它一个 xyz 索引的网格网格,它会生成一个 3 x nx x ny x nz 数组,其中第一个索引越过向量场的 xyz 分量,其他索引直接对应于网格网格输入维度
现在我只需要将输出数组的数组元素映射到初始图像中的相应像素。我想使用 map_coordinates 但我不清楚坐标参数的格式。
谁能给我一个例子,说明在这种情况下我将如何创建坐标数组?
解决方案
终于弄清楚了,所以我想我会把它留在这里
# transposed_frame is the 3d image that needs to be transformed (shape (632, 352, 35))
# Meshgrid of the matrix coordinates
x_grid, y_grid, z_grid = np.meshgrid(range(transposed_frame.shape[0]), range(transposed_frame.shape[1]), range(transposed_frame.shape[2]), indexing = 'ij')
# inverse transformation that needs to be applied to the image (shape (3, 632, 352, 35))
# the first dimension goes over the different components of the vector field x y z
# So transform[0, i, j, k] is the x coordinate of the vector field in the point [i, j, k]
transform = vectorized_interp_field(x_grid, y_grid, z_grid)
# Transforming the image through map_coordinates is then as simple as
inverse_transformed = map_coordinates(transposed_frame, transform)
我不了解 map_coordinates 的部分正是映射矩阵应该具有的高维数据形式。它似乎通常如下工作
B = map_coordinates(A, mapping)
B[i, j, k] = A[mapping[0, i, j, k], mapping[1, i, j, k], mapping[2, i, j, k]]
推荐阅读
- python-3.x - conda activate env “没有这样的文件或目录”
- javascript - Java脚本WebSocket onopen事件未触发?
- html - 如何在我的幻灯片中消除点行之间的空间。我的行之间大约有 2.5 英寸。我有 120 张幻灯片,导致三排点
- android-studio - 当我使用 WebView for WhatsApp Web 时,您的浏览器不受支持 - Android Studio
- javascript - 从数组中添加相同的标题
- symfony5 - Symfony 5 Mercure 无法为“https://127.0.0.1:8000/.well-known/mercure”发送更新 SSL 连接错误
- timer - 为什么我们应该在 EJB 中使用 @Startup 进行定时器服务?
- json - 如何在 go 中打印 [][]interface{}?
- javascript - 如何使用一个 Jquery 函数来处理多个 onchange (HTML) 事件
- oracle - 如何将一个分区的数据从一个表及其子表(引用分区)移动到另一个表及其子表(引用分区)?