示例#1
0
    def reload(self, n=None):
        """Reload one or more images from file.

        Parameters
        ----------
        n : None or int
            The number of the image to reload. If None (default), all images in
            memory are reloaded.  If `n` specifies an image not yet in memory,
            it is loaded.

        Returns
        -------
        None

        Notes
        -----
        `reload` is used to reload all images in memory when `as_grey` is
        changed.
        """
        if n is not None:
            n = self._check_numimg(n)
            idx = n % len(self.data)
            self.data[idx] = imread(self.files[n], self.as_grey,
                                    dtype=self._dtype)
        else:
            for idx, img in enumerate(self.data):
                if img is not None:
                    self.data[idx] = imread(self.files[idx], self.as_grey,
                                            dtype=self._dtype)
示例#2
0
    def __getitem__(self, n):
        """Return image n in the collection.

        Loading is done on demand.

        Parameters
        ----------
        n : int
            The image number to be returned.

        Returns
        -------
        img : ndarray
           The `n`-th image in the collection.
        """
        n = self._check_imgnum(n)
        idx = n % len(self.data)

        if (self.conserve_memory and n != self._cached) or (self.data[idx] is None):
            self.data[idx] = imread(self.files[n], self.as_grey,
                                    dtype=self._dtype)
            self._cached = n

        return self.data[idx]