【发布时间】:2021-07-03 18:33:23
【问题描述】:
我正在尝试从许多 2D 数组中创建一个 3D 数组。
图像文件
每张图片都变成一个二维数组。
https://drive.google.com/drive/folders/1xBucvqhKFjAfbRIhq5wjr40kSjNor_0t?usp=sharing
using Images, Colors
paths = readdir(
"/Users/me/Downloads/ct_scans"
, join = true
)
images_3D = []
for p = paths
img = load(p)
gray = Gray.(img)
arr = convert(Array{Float64}, gray) # <----- 2D array
append!(images_3d, arr)
end
>>> size(images_3d)
(1536000) # <--- 1D view?
>>> 1536000 == 80*160*120
true
>>> reshaped_3d = reshape(images_3d, (80,160,120))
>>> Gray.(reshaped_3d[1,:,:])
# 160x120 scrambled mess of pixels not rearranged as expected
-
append!创建一个 size== 1D 数组,它没有按预期重塑。 - 而
push!创建一个保持其形状的硬阵列阵列。从技术上讲,它不是 3D,只是一个 80 元素向量。 - 当我尝试初始化一个空的 3D,然后用我自己的 2D 图像覆盖每个 2D 时,我收到
Matrix{Float64} to Float64类型转换失败。 - 无法迭代
vcat2D 数组,因为无法覆盖变量。
发布此内容的部分原因是为了了解 Julia 程序员如何处理多维数组。
【问题讨论】: