【发布时间】:2021-05-25 03:47:37
【问题描述】:
我正在尝试读取 3D 图像二进制文件并在 python 中显示 3D 图像的切片。格式为 int16 大端。文件扩展名为.rec。我有以下代码:
struct_fmt = '>h' # big-endian,signed int16
struct_len = struct.calcsize(struct_fmt)
struct_unpack = struct.Struct(struct_fmt).unpack_from
results = []
with open('test.rec', "rb") as f:
while True:
data = f.read(struct_len)
if not data: break
s = struct_unpack(data)
results.append(s)
img3d = np.array(results)
img3d = img3d.reshape(401,401,326)
np.save('output.npy',img3d)
image = np.load('output.npy')
fig,ax=plt.subplots()
output_slice=image[:,190,:]
ax.imshow(output_slice,cmap='gray')
ax.axis('off')
plt.show()
但我得到的所有体素值都是 0。而且图像是黑色的。我错过了什么?
【问题讨论】:
标签: python numpy matplotlib 3d voxel