Python 逐帧打开nd2电影

Python 逐帧打开nd2电影,python,image,file,Python,Image,File,我有一个nd2文件,我想打开它并将每个帧复制到一个numpy数组中。我可以打开它看第一张图片,如: import numpy as np from nd2reader import ND2Reader import matplotlib.pyplot as plt images = ND2Reader('movie.nd2') plt.imshow(images[0]) plt.show() 但是如果我想看第二帧 plt.imshow(images[1]) plt.show() 我得到一

我有一个nd2文件,我想打开它并将每个帧复制到一个numpy数组中。我可以打开它看第一张图片,如:

import numpy as np
from nd2reader import ND2Reader
import matplotlib.pyplot as plt

images = ND2Reader('movie.nd2')

plt.imshow(images[0])
plt.show()
但是如果我想看第二帧

plt.imshow(images[1])
plt.show()
我得到一个错误:

Traceback (most recent call last):
      File "/snap/pycharm-community/236/plugins/python-ce/helpers/pydev/_pydevd_bundle/pydevd_exec2.py", line 3, in Exec
        exec(exp, global_vars, local_vars)
      File "<input>", line 1, in <module>
      File "/home/shepbryan/.local/lib/python3.6/site-packages/slicerator/__init__.py", line 188, in __getitem__
        return self._get(indices)
      File "/home/shepbryan/.local/lib/python3.6/site-packages/pims/base_frames.py", line 98, in __getitem__
        return self.get_frame(key)
      File "/home/shepbryan/.local/lib/python3.6/site-packages/pims/base_frames.py", line 592, in get_frame
        result = self._get_frame_wrapped(**coords)
      File "/home/shepbryan/.local/lib/python3.6/site-packages/nd2reader/reader.py", line 72, in get_frame_2D
        return self._parser.get_image_by_attributes(t, v, c, z, y, x)
      File "/home/shepbryan/.local/lib/python3.6/site-packages/nd2reader/parser.py", line 104, in get_image_by_attributes
        height, width)
      File "/home/shepbryan/.local/lib/python3.6/site-packages/nd2reader/parser.py", line 262, in _get_raw_image_data
        chunk = self._label_map.get_image_data_location(image_group_number)
      File "/home/shepbryan/.local/lib/python3.6/site-packages/nd2reader/label_map.py", line 80, in get_image_data_location
        return self._image_data[index]
    KeyError: 2499
回溯(最近一次呼叫最后一次):
文件“/snap/pycharm community/236/plugins/python-ce/helpers/pydev/_-pydevd_-bundle/pydevd_-exec2.py”,第3行,在Exec中
执行官(exp、全局变量、本地变量)
文件“”,第1行,在
文件“/home/shepbryan/.local/lib/python3.6/site packages/slicerator/_init__.py”,第188行,在_getitem中__
返回自获取(索引)
文件“/home/shepbryan/.local/lib/python3.6/site packages/pims/base_frames.py”,第98行,在u_getitem中__
返回self.get_帧(键)
文件“/home/shepbryan/.local/lib/python3.6/site packages/pims/base\u frames.py”,第592行,在get\u frame中
结果=自我。获取框架包裹(**coords)
文件“/home/shepbryan/.local/lib/python3.6/site packages/nd2reader/reader.py”,第72行,在get\u frame\u 2D中
返回self.\u解析器。通过属性(t、v、c、z、y、x)获取图像
文件“/home/shepbryan/.local/lib/python3.6/site packages/nd2reader/parser.py”,第104行,按属性获取图像
高度、宽度)
文件“/home/shepbryan/.local/lib/python3.6/site packages/nd2reader/parser.py”,第262行,在获取原始图像数据中
chunk=self.\u标签\u映射。获取\u图像\u数据\u位置(图像\u组\u编号)
文件“/home/shepbryan/.local/lib/python3.6/site packages/nd2reader/label\u map.py”,第80行,在get\u image\u data\u位置
返回self.\u图像\u数据[索引]
密钥错误:2499

逐帧打开文件的正确方法是什么?

您的代码看起来是正确的。我从下载了一个ND2视频文件示例。第二个文件是电影文件<代码>plt.imshow(图像[1])工作正常。您可以尝试下载示例,并检查它是否与您的设置一起工作。