提问人:ac25 提问时间:11/16/2023 最后编辑:ac25 更新时间:11/16/2023 访问量:38
尝试使用 Python 焦点堆叠工具:IndexError:列表索引超出范围
Trying to use Python focus-stacking tool: IndexError: list index out of range
问:
我正在尝试在我拥有的一组图像上使用此焦点堆叠工具,但我收到错误。这是我在 Linux 终端中使用的命令:
focusstack -i /projectnb/npbssmic/ac25/focus_stacking/Zstack -otest.png
我在虚拟环境中工作,我指定的目录是包含图像的目录的完整路径。它们是.tif格式。我将在下面放置此目录的屏幕截图,但首先这是我得到的错误:
INFO:focus_stack.focus_stack:reading images
INFO:focus_stack.focus_stack:aligning images
Traceback (most recent call last):
File "/projectnb/npbssmic/ac25/.conda/envs/pytorch_env/bin/focusstack", line 33, in <module>
sys.exit(load_entry_point('focus-stack', 'console_scripts', 'focusstack')())
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/projectnb/npbssmic/ac25/focus_stacking/focus-stack/focus-stack/focus_stack/run.py", line 58, in main
stacked = stacker.focus_stack(image_files)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/projectnb/npbssmic/ac25/focus_stacking/focus-stack/focus-stack/focus_stack/focus_stack.py", line 41, in focus_stack
images = self._align_images(image_matrices)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/projectnb/npbssmic/ac25/focus_stacking/focus-stack/focus-stack/focus_stack/focus_stack.py", line 84, in _align_images
aligned_imgs.append(images[0])
~~~~~~^^^
IndexError: list index out of range
我查看了源代码,似乎这个错误是因为对我目录中的文件调用 cv2.imread() 不起作用,但我不确定为什么。这是我所指的源代码:
def focus_stack(self, image_files: List[str]) -> np.ndarray:
"""Pipeline to focus stack a list of images."""
image_matrices = self._read_images(image_files)
images = self._align_images(image_matrices)
laplacian = self._compute_laplacian(images)
focus_stacked = self._find_focus_regions(images, laplacian)
return focus_stacked
@staticmethod
def _read_images(image_files: List[str]) -> List[np.ndarray]:
"""Read the images into numpy arrays using OpenCV."""
logger.info("reading images")
return [cv2.imread(img) for img in image_files]
以下是目录的样子,以防万一:
答: 暂无答案
评论
/projectnb/npbssmic/ac25/focus_stacking/Zstack
projectnb/npbssmic/ac25/focus_stacking/Zstack
os.path.exists()
/projectnb/npbssmic/ac25/focus_stacking/Zstack
focus_stacking
print(image_files)
print(os.getcwd())