使用两个numpy数组创建图像

2024-10-01 04:45:55 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在做一个项目,我在一个名为Prismatic的程序中进行模拟,以获取我以后要使用的文件,Prismatic以h5格式输出文件,我可以使用Python从中提取数据,模拟生成一个图像,保存在两个数据集(dim1,dim2)中,每一个都是大小为219的numpy数组,我试图再次从中创建图像,但我不确定这是如何工作的,我尝试堆叠numpy数组,但我只是在图像中得到一行,我刚刚了解了numpy数组,我对它们知之甚少,有人能帮忙吗?这是我的密码

fi = h5py.File('ty.h5')
a = fi['4DSTEM_simulation']['data']['realslices']['annular_detector_depth0000']['dim1'][:]
b = fi['4DSTEM_simulation']['data']['realslices']['annular_detector_depth0000']['dim2'][:]
merge_arr = numpy.stack((a, b), axis=0)
data = Image.fromarray(merge_arr)
if data.mode != 'RGB':
    data = data.convert('RGB')

Tags: 文件数据图像numpydata数组detectorfi
1条回答
网友
1楼 · 发布于 2024-10-01 04:45:55

好的,根据你的数据集,我找到了一张图片

from matplotlib import pyplot as plt
%matplotlib inline # remove this if you are not using a jupyter notebook
import h5py
# data link https://file.io/riS5juuYLNin

f = h5py.File('ty.h5')

realslice = (f['4DSTEM_simulation']
 ['data']
 ['realslices']
 ['annular_detector_depth0000']
 ['realslice'])[:]

plt.imshow(realslice)
#plt.show() # add this if you are not using a jupyter notebook

enter image description here

解决这个问题的真正工具是查看文件f的给定级别上的键是什么,如f.keys()f['4DSTEM_simulation'].keys()等等,然后通过提取这些键访问的可用对象来查看其中的项的形状。最后我发现了一个是图像。我对这些数据一无所知,所以可能还有更多。看来你原来的问题实际上并不是什么需要解决的问题。两个246x1阵列绝对不会以独特的方式形成图像

相关问题 更多 >