Trying to use Python focus-stacking tool: IndexError: list index out of range

54 Views Asked by At

I am trying to use this focus-stacking tool on a set of images that I have, but I am getting an error. Here is the command I use in my Linux terminal:

focusstack -i /projectnb/npbssmic/ac25/focus_stacking/Zstack -otest.png

I am working in a virtual environment and the directory I specify is the full path to the directory containing the images. They are .tif format. I will put a screenshot of this directory below, but first here is the error I get:

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

I looked over the source code and it seems like this error is because the call to cv2.imread() on the files in my directory is not working, but I am not sure why. Here's the source code I am referring to:

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]

Here's what the directory looks like in case it helps:

Directory

0

There are 0 best solutions below