逐帧打开nd2电影

2024-10-01 02:38:17 发布

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

我有一个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

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


Tags: inpyimageselfhomegetlibpackages